File: spl_mutex.h

package info (click to toggle)
libterralib 4.3.0+dfsg.2-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 61,564 kB
  • ctags: 37,110
  • sloc: cpp: 225,052; ansic: 31,562; makefile: 807; sh: 80; xml: 37
file content (145 lines) | stat: -rw-r--r-- 5,920 bytes parent folder | download | duplicates (3)
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
/*!

\section terms_of_use Terms of Use

libspl - the simple plugin layer library.
Copyright (C) 2004 Andreas Loeffler and Ren� Stuhr (www.unitedbytes.de).

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

\section author Author
Ren� Stuhr (www.unitedbytes.de)

*/

//---------------------------------------------------------------------------------------------------------------------------
/// @file		spl_mutex.h
/// @version	1.0
/// @brief		Cross platform mutex class.
/// @author		Ren� Stuhr
/// @remarks	All thread safe classes of SPL are derivated from this class. 
//---------------------------------------------------------------------------------------------------------------------------

#ifndef		__SPL_MUTEX_H__
#define		__SPL_MUTEX_H__

#ifndef		__SPL_PLATFORM_H__
#include	"spl_platform.h"
#endif

#if				SPL_PLATFORM == SPL_PLATFORM_LINUX
	#include	<errno.h>
	#include	<pthread.h>
#endif

#if	(SPL_PLATFORM == SPL_PLATFORM_HURD) || (SPL_PLATFORM == SPL_PLATFORM_KFREEBSD)
	#include	<errno.h>
	#include	<pthread.h>
#endif

#if				SPL_PLATFORM == SPL_PLATFORM_WIN32
	#include	<windows.h>
#endif

#ifndef		EBUSY
#define		EBUSY	16	
#endif

#if SPL_PLATFORM == SPL_PLATFORM_WIN32
	#if		defined ( SPL_MAKE_DLL )
		#define SPL_API		__declspec( dllexport )
	#elif	defined ( SPL_USE_DLL )
		#define SPL_API		__declspec( dllimport )
	#else 
		#define SPL_API	
	#endif
#else
	#define SPL_API 
#endif

namespace SPL 
{

//---------------------------------------------------------------------------------------------------------------------------
///	@brief		Multiplatform mutex class.
///	@ingroup	SPL
//---------------------------------------------------------------------------------------------------------------------------
class slcMutex
{
	//
	//-----------------------------------------------------------------------------------------------------------------------
	//***********************************************     CON/DESTRUCTION     ***********************************************
	//-----------------------------------------------------------------------------------------------------------------------
	//
public:

	//-----------------------------------------------------------------------------------------------------------------------
	///	@brief		Default constructor.
	//-----------------------------------------------------------------------------------------------------------------------
	SPL_API slcMutex( void );

	//-----------------------------------------------------------------------------------------------------------------------
	///	@brief		Default destructor.
	//-----------------------------------------------------------------------------------------------------------------------
	virtual SPL_API ~slcMutex( void );

	//
	//-----------------------------------------------------------------------------------------------------------------------
	//************************************************     MODIFICATION     *************************************************
	//-----------------------------------------------------------------------------------------------------------------------
	//
public:

	//-----------------------------------------------------------------------------------------------------------------------
	///	@brief		Locks a section - If section is already busy then block and wait until it's ready again.
	//-----------------------------------------------------------------------------------------------------------------------
	virtual void SPL_API Lock( void );

	//-----------------------------------------------------------------------------------------------------------------------
	///	@brief		Locks a section - If section is busy, return without blocking.
	///	@return		The method returns one of the following values:
	///	@retval		EBUSY | Section is still locked from another caller.
	///	@retval		0     | Section is now locked by current call.
	//-----------------------------------------------------------------------------------------------------------------------
	virtual long SPL_API TryLock( void );

	//-----------------------------------------------------------------------------------------------------------------------
	///	@brief		Unlocks a section.
	//-----------------------------------------------------------------------------------------------------------------------
	virtual void SPL_API Unlock( void );

	//
	//-----------------------------------------------------------------------------------------------------------------------
	//*************************************************     ATTRIBUTES     **************************************************
	//-----------------------------------------------------------------------------------------------------------------------
	//
private:

#if	SPL_PLATFORM == SPL_PLATFORM_WIN32		
	
	HANDLE				m_access;				///< WIN32 mutex.
	SECURITY_ATTRIBUTES m_sa;

#elif (SPL_PLATFORM == SPL_PLATFORM_LINUX) || (SPL_PLATFORM == SPL_PLATFORM_HURD) || (SPL_PLATFORM_KFREEBSD)

	pthread_mutex_t		m_access;				///< POSIX mutex.

#endif	
};

} // End of namespace SPL

#endif	// __SPL_MUTEX_H__