mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
60cb435cb4
If threads are being used, then fork() will now acquire and release and runtime locks so that fork() may be safely used from threads. This also makes vfork() thread safe, because pthread mutexes will do nothing when the process is a child of vfork(). More torture tests have been written to confirm this all works like a charm. Additionally: - Invent hexpcpy() api - Rename nsync_malloc_() to kmalloc() - Complete posix named semaphore implementation - Make pthread_create() asynchronous signal safe - Add rm, rmdir, and touch to command interpreter builtins - Invent sigisprecious() and modify sigset functions to use it - Add unit tests for posix_spawn() attributes and fix its bugs One unresolved problem is the reclaiming of *NSYNC waiter memory in the forked child processes, within apps which have threads waiting on locks
42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
#ifndef COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
|
|
#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
|
|
#include "libc/calls/struct/timespec.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#define SEM_FAILED ((sem_t *)0)
|
|
#define SEM_MAGIC_NAMED 0xDEADBEEFu
|
|
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
|
|
|
|
typedef struct {
|
|
union {
|
|
struct {
|
|
_Atomic(int) sem_value;
|
|
_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 */
|
|
bool sem_pshared;
|
|
};
|
|
void *sem_space[32];
|
|
};
|
|
} sem_t;
|
|
|
|
int sem_init(sem_t *, int, unsigned);
|
|
int sem_destroy(sem_t *);
|
|
int sem_post(sem_t *);
|
|
int sem_wait(sem_t *);
|
|
int sem_trywait(sem_t *);
|
|
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 *);
|
|
int sem_unlink(const char *);
|
|
const char *sem_path_np(const char *, char *, size_t);
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_ */
|