beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / goo / GooMutex.h
blobb2714b048c722bbd37331e21ecf47723efa9007f
1 //========================================================================
2 //
3 // GooMutex.h
4 //
5 // Portable mutex macros.
6 //
7 // Copyright 2002-2003 Glyph & Cog, LLC
8 //
9 //========================================================================
11 //========================================================================
13 // Modified under the Poppler project - http://poppler.freedesktop.org
15 // All changes made under the Poppler project to this file are licensed
16 // under GPL version 2 or later
18 // Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
19 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
20 // Copyright (C) 2013 Albert Astals Cid <aacid@kde.org>
21 // Copyright (C) 2013 Adam Reichold <adamreichold@myopera.com>
22 // Copyright (C) 2014 Bogdan Cristea <cristeab@gmail.com>
23 // Copyright (C) 2014 Peter Breitenlohner <peb@mppmu.mpg.de>
25 // To see a description of the changes please see the Changelog file that
26 // came with your tarball or type make ChangeLog if you are building from git
28 //========================================================================
30 #ifndef GMUTEX_H
31 #define GMUTEX_H
33 // Usage:
35 // GooMutex m;
36 // gInitMutex(&m);
37 // ...
38 // gLockMutex(&m);
39 // ... critical section ...
40 // gUnlockMutex(&m);
41 // ...
42 // gDestroyMutex(&m);
44 #ifdef _WIN32
45 #ifndef NOMINMAX
46 #define NOMINMAX
47 #endif
48 #include <windows.h>
50 typedef CRITICAL_SECTION GooMutex;
52 #define gInitMutex(m) InitializeCriticalSection(m)
53 #define gDestroyMutex(m) DeleteCriticalSection(m)
54 #define gLockMutex(m) EnterCriticalSection(m)
55 #define gUnlockMutex(m) LeaveCriticalSection(m)
57 #else // assume pthreads
59 #include <pthread.h>
61 typedef pthread_mutex_t GooMutex;
63 inline void gInitMutex(GooMutex *m) {
64 pthread_mutexattr_t mutexattr;
65 pthread_mutexattr_init(&mutexattr);
66 pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
67 pthread_mutex_init(m, &mutexattr);
68 pthread_mutexattr_destroy(&mutexattr);
70 #define gDestroyMutex(m) pthread_mutex_destroy(m)
71 #define gLockMutex(m) pthread_mutex_lock(m)
72 #define gUnlockMutex(m) pthread_mutex_unlock(m)
74 #endif
76 class MutexLocker {
77 public:
78 MutexLocker(GooMutex *mutexA) : mutex(mutexA) { gLockMutex(mutex); }
79 ~MutexLocker() { gUnlockMutex(mutex); }
81 private:
82 GooMutex *mutex;
85 #endif