Release ETL_@VERSION_MAJ@_@VERSION_MIN@_@VERSION_REV@
[synfig.git] / ETL / tags / ETL_@VERSION_MAJ@_@VERSION_MIN@_@VERSION_REV@ / ETL / _mutex_pthreads_simple.h
1 /*! ========================================================================
2 ** Extended Template and Library
3 ** Mutex Abstraction Class Implementation
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 ** Copyright (c) 2008 Chris Moore
8 **
9 ** This package is free software; you can redistribute it and/or
10 ** modify it under the terms of the GNU General Public License as
11 ** published by the Free Software Foundation; either version 2 of
12 ** the License, or (at your option) any later version.
13 **
14 ** This package is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ** General Public License for more details.
18 **
19 ** === N O T E S ===========================================================
20 **
21 ** This is an internal header file, included by other ETL headers.
22 ** You should not attempt to use it directly.
23 **
24 ** ========================================================================= */
25
26 /* === S T A R T =========================================================== */
27
28 #ifndef __ETL__MUTEX_PTHREADS_SIMPLE_H_
29 #define __ETL__MUTEX_PTHREADS_SIMPLE_H_
30
31 /* === H E A D E R S ======================================================= */
32
33 #include <pthread.h>
34
35 /* === M A C R O S ========================================================= */
36
37 /* === C L A S S E S & S T R U C T S ======================================= */
38
39 _ETL_BEGIN_NAMESPACE
40
41 class mutex
42 {
43         pthread_mutex_t mtx;
44 public:
45                         mutex()                 { pthread_mutex_init(&mtx,NULL);        }
46                    ~mutex()                     { pthread_mutex_destroy(&mtx);          }
47         void    lock_mutex()    { pthread_mutex_lock(&mtx);                     }
48         void    unlock_mutex()  { pthread_mutex_unlock(&mtx);           }
49
50         //! Exception-safe mutex lock class
51         class lock
52         {
53                 mutex *_mtx;
54         public:
55                  lock(mutex &x):_mtx(&x)        { _mtx->lock_mutex();           }
56                 ~lock()                                         { _mtx->unlock_mutex();         }
57         };
58 };
59
60 _ETL_END_NAMESPACE
61
62 /* === E N D =============================================================== */
63
64 #endif