Skip to content

Commit f26309a

Browse files
committed
Update lightweightsemaphore.h
... to support building on zOS. Signed-off-by: v1gnesh <v1gnesh@users.noreply.github.com>
1 parent f640d28 commit f26309a

1 file changed

Lines changed: 0 additions & 76 deletions

File tree

lightweightsemaphore.h

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ extern "C" {
2828
#include <zos-semaphore.h>
2929
#elif defined(__unix__)
3030
#include <semaphore.h>
31-
#elif defined(__MVS__)
32-
#include <zos-semaphore.h>
3331

3432
#if defined(__GLIBC_PREREQ) && defined(_GNU_SOURCE)
3533
#if __GLIBC_PREREQ(2,30)
@@ -257,80 +255,6 @@ class Semaphore
257255
}
258256
}
259257
};
260-
#elif defined(__MVS__)
261-
//---------------------------------------------------------
262-
// Semaphore (MVS aka z/OS)
263-
//---------------------------------------------------------
264-
class Semaphore
265-
{
266-
private:
267-
sem_t m_sema;
268-
269-
Semaphore(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
270-
Semaphore& operator=(const Semaphore& other) MOODYCAMEL_DELETE_FUNCTION;
271-
272-
public:
273-
Semaphore(int initialCount = 0)
274-
{
275-
assert(initialCount >= 0);
276-
int rc = sem_init(&m_sema, 0, initialCount);
277-
assert(rc == 0);
278-
(void)rc;
279-
}
280-
281-
~Semaphore()
282-
{
283-
sem_destroy(&m_sema);
284-
}
285-
286-
bool wait()
287-
{
288-
// http://stackoverflow.com/questions/2013181/gdb-causes-sem-wait-to-fail-with-eintr-error
289-
int rc;
290-
do {
291-
rc = sem_wait(&m_sema);
292-
} while (rc == -1 && errno == EINTR);
293-
return rc == 0;
294-
}
295-
296-
bool try_wait()
297-
{
298-
int rc;
299-
do {
300-
rc = sem_trywait(&m_sema);
301-
} while (rc == -1 && errno == EINTR);
302-
return rc == 0;
303-
}
304-
305-
bool timed_wait(std::uint64_t usecs)
306-
{
307-
struct timespec ts;
308-
const int usecs_in_1_sec = 1000000;
309-
const int nsecs_in_1_sec = 1000000000;
310-
311-
ts.tv_sec = usecs / usecs_in_1_sec;
312-
ts.tv_nsec = (usecs % usecs_in_1_sec) * 1000;
313-
314-
int rc;
315-
do {
316-
rc = sem_timedwait(&m_sema, &ts);
317-
} while (rc == -1 && errno == EINTR);
318-
return rc == 0;
319-
}
320-
321-
void signal()
322-
{
323-
while (sem_post(&m_sema) == -1);
324-
}
325-
326-
void signal(int count)
327-
{
328-
while (count-- > 0)
329-
{
330-
while (sem_post(&m_sema) == -1);
331-
}
332-
}
333-
};
334258
#else
335259
#error Unsupported platform! (No semaphore wrapper available)
336260
#endif

0 commit comments

Comments
 (0)