libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
Semaphore.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// $Id: Semaphore.h,v 1.5 2012/05/20 04:12:18 vlg Exp $
4
//------------------------------------------------------------------------------
5
// Semaphore.h
6
//------------------------------------------------------------------------------
7
// Copyright (c) 2000 by Vladislav Grinchenko
8
//
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Library General Public
11
// License as published by the Free Software Foundation; either
12
// version 2 of the License, or (at your option) any later version.
13
//------------------------------------------------------------------------------
14
15
#ifndef SEMAPHORE_H
16
#define SEMAPHORE_H
17
18
#if !defined(WIN32)
19
20
#include <sys/types.h>
21
#include <sys/ipc.h>
22
#include <sys/sem.h>
23
24
#include "
assa/Assure.h
"
// trace() & Assert family
25
26
namespace
ASSA {
27
67
class
Semaphore
68
{
69
public
:
71
Semaphore
();
72
74
virtual
~Semaphore
();
75
83
int
create
(key_t key_,
int
initval_ = 1);
84
94
int
open
(key_t key_);
95
105
void
close
();
106
115
void
remove
();
116
120
void
wait
();
121
125
void
signal
();
126
131
void
op
(
int
val_);
132
134
key_t
key
()
const
{
return
m_key
; }
135
137
int
id
()
const
{
return
m_id
; }
138
142
void
dump
(
void
)
const
;
143
144
protected
:
147
void
init
();
148
149
protected
:
151
key_t
m_key
;
152
154
int
m_id
;
155
156
protected
:
157
static
const
int
BIGCOUNT
;
158
161
static
sembuf
m_op_lock
[2];
162
166
static
sembuf
m_op_endcreate
[2];
167
171
static
sembuf
m_op_open
[2];
172
176
static
sembuf
m_op_close
[3];
177
180
static
sembuf
m_op_unlock
[1];
181
186
static
sembuf
m_op_op
[1];
187
};
188
189
inline
190
Semaphore::
191
Semaphore
()
192
{
193
trace_with_mask
(
"Semaphore::Semaphore"
,
SEM
);
194
195
init
();
196
}
197
198
inline
199
Semaphore::
200
~Semaphore
()
201
{
202
trace_with_mask
(
"Semaphore::~Semaphore"
,
SEM
);
203
204
if
(
m_id
> 0) {
205
this->
close
();
206
}
207
}
208
209
inline
void
210
Semaphore::
211
init
()
212
{
213
m_key
= (key_t) -1;
214
m_id
= -1;
215
}
216
217
inline
void
218
Semaphore::
219
wait
()
220
{
221
trace_with_mask
(
"Semaphore::wait"
,
SEM
);
222
op
(-1);
223
}
224
225
inline
void
226
Semaphore::
227
signal
()
228
{
229
trace_with_mask
(
"Semaphore::signal"
,
SEM
);
230
op
(1);
231
}
232
233
}
// end namespace ASSA
234
235
#endif
/* !defined(WIN32) */
236
237
#endif
/* SEMAPHORE_H */
Generated on Tue Jun 19 2012 07:41:56 for libassa by
1.8.1.1