2022-09-10 23:11:26 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
|
2022-09-11 02:57:50 +00:00
|
|
|
#include "libc/calls/struct/timespec.h"
|
2022-09-10 23:11:26 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2022-10-16 19:05:08 +00:00
|
|
|
#define SEM_FAILED ((sem_t *)0)
|
|
|
|
#define SEM_MAGIC_NAMED 0xDEADBEEFu
|
|
|
|
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
|
2022-09-10 23:11:26 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2022-10-14 15:25:47 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
_Atomic(int) sem_value;
|
2022-10-16 19:05:08 +00:00
|
|
|
_Atomic(int) sem_waiters;
|
|
|
|
_Atomic(int) sem_prefs; /* named only */
|
|
|
|
unsigned sem_magic;
|
|
|
|
int64_t sem_dev; /* named only */
|
|
|
|
int64_t sem_ino; /* named only */
|
|
|
|
int sem_pid; /* unnamed only */
|
|
|
|
bool sem_lazydelete; /* named only */
|
2022-10-14 15:25:47 +00:00
|
|
|
bool sem_pshared;
|
|
|
|
};
|
|
|
|
void *sem_space[32];
|
|
|
|
};
|
2022-09-10 23:11:26 +00:00
|
|
|
} sem_t;
|
|
|
|
|
|
|
|
int sem_init(sem_t *, int, unsigned);
|
2022-10-14 15:25:47 +00:00
|
|
|
int sem_destroy(sem_t *);
|
2022-09-10 23:11:26 +00:00
|
|
|
int sem_post(sem_t *);
|
2022-10-14 15:25:47 +00:00
|
|
|
int sem_wait(sem_t *);
|
2022-09-10 23:11:26 +00:00
|
|
|
int sem_trywait(sem_t *);
|
2022-10-14 15:25:47 +00:00
|
|
|
int sem_timedwait(sem_t *, const struct timespec *);
|
|
|
|
int sem_getvalue(sem_t *, int *);
|
|
|
|
sem_t *sem_open(const char *, int, ...);
|
|
|
|
int sem_close(sem_t *);
|
2022-09-10 23:11:26 +00:00
|
|
|
int sem_unlink(const char *);
|
2022-10-16 19:05:08 +00:00
|
|
|
const char *sem_path_np(const char *, char *, size_t);
|
2022-09-10 23:11:26 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_ */
|