Fixed some more confidential notices
[synfig.git] / synfig-core / tags / stable / src / sinfg / mutex.h
1 /* === S I N F G =========================================================== */
2 /*!     \file mutex.h
3 **      \brief Template Header
4 **
5 **      $Id: mutex.h,v 1.2 2005/01/10 07:40:26 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SINFG_MUTEX_H
25 #define __SINFG_MUTEX_H
26
27 /* === H E A D E R S ======================================================= */
28
29 /* === M A C R O S ========================================================= */
30
31 /* === T Y P E D E F S ===================================================== */
32
33 /* === C L A S S E S & S T R U C T S ======================================= */
34
35 namespace sinfg {
36
37 class RecMutex;
38
39 class Mutex
40 {
41         friend class RecMutex;
42
43 protected:
44         void* blackbox;
45         
46 public:
47         
48         class Lock
49         {
50                 Mutex& mutex;
51         public:
52                 Lock(Mutex& x):mutex(x) { mutex.lock(); }
53                 ~Lock() { mutex.unlock(); }
54         };
55         
56         Mutex();
57         ~Mutex();
58         
59         void lock();
60         void unlock();
61         bool try_lock();
62         bool is_locked();
63         
64 private:
65         //! Non-copyable
66         Mutex(const Mutex&);
67         
68         //! Non-assignable
69         void operator=(const Mutex&);
70 };
71
72 class RecMutex : public Mutex
73 {
74 public:
75         RecMutex();
76
77         void unlock_all();
78 };
79
80 class RWLock
81 {
82         void* blackbox;
83         
84 public:
85         
86         class ReaderLock
87         {
88                 RWLock& rw_lock;
89         public:
90                 ReaderLock(RWLock& x):rw_lock(x) { rw_lock.reader_lock(); }
91                 ~ReaderLock() { rw_lock.reader_unlock(); }
92         };
93         class WriterLock
94         {
95                 RWLock& rw_lock;
96         public:
97                 WriterLock(RWLock& x):rw_lock(x) { rw_lock.writer_lock(); }
98                 ~WriterLock() { rw_lock.writer_unlock(); }
99         };
100         
101         RWLock();
102         ~RWLock();
103
104         void reader_lock();
105         void reader_unlock();
106         bool reader_trylock();
107
108         void writer_lock();
109         void writer_unlock();
110         bool writer_trylock();
111 };
112
113 }; // END of namespace sinfg
114
115 /* === E N D =============================================================== */
116
117 #endif