mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 17:40:30 +00:00
Iterate more on recent changes
This commit is contained in:
parent
7138399f96
commit
d0ad2694ed
22 changed files with 90 additions and 158 deletions
35
third_party/nsync/mu_semaphore_sem.c
vendored
35
third_party/nsync/mu_semaphore_sem.c
vendored
|
@ -55,12 +55,24 @@ static struct {
|
|||
static nsync_semaphore *sem_big_enough_for_sem = (nsync_semaphore *) (uintptr_t)(1 /
|
||||
(sizeof (struct sem) <= sizeof (*sem_big_enough_for_sem)));
|
||||
|
||||
static void nsync_mu_semaphore_sem_create (struct sem *f) {
|
||||
int lol;
|
||||
f->id = 0;
|
||||
ASSERT (!sys_sem_init (0, &f->id));
|
||||
if ((lol = __sys_fcntl (f->id, F_DUPFD_CLOEXEC, 50)) >= 50) {
|
||||
sys_close (f->id);
|
||||
f->id = lol;
|
||||
}
|
||||
}
|
||||
|
||||
static void nsync_mu_semaphore_sem_fork_child (void) {
|
||||
struct Dll *e;
|
||||
struct sem *f;
|
||||
for (e = dll_first (g_sems.list); e; e = dll_next (g_sems.list, e)) {
|
||||
sys_close (SEM_CONTAINER (e)->id);
|
||||
f = SEM_CONTAINER (e);
|
||||
sys_close (f->id);
|
||||
nsync_mu_semaphore_sem_create (f);
|
||||
}
|
||||
g_sems.list = 0; /* list memory is on dead thread stacks */
|
||||
(void) pthread_spin_init (&g_sems.lock, 0);
|
||||
}
|
||||
|
||||
|
@ -70,14 +82,8 @@ static void nsync_mu_semaphore_sem_init (void) {
|
|||
|
||||
/* Initialize *s; the initial value is 0. */
|
||||
void nsync_mu_semaphore_init_sem (nsync_semaphore *s) {
|
||||
int lol;
|
||||
struct sem *f = (struct sem *) s;
|
||||
f->id = 0;
|
||||
ASSERT (!sys_sem_init (0, &f->id));
|
||||
if ((lol = __sys_fcntl (f->id, F_DUPFD_CLOEXEC, 50)) >= 50) {
|
||||
sys_close (f->id);
|
||||
f->id = lol;
|
||||
}
|
||||
nsync_mu_semaphore_sem_create (f);
|
||||
cosmo_once (&g_sems.once, nsync_mu_semaphore_sem_init);
|
||||
pthread_spin_lock (&g_sems.lock);
|
||||
dll_init (&f->list);
|
||||
|
@ -86,17 +92,6 @@ void nsync_mu_semaphore_init_sem (nsync_semaphore *s) {
|
|||
STRACE ("sem_init(0, [%ld]) → 0", f->id);
|
||||
}
|
||||
|
||||
/* Releases system resources associated with *s. */
|
||||
void nsync_mu_semaphore_destroy_sem (nsync_semaphore *s) {
|
||||
int rc;
|
||||
struct sem *f = (struct sem *) s;
|
||||
ASSERT (!(rc = sys_sem_destroy (f->id)));
|
||||
pthread_spin_lock (&g_sems.lock);
|
||||
dll_remove (&g_sems.list, &f->list);
|
||||
pthread_spin_unlock (&g_sems.lock);
|
||||
STRACE ("sem_destroy(%ld) → %d", f->id, rc);
|
||||
}
|
||||
|
||||
/* Wait until the count of *s exceeds 0, and decrement it. If POSIX cancellations
|
||||
are currently disabled by the thread, then this function always succeeds. When
|
||||
they're enabled in MASKED mode, this function may return ECANCELED. Otherwise,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue