mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
464858dbb4
This fixes a regression in mmap(MAP_FIXED) on Windows caused by a recent revision. This change also fixes ZipOS so it no longer needs a MAP_FIXED mapping to open files from the PKZIP store. The memory mapping mutex was implemented incorrectly earlier which meant that ftrace and strace could cause cause crashes. This lock and other recursive mutexes are rewritten so that it should be provable that recursive mutexes in cosmopolitan are asynchronous signal safe.
23 lines
946 B
C
23 lines
946 B
C
#ifndef COSMOPOLITAN_LIBC_THREAD_LOCK_H_
|
|
#define COSMOPOLITAN_LIBC_THREAD_LOCK_H_
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#define MUTEX_DEPTH_MIN 0x00000010ull
|
|
#define MUTEX_DEPTH_MAX 0x000003f0ull
|
|
|
|
#define MUTEX_TYPE(word) ((word) & 3)
|
|
#define MUTEX_PSHARED(word) ((word) & 4)
|
|
#define MUTEX_LOCKED(word) ((word) & 8)
|
|
#define MUTEX_DEPTH(word) ((word) & MUTEX_DEPTH_MAX)
|
|
#define MUTEX_OWNER(word) ((word) >> 32)
|
|
|
|
#define MUTEX_LOCK(word) (((word) & 7) | 8)
|
|
#define MUTEX_UNLOCK(word) ((word) & 7)
|
|
#define MUTEX_SET_TYPE(word, type) (((word) & ~3ull) | (type))
|
|
#define MUTEX_SET_PSHARED(word, pshared) (((word) & ~4ull) | (pshared))
|
|
#define MUTEX_INC_DEPTH(word) ((word) + MUTEX_DEPTH_MIN)
|
|
#define MUTEX_DEC_DEPTH(word) ((word) - MUTEX_DEPTH_MIN)
|
|
#define MUTEX_SET_OWNER(word, tid) ((uint64_t)(tid) << 32 | (uint32_t)(word))
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_LIBC_THREAD_LOCK_H_ */
|