Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2004-07-22 16:21:17


Eric Niebler wrote:
> get a pointer to the mutex from the scoped_lock. You should get back a
> token or a void* that is useful only for comparison purposes.

It just came to my mind that if we decide to add common base class, such
void* could be returned there. Thus it would look something like:

class lock
{
   bool* active_;
   void* mutex_;
protected:
   ~lock() {} // no-op
   lock(bool* active, void* mutex) : active_(active), mutex_(mutex)
     {assert(active_ != NULL); assert(mutex_ != NULL);}
   lock(const lock& src) : active_(src.active_)
     {assert(src.mutex_ == mutex_);}
public:
   bool active() const {return *active_;}
   void* mutex() const {return mutex_;}
// or just polymorphic functions:
// virtual bool active() const = 0;
// virtual void* mutex() const = 0;
   operator safe_bool() const {return active() ? safe_true : safe_false;}
};

Actually "mutex" can be renamed here to "handle" or "primitive" ...

B.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk