2021-02-11 21:55:35 +03:30
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-11 21:55:35 +03:30
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-07-15 15:22:45 +02:00
|
|
|
// Includes essentially mandated by POSIX:
|
|
|
|
|
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/semaphore.h.html
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2021-04-14 22:45:21 +02:00
|
|
|
#include <limits.h>
|
2021-04-14 04:29:39 +02:00
|
|
|
#include <pthread.h>
|
2021-02-11 21:55:35 +03:30
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
2022-07-14 03:07:06 +03:00
|
|
|
#define SEM_FLAG_PROCESS_SHARED (1 << 0)
|
2022-07-14 03:31:12 +03:00
|
|
|
#define SEM_FLAG_NAMED (1 << 1)
|
2021-04-14 04:29:39 +02:00
|
|
|
typedef struct {
|
2022-07-14 03:02:08 +03:00
|
|
|
uint32_t magic;
|
2021-07-05 15:10:34 +03:00
|
|
|
uint32_t value;
|
2022-07-14 03:07:06 +03:00
|
|
|
uint8_t flags;
|
2021-04-14 04:29:39 +02:00
|
|
|
} sem_t;
|
2021-02-11 21:55:35 +03:30
|
|
|
|
|
|
|
|
int sem_close(sem_t*);
|
|
|
|
|
int sem_destroy(sem_t*);
|
|
|
|
|
int sem_getvalue(sem_t*, int*);
|
|
|
|
|
int sem_init(sem_t*, int, unsigned int);
|
2022-04-01 20:58:27 +03:00
|
|
|
sem_t* sem_open(char const*, int, ...);
|
2021-02-11 21:55:35 +03:30
|
|
|
int sem_post(sem_t*);
|
|
|
|
|
int sem_trywait(sem_t*);
|
2022-04-01 20:58:27 +03:00
|
|
|
int sem_unlink(char const*);
|
2021-02-11 21:55:35 +03:30
|
|
|
int sem_wait(sem_t*);
|
2021-07-05 15:10:34 +03:00
|
|
|
int sem_timedwait(sem_t*, const struct timespec* abstime);
|
2021-02-11 21:55:35 +03:30
|
|
|
|
2022-03-16 18:02:28 +00:00
|
|
|
#define SEM_FAILED ((sem_t*)0)
|
2021-04-14 22:45:21 +02:00
|
|
|
#define SEM_VALUE_MAX INT_MAX
|
|
|
|
|
|
2021-02-11 21:55:35 +03:30
|
|
|
__END_DECLS
|