zoslib
z/OS C/C++ Library
Loading...
Searching...
No Matches
zos-semaphore.h
Go to the documentation of this file.
1
2// Licensed Materials - Property of IBM
3// ZOSLIB
4// (C) Copyright IBM Corp. 2020. All Rights Reserved.
5// US Government Users Restricted Rights - Use, duplication
6// or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
8
9// APIs that implement POSIX semaphores.
10
11#ifndef ZOS_SEMAPHORE_H_
12#define ZOS_SEMAPHORE_H_
13
14#include "zos-macros.h"
15
16#include <errno.h>
17#include <inttypes.h>
18#include <pthread.h>
19#include <sys/sem.h>
20
21#if __WORDSIZE == 64
22#define __SIZEOF_SEM_T 32
23#else
24#define __SIZEOF_SEM_T 16
25#endif
26
27#define SEM_FAILED ((sem_t *)0)
28
29typedef struct __sem {
30 volatile unsigned int value;
31 volatile unsigned int id; // 0 for non shared (thread), pid for share
32 volatile unsigned int waitcnt;
33 pthread_mutex_t mutex;
34 pthread_cond_t cond;
36
37typedef struct {
39} __sem_t;
40
41#define sem_t __sem_t
42
43#define sem_init __sem_init
44#define sem_post __sem_post
45#define sem_trywait __sem_trywait
46#define sem_timedwait __sem_timedwait
47#define sem_wait __sem_wait
48#define sem_getvalue __sem_getvalue
49#define sem_destroy __sem_destroy
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
56__Z_EXPORT int __sem_init(__sem_t *s0, int shared, unsigned int val);
59__Z_EXPORT int __sem_timedwait(__sem_t *s0, const struct timespec *abs_timeout);
61__Z_EXPORT int __sem_getvalue(__sem_t *s0, int *sval);
63
64__Z_EXPORT unsigned int atomic_dec(volatile unsigned int *loc);
65__Z_EXPORT unsigned int atomic_inc(volatile unsigned int *loc);
66
67#ifdef __cplusplus
68}
69#endif
70
71#endif // ZOS_SEMAPHORE_H_
Definition zos-semaphore.h:37
____sem_t * _s
Definition zos-semaphore.h:38
Definition zos-semaphore.h:29
volatile unsigned int id
Definition zos-semaphore.h:31
pthread_mutex_t mutex
Definition zos-semaphore.h:33
pthread_cond_t cond
Definition zos-semaphore.h:34
volatile unsigned int waitcnt
Definition zos-semaphore.h:32
volatile unsigned int value
Definition zos-semaphore.h:30
#define __Z_EXPORT
Definition zos-macros.h:13
struct __sem ____sem_t
__Z_EXPORT int __sem_init(__sem_t *s0, int shared, unsigned int val)
Definition zos-semaphore.cc:59
__Z_EXPORT int __sem_getvalue(__sem_t *s0, int *sval)
Definition zos-semaphore.cc:327
__Z_EXPORT unsigned int atomic_inc(volatile unsigned int *loc)
Definition zos-semaphore.cc:55
__Z_EXPORT int __sem_timedwait(__sem_t *s0, const struct timespec *abs_timeout)
Definition zos-semaphore.cc:279
__Z_EXPORT int __sem_destroy(__sem_t *s0)
Definition zos-semaphore.cc:296
__Z_EXPORT int __sem_post(__sem_t *s0)
Definition zos-semaphore.cc:126
__Z_EXPORT int __sem_trywait(__sem_t *s0)
Definition zos-semaphore.cc:167
__Z_EXPORT int __sem_wait(__sem_t *s0)
Definition zos-semaphore.cc:290
__Z_EXPORT unsigned int atomic_dec(volatile unsigned int *loc)
Definition zos-semaphore.cc:51