ladybird/Userland/Libraries/LibPthread/semaphore.h
Sergey Bugaev 690141ff8b LibPthread: Reimplement semaphores
This implementation does not use locking or condition variables
internally; it's purely based on atomics and futexes.

Notably, concurrent sem_wait() and sem_post() calls can run *completely
in parallel* without slowing each other down, as long as there are empty
slots for them all to succeed without blocking.

Additionally, sem_wait() never executes an atomic operation with release
ordering, and sem_post() never executes an atomic operation with acquire
ordering (unless you count the syscall). This means the compiler and the
hardware are free to reorder code *into* the critical section.
2021-07-05 20:26:01 +02:00

34 lines
628 B
C

/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <limits.h>
#include <pthread.h>
#include <sys/cdefs.h>
#include <sys/types.h>
__BEGIN_DECLS
typedef struct {
uint32_t value;
} sem_t;
int sem_close(sem_t*);
int sem_destroy(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_init(sem_t*, int, unsigned int);
sem_t* sem_open(const char*, int, ...);
int sem_post(sem_t*);
int sem_trywait(sem_t*);
int sem_unlink(const char*);
int sem_wait(sem_t*);
int sem_timedwait(sem_t*, const struct timespec* abstime);
#define SEM_VALUE_MAX INT_MAX
__END_DECLS