mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-31 17:52:27 +00:00
Make more improvements to threads and mappings
- NetBSD should now have faster synchronization - POSIX barriers may now be shared across processes - An edge case with memory map tracking has been fixed - Grand Central Dispatch is no longer used on MacOS ARM64 - POSIX mutexes in normal mode now use futexes across processes
This commit is contained in:
parent
2187d6d2dd
commit
e398f3887c
20 changed files with 566 additions and 171 deletions
|
@ -17,8 +17,9 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/nsync/counter.h"
|
||||
|
||||
/**
|
||||
* Initializes barrier.
|
||||
|
@ -28,16 +29,17 @@
|
|||
* before the barrier is released, which must be greater than zero
|
||||
* @return 0 on success, or error number on failure
|
||||
* @raise EINVAL if `count` isn't greater than zero
|
||||
* @raise ENOMEM if insufficient memory exists
|
||||
*/
|
||||
errno_t pthread_barrier_init(pthread_barrier_t *barrier,
|
||||
const pthread_barrierattr_t *attr,
|
||||
unsigned count) {
|
||||
nsync_counter c;
|
||||
if (!count)
|
||||
return EINVAL;
|
||||
if (!(c = nsync_counter_new(count)))
|
||||
return ENOMEM;
|
||||
*barrier = (pthread_barrier_t){._nsync = c};
|
||||
if (count > INT_MAX)
|
||||
return EINVAL;
|
||||
barrier->_count = count;
|
||||
barrier->_pshared = attr ? *attr : PTHREAD_PROCESS_PRIVATE;
|
||||
atomic_store_explicit(&barrier->_counter, count, memory_order_relaxed);
|
||||
atomic_store_explicit(&barrier->_waiters, 0, memory_order_relaxed);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue