InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MSemaphore.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Lonnie Millett
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __MSemaphore__
25 #define __MSemaphore__
26 
27 #include <pthread.h>
28 
29 namespace ID {
30 
31 //========================================================================================
32 // CLASS MSemaphore
33 //========================================================================================
34 
36 {
37 public:
38  MSemaphore(const uint32& initialCount);
39  ~MSemaphore();
40 
41  void Acquire();
42  void Relinquish();
43 
44 private:
45  uint32 fCount; // Current count of the semaphore.
46  uint32 fWaitersCount; // Number of threads that have called <sema_wait>.
47  pthread_mutex_t fLock; // Serialize access to <count_> and <waiters_count_>.
48  pthread_cond_t fCountNonzero; // Condition variable that blocks the <count_> 0.
49 };
50 
51 }
52 
53 #endif
54