1 //========================================================================
5 // Portable mutex macros.
7 // Copyright 2002-2003 Glyph & Cog, LLC
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 //========================================================================
39 // ... critical section ...
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
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)
78 MutexLocker(GooMutex
*mutexA
) : mutex(mutexA
) { gLockMutex(mutex
); }
79 ~MutexLocker() { gUnlockMutex(mutex
); }