~drizzle-trunk/drizzle/development

1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
 *
3
 * PrimeBase Media Stream for MySQL
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
18
 *
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
 * Continued development: Barry Leslie
21
 *
22
 * 2007-06-06
23
 *
24
 * CORE SYSTEM:
25
 * A basic mutex (mutual exclusion) object.
26
 *
27
 */
28
29
#ifndef __CSMUTEX_H__
30
#define __CSMUTEX_H__
31
32
#include <pthread.h>
33
34
#include "CSDefs.h"
35
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
36
class CSThread;
37
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
38
class CSMutex {
39
public:
40
	CSMutex();
41
	virtual ~CSMutex();
42
43
	virtual void lock();
44
	virtual void unlock();
45
46
	friend class CSLock;
47
	friend class CSSync;
48
49
private:
50
	pthread_mutex_t	iMutex;
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
51
#ifdef DEBUG
52
	CSThread		*iLocker;
53
public:
54
	bool			trace;
55
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
56
};
57
58
class CSLock : public CSMutex {
59
public:
60
	CSLock();
61
	virtual ~CSLock();
62
63
	virtual void lock();
64
	virtual void unlock();
65
	virtual bool haveLock();
66
67
	friend class CSSync;
68
69
private:
70
	CSThread		*iLockingThread;
71
	int				iLockCount;
72
};
73
74
class CSSync : public CSLock {
75
public:
76
	CSSync();
77
	virtual ~CSSync();
78
	
79
	/* Wait for resources on the object
80
	 * to be freed.
81
	 *
82
	 * This function may only be called
83
	 * if the thread has already locked the
84
	 * object.
85
	 */
86
	virtual void wait();
87
88
	/* Wait for a certain amount of time, in
89
	 * milli-seconds (1/1000th of a second).
90
	 */
91
	void wait(time_t mill_sec);
92
93
	/*
94
	 * Wakeup any waiters.
95
	 */
96
	virtual void wakeup();
97
98
private:
99
	pthread_cond_t	iCondition;
100
};
101
102
#endif
103