in plugin/:
[moon.git] / src / mutex.h
blob383f77d2ed94f032e2cd1f9fa72f64072acfa814
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * mutex.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __MOON_MUTEX_H__
14 #define __MOON_MUTEX_H__
16 #include <pthread.h>
18 class Mutex {
19 private:
20 pthread_mutex_t mutex;
22 public:
23 Mutex ()
25 pthread_mutex_init (&mutex, NULL);
27 Mutex (bool recursive)
29 pthread_mutexattr_t attribs;
30 pthread_mutexattr_init (&attribs);
31 pthread_mutexattr_settype (&attribs, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_DEFAULT);
32 pthread_mutex_init (&mutex, &attribs);
33 pthread_mutexattr_destroy (&attribs);
35 ~Mutex ()
37 pthread_mutex_destroy (&mutex);
39 void Lock ()
41 pthread_mutex_lock (&mutex);
43 void Unlock ()
45 pthread_mutex_unlock (&mutex);
49 #endif /* __MOON_MUTEX_H */