|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-07-07 05:48:50
Howard Hinnant wrote:
> I like the latent_write_lock / upgradeable lock idea proposed by Bruno
> / Alexander. I have been playing with the following interface:
>
> namespace detail
> {
>
> template <class RW_Mutex>
> class read_lock
> {
> public:
> typedef RW_Mutex mutex_type;
>
> explicit read_lock(mutex_type& m, bool lock_it = true);
> explicit read_lock(upgradable_read_lock<mutex_type>& r);
> explicit read_lock(write_lock<mutex_type>& w);
>
> ~read_lock();
>
> void lock();
> bool try_lock();
> void unlock();
> bool locked() const;
> operator int bool_type::* () const;
>
> private:
> read_lock(const read_lock&);
> read_lock& operator=(const read_lock&);
> };
[...]
Seems very good to me. Also demonstrates a better lock taxonomy (which
allows me to include some on-topic content ;-) ):
Lock
Lock( Mutex&, bool = true );
void lock();
void unlock();
bool locked() const;
operator int bool_type::* () const;
TryLock: Lock
+bool try_lock();
TimedLock: TryLock
+bool timed_lock( xtime const & );
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk