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
44 lines
1.4 KiB
C
44 lines
1.4 KiB
C
#ifndef COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_
|
|
#define COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_
|
|
#include "libc/intrin/nopl.internal.h"
|
|
#include "libc/thread/thread.h"
|
|
#include "libc/thread/tls.h"
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
hidden extern int __vforked;
|
|
hidden extern bool __time_critical;
|
|
hidden extern unsigned __sighandrvas[NSIG];
|
|
hidden extern unsigned __sighandflags[NSIG];
|
|
hidden extern pthread_mutex_t __fds_lock_obj;
|
|
hidden extern pthread_mutex_t __sig_lock_obj;
|
|
hidden extern const struct NtSecurityAttributes kNtIsInheritable;
|
|
|
|
void __fds_lock(void);
|
|
void __fds_unlock(void);
|
|
void __fds_funlock(void);
|
|
void __sig_lock(void);
|
|
void __sig_unlock(void);
|
|
void __sig_funlock(void);
|
|
|
|
#ifdef _NOPL0
|
|
#define __fds_lock() _NOPL0("__threadcalls", __fds_lock)
|
|
#define __fds_unlock() _NOPL0("__threadcalls", __fds_unlock)
|
|
#else
|
|
#define __fds_lock() (__threaded ? __fds_lock() : 0)
|
|
#define __fds_unlock() (__threaded ? __fds_unlock() : 0)
|
|
#endif
|
|
|
|
#ifdef _NOPL0
|
|
#define __sig_lock() _NOPL0("__threadcalls", __sig_lock)
|
|
#define __sig_unlock() _NOPL0("__threadcalls", __sig_unlock)
|
|
#else
|
|
#define __sig_lock() (__threaded ? __sig_lock() : 0)
|
|
#define __sig_unlock() (__threaded ? __sig_unlock() : 0)
|
|
#endif
|
|
|
|
#define __vforked (__tls_enabled && (__get_tls()->tib_flags & TIB_FLAG_VFORKED))
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_ */
|