1/*
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26#ifndef __MUTEX_H__
27#define __MUTEX_H__
28
29
30
31#include <pthread.h>
32
33
34
35// base class for a mutex -- note that this can't be instantiated
36class Mutex
37{
38protected:
39	pthread_mutex_t *mMutexPtr;
40	Mutex () {}
41
42public:
43	void Lock ();
44	void Unlock ();
45};
46
47
48
49
50// Mutex which initializes its own mutex
51class DynamicMutex : public Mutex
52{
53protected:
54	pthread_mutex_t mMutex;
55
56public:
57	DynamicMutex ();
58	~DynamicMutex ();
59};
60
61
62
63// Mutex which takes an externally initialized mutex
64class StaticMutex : public Mutex
65{
66protected:
67	pthread_mutex_t& mMutex;
68
69public:
70	StaticMutex (pthread_mutex_t &mutex);
71};
72
73
74
75// class which locks and unlocks a mutex when it goes in and out of scope
76class MutexLocker
77{
78protected:
79	Mutex& mMutex;
80
81public:
82	MutexLocker (Mutex &mutex);
83	~MutexLocker ();
84};
85
86
87
88#endif
89