summaryrefslogtreecommitdiff
path: root/gpr/source/lib/dng_sdk/dng_mutex.h
blob: b067728619775304babe2821a89d85f91c61ca5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*****************************************************************************/
// Copyright 2006-2008 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
// accordance with the terms of the Adobe license agreement accompanying it.
/*****************************************************************************/

/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_mutex.h#2 $ */ 
/* $DateTime: 2012/09/05 12:31:51 $ */
/* $Change: 847652 $ */
/* $Author: tknoll $ */

/******************************************************************************/

#ifndef __dng_mutex__
#define __dng_mutex__

/******************************************************************************/

#include "dng_flags.h"

/******************************************************************************/

#include "dng_types.h"

#if qDNGThreadSafe

#include "dng_pthread.h"

#endif

/******************************************************************************/

class dng_mutex
	{
	
	public:
	
		enum
			{
			kDNGMutexLevelLeaf = 0x70000000u
			};

		dng_mutex (const char *mutexName,
				   uint32 mutexLevel = kDNGMutexLevelLeaf);

		virtual ~dng_mutex ();

		void Lock ();

		void Unlock ();
		
		const char *MutexName () const;

	protected:
	
		#if qDNGThreadSafe
	
		pthread_mutex_t fPthreadMutex;
	
		const uint32 fMutexLevel;

		uint32 fRecursiveLockCount;

		dng_mutex *fPrevHeldMutex;

		const char * const fMutexName;

		friend class dng_condition;
		
		#endif

	private:
	
		// Hidden copy constructor and assignment operator.
	
		dng_mutex (const dng_mutex &mutex);
		
		dng_mutex & operator= (const dng_mutex &mutex);
		
	};
		
/*****************************************************************************/

class dng_lock_mutex
	{
	
	private:
	
		dng_mutex *fMutex;
	
	public:
	
		dng_lock_mutex (dng_mutex *mutex);
			
		~dng_lock_mutex ();
			
	private:
	
		// Hidden copy constructor and assignment operator.
	
		dng_lock_mutex (const dng_lock_mutex &lock);
		
		dng_lock_mutex & operator= (const dng_lock_mutex &lock);
		
	};
	
/*****************************************************************************/

class dng_unlock_mutex
	{
	
	private:
	
		dng_mutex *fMutex;
	
	public:
	
		dng_unlock_mutex (dng_mutex *mutex);
			
		~dng_unlock_mutex ();
			
	private:
	
		// Hidden copy constructor and assignment operator.
	
		dng_unlock_mutex (const dng_unlock_mutex &unlock);
		
		dng_unlock_mutex & operator= (const dng_unlock_mutex &unlock);
		
	};
	
/*****************************************************************************/

#if qDNGThreadSafe

/*****************************************************************************/

class dng_condition
	{
	
	public:

		dng_condition ();

		~dng_condition ();

		bool Wait (dng_mutex &mutex, double timeoutSecs = -1.0);

		void Signal ();
		
		void Broadcast ();

	protected:
	
		pthread_cond_t fPthreadCondition;

	private:
	
		// Hidden copy constructor and assignment operator.
	
		dng_condition (const dng_condition &condition);
		
		dng_condition & operator= (const dng_condition &condition);

	};

/*****************************************************************************/

#endif // qDNGThreadSafe

/*****************************************************************************/

#endif
	
/*****************************************************************************/