mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Add shared memory apis to redbean
You can now do things like implement mutexes using futexes in your redbean lua code. This provides the fastest possible inter-process communication for your production systems when SQLite alone as ipc or things like pipes aren't sufficient.
This commit is contained in:
parent
81ee11a16e
commit
7822917fc2
21 changed files with 988 additions and 23 deletions
1
third_party/nsync/atomic.internal.h
vendored
1
third_party/nsync/atomic.internal.h
vendored
|
@ -1,6 +1,7 @@
|
|||
#ifndef NSYNC_ATOMIC_INTERNAL_H_
|
||||
#define NSYNC_ATOMIC_INTERNAL_H_
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/cmpxchg.h"
|
||||
#include "third_party/nsync/atomic.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
|
6
third_party/nsync/futex.c
vendored
6
third_party/nsync/futex.c
vendored
|
@ -106,7 +106,7 @@ int nsync_futex_wait_ (int *p, int expect, char pshare, struct timespec *timeout
|
|||
uint32_t ms;
|
||||
int rc, op, fop;
|
||||
|
||||
if (!FUTEX_IS_SUPPORTED) {
|
||||
if (!FUTEX_IS_SUPPORTED || (IsWindows() && pshare)) {
|
||||
nsync_yield_ ();
|
||||
if (timeout) {
|
||||
return -EINTR;
|
||||
|
@ -166,12 +166,12 @@ int nsync_futex_wait_ (int *p, int expect, char pshare, struct timespec *timeout
|
|||
}
|
||||
|
||||
int nsync_futex_wake_ (int *p, int count, char pshare) {
|
||||
int rc, op, fop;
|
||||
int e, rc, op, fop;
|
||||
int wake (void *, int, int) asm ("_futex");
|
||||
|
||||
ASSERT (count == 1 || count == INT_MAX);
|
||||
|
||||
if (!FUTEX_IS_SUPPORTED) {
|
||||
if (!FUTEX_IS_SUPPORTED || (IsWindows() && pshare)) {
|
||||
nsync_yield_ ();
|
||||
return 0;
|
||||
}
|
||||
|
|
3
third_party/nsync/malloc.c
vendored
3
third_party/nsync/malloc.c
vendored
|
@ -21,6 +21,7 @@
|
|||
#include "libc/intrin/extend.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "third_party/nsync/common.internal.h"
|
||||
#include "third_party/nsync/malloc.internal.h"
|
||||
// clang-format off
|
||||
|
@ -45,7 +46,7 @@ void *nsync_malloc_ (size_t size) {
|
|||
if (!nsync_malloc_endptr_) nsync_malloc_endptr_ = start;
|
||||
nsync_malloc_endptr_ =
|
||||
_extend (start, nsync_malloc_total_, nsync_malloc_endptr_,
|
||||
kMemtrackNsyncStart + kMemtrackNsyncSize);
|
||||
MAP_PRIVATE, kMemtrackNsyncStart + kMemtrackNsyncSize);
|
||||
atomic_store_explicit (&nsync_malloc_lock_, 0, memory_order_relaxed);
|
||||
return start + offset;
|
||||
}
|
||||
|
|
2
third_party/nsync/mu_semaphore.h
vendored
2
third_party/nsync/mu_semaphore.h
vendored
|
@ -5,7 +5,7 @@
|
|||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef struct nsync_semaphore_s_ {
|
||||
void *sem_space[32]; /* space used by implementation */
|
||||
void *sem_space[1]; /* [jart] reduced to 8 bytes */
|
||||
} nsync_semaphore;
|
||||
|
||||
/* Initialize *s; the initial value is 0. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue