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
25{
26 max = num;
27 if (sem_init(&sem, 0, num)) {
28 fprintf(STD_OUT, "Error initializing semaphore");
29 }
30}
31
33{
34 if (sem_destroy(&sem)) {
35 fprintf(STD_OUT, "Error destroying semaphore");
36 }
37}
38
39int32_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
48int32_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
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
70int32_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
int32_t retVal
double num
int32_t Trylock()
Definition qsem.cxx:57
int32_t Query()
Definition qsem.cxx:70
int32_t Unlock()
Definition qsem.cxx:48
~qSem()
Definition qsem.cxx:32
int32_t Lock()
Definition qsem.cxx:39
qSem(int32_t num=1)
Definition qsem.cxx:24
GLsizei const GLfloat * value
Definition glcorearb.h:819
#define STD_OUT
Definition qsem.cxx:21