mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-03 08:20:28 +00:00
Use *NSYNC for POSIX threads locking APIs
Condition variables, barriers, and r/w locks now work very well.
This commit is contained in:
parent
3de35e196c
commit
b5cb71ab84
197 changed files with 3734 additions and 3817 deletions
|
@ -19,14 +19,16 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sched-sysv.internal.h"
|
||||
#include "libc/calls/struct/sigaltstack.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/wait0.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/gc.internal.h"
|
||||
|
@ -35,11 +37,16 @@
|
|||
#include "libc/sysv/consts/clone.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/ss.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/spawn.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/thread/wait0.internal.h"
|
||||
|
||||
STATIC_YOINK("nsync_mu_lock");
|
||||
STATIC_YOINK("nsync_mu_unlock");
|
||||
|
||||
#define MAP_ANON_OPENBSD 0x1000
|
||||
#define MAP_STACK_OPENBSD 0x4000
|
||||
|
@ -53,7 +60,12 @@ void _pthread_free(struct PosixThread *pt) {
|
|||
if (pt->ownstack && //
|
||||
pt->attr.stackaddr && //
|
||||
pt->attr.stackaddr != MAP_FAILED) {
|
||||
munmap(&pt->attr.stackaddr, pt->attr.stacksize);
|
||||
if (munmap(pt->attr.stackaddr, pt->attr.stacksize)) {
|
||||
notpossible;
|
||||
}
|
||||
}
|
||||
if (pt->altstack) {
|
||||
free(pt->altstack);
|
||||
}
|
||||
free(pt);
|
||||
}
|
||||
|
@ -61,6 +73,15 @@ void _pthread_free(struct PosixThread *pt) {
|
|||
static int PosixThread(void *arg, int tid) {
|
||||
struct PosixThread *pt = arg;
|
||||
enum PosixThreadStatus status;
|
||||
struct sigaltstack ss;
|
||||
if (pt->altstack) {
|
||||
ss.ss_flags = 0;
|
||||
ss.ss_size = SIGSTKSZ;
|
||||
ss.ss_sp = pt->altstack;
|
||||
if (sigaltstack(&ss, 0)) {
|
||||
notpossible;
|
||||
}
|
||||
}
|
||||
if (pt->attr.inheritsched == PTHREAD_EXPLICIT_SCHED) {
|
||||
_pthread_reschedule(pt);
|
||||
}
|
||||
|
@ -254,6 +275,11 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
|||
}
|
||||
}
|
||||
|
||||
// setup signal handler stack
|
||||
if (_wantcrashreports && !IsWindows()) {
|
||||
pt->altstack = malloc(SIGSTKSZ);
|
||||
}
|
||||
|
||||
// set initial status
|
||||
switch (pt->attr.detachstate) {
|
||||
case PTHREAD_CREATE_JOINABLE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue