Project
Loading...
Searching...
No Matches
qsem.cxx
Go to the documentation of this file.
1
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3
// All rights not expressly granted are reserved.
4
//
5
// This software is distributed under the terms of the GNU General Public
6
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7
//
8
// In applying this license CERN does not waive the privileges and immunities
9
// granted to it by virtue of its status as an Intergovernmental Organization
10
// or submit itself to any jurisdiction.
11
14
15
#include <cerrno>
16
#include <cstdio>
17
18
#include "
qsem.h
"
19
20
#ifndef STD_OUT
21
#define STD_OUT stdout
22
#endif
23
24
qSem::qSem
(int32_t
num
)
25
{
26
max =
num
;
27
if
(sem_init(&sem, 0,
num
)) {
28
fprintf(
STD_OUT
,
"Error initializing semaphore"
);
29
}
30
}
31
32
qSem::~qSem
()
33
{
34
if
(sem_destroy(&sem)) {
35
fprintf(
STD_OUT
,
"Error destroying semaphore"
);
36
}
37
}
38
39
int32_t
qSem::Lock
()
40
{
41
int32_t
retVal
;
42
if
((
retVal
= sem_wait(&sem))) {
43
fprintf(
STD_OUT
,
"Error locking semaphore"
);
44
}
45
return
(
retVal
);
46
}
47
48
int32_t
qSem::Unlock
()
49
{
50
int32_t
retVal
;
51
if
((
retVal
= sem_post(&sem))) {
52
fprintf(
STD_OUT
,
"Error unlocking semaphire"
);
53
}
54
return
(
retVal
);
55
}
56
57
int32_t
qSem::Trylock
()
58
{
59
int32_t
retVal
= sem_trywait(&sem);
60
if
(
retVal
) {
61
if
(errno ==
EAGAIN
) {
62
return
(
EBUSY
);
63
}
64
return
(-1);
65
}
66
return
(0);
67
}
68
69
#ifndef _WIN32
70
int32_t
qSem::Query
()
71
{
72
int32_t
value
;
73
if
(sem_getvalue(&sem, &
value
) != 0) {
74
value
= -1;
75
}
76
return
(
value
);
77
}
78
#endif
retVal
int32_t retVal
Definition
GPUReconstruction.cxx:57
num
double num
Definition
bench_Clusterizer.cxx:122
qSem::Trylock
int32_t Trylock()
Definition
qsem.cxx:57
qSem::Query
int32_t Query()
Definition
qsem.cxx:70
qSem::Unlock
int32_t Unlock()
Definition
qsem.cxx:48
qSem::~qSem
~qSem()
Definition
qsem.cxx:32
qSem::Lock
int32_t Lock()
Definition
qsem.cxx:39
qSem::qSem
qSem(int32_t num=1)
Definition
qsem.cxx:24
value
GLsizei const GLfloat * value
Definition
glcorearb.h:819
EBUSY
#define EBUSY
Definition
pthread_mutex_win32_wrapper.h:25
EAGAIN
#define EAGAIN
Definition
pthread_mutex_win32_wrapper.h:29
STD_OUT
#define STD_OUT
Definition
qsem.cxx:21
qsem.h
GPU
GPUTracking
utils
qsem.cxx
Generated on Tue Feb 25 2025 17:03:27 for Project by
1.9.8