From a744b32df33e2b7c270f8d9f7b7ae3b01eeebaed Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Tue, 15 Oct 2002 15:53:49 +0000 Subject: [PATCH] Fixed race condition in Release(), supplied by Marcus Overhangen. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1529 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/print/BeUtils.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/servers/print/BeUtils.h b/src/servers/print/BeUtils.h index ef1e3dc344..0b3bdc7b4d 100644 --- a/src/servers/print/BeUtils.h +++ b/src/servers/print/BeUtils.h @@ -57,19 +57,18 @@ public: // dtor should be private, but ie. ObjectList requires a public dtor! virtual ~Object() { }; - // thread-safe as long as thread that calls acquire has already + // thread-safe as long as thread that calls Acquire has already // a reference to the object - void Acquire() { + void Acquire() { atomic_add(&fRefCount, 1); } - bool Release() { - atomic_add(&fRefCount, -1); - if (fRefCount == 0) { - delete this; return true; - } else { - return false; - } + bool Release() { + if (atomic_add(&fRefCount, -1) == 1) { + delete this; return true; + } else { + return false; + } } };