Add *NSYNC to libc/isystem

This commit is contained in:
Justine Tunney 2022-09-13 01:46:29 -07:00
parent 6f7d0cb1c3
commit 22b63d0b98
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
32 changed files with 286 additions and 119 deletions

164
Makefile
View file

@ -128,6 +128,7 @@ include libc/mem/mem.mk #─┐
include libc/zipos/zipos.mk # ├──DYNAMIC RUNTIME include libc/zipos/zipos.mk # ├──DYNAMIC RUNTIME
include third_party/gdtoa/gdtoa.mk # │ You can now use stdio include third_party/gdtoa/gdtoa.mk # │ You can now use stdio
include libc/time/time.mk # │ You can finally call malloc() include libc/time/time.mk # │ You can finally call malloc()
include third_party/nsync/mem/mem.mk # │
include libc/thread/thread.mk # │ include libc/thread/thread.mk # │
include libc/stdio/stdio.mk # │ include libc/stdio/stdio.mk # │
include third_party/libcxx/libcxx.mk # │ include third_party/libcxx/libcxx.mk # │
@ -265,98 +266,101 @@ o/$(MODE)/srcs-old.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(SRCS
o/$(MODE)/hdrs-old.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS) $(INCS),$(dir $(x)))) o/$(MODE)/hdrs-old.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(HDRS) $(INCS),$(dir $(x))))
$(file >$@) $(foreach x,$(HDRS) $(INCS),$(file >>$@,$(x))) $(file >$@) $(foreach x,$(HDRS) $(INCS),$(file >>$@,$(x)))
TAGS: .UNSANDBOXED = 1 TAGS: private .UNSANDBOXED = 1
TAGS: o/$(MODE)/srcs-old.txt $(SRCS) TAGS: o/$(MODE)/srcs-old.txt $(SRCS)
@$(RM) $@ @$(RM) $@
@$(TAGS) $(TAGSFLAGS) -L $< -o $@ @$(TAGS) $(TAGSFLAGS) -L $< -o $@
HTAGS: .UNSANDBOXED = 1 HTAGS: private .UNSANDBOXED = 1
HTAGS: o/$(MODE)/hdrs-old.txt $(HDRS) HTAGS: o/$(MODE)/hdrs-old.txt $(HDRS)
@$(RM) $@ @$(RM) $@
@build/htags -L $< -o $@ @build/htags -L $< -o $@
loc: .UNSANDBOXED = 1 loc: private .UNSANDBOXED = 1
loc: o/$(MODE)/tool/build/summy.com loc: o/$(MODE)/tool/build/summy.com
find -name \*.h -or -name \*.c -or -name \*.S | \ find -name \*.h -or -name \*.c -or -name \*.S | \
$(XARGS) wc -l | grep total | awk '{print $$1}' | $< $(XARGS) wc -l | grep total | awk '{print $$1}' | $<
COSMOPOLITAN_OBJECTS = \ # PLEASE: MAINTAIN TOPOLOGICAL ORDER
NET_HTTP \ # FROM HIGHEST LEVEL TO LOWEST LEVEL
LIBC_DNS \ COSMOPOLITAN_OBJECTS = \
LIBC_SOCK \ NET_HTTP \
LIBC_NT_WS2_32 \ LIBC_DNS \
LIBC_NT_IPHLPAPI \ LIBC_SOCK \
LIBC_NT_MSWSOCK \ LIBC_NT_WS2_32 \
LIBC_X \ LIBC_NT_IPHLPAPI \
THIRD_PARTY_GETOPT \ LIBC_NT_MSWSOCK \
LIBC_LOG \ LIBC_X \
LIBC_TIME \ THIRD_PARTY_GETOPT \
LIBC_ZIPOS \ LIBC_LOG \
THIRD_PARTY_ZLIB \ LIBC_TIME \
THIRD_PARTY_MUSL \ LIBC_ZIPOS \
LIBC_STDIO \ THIRD_PARTY_ZLIB \
THIRD_PARTY_GDTOA \ THIRD_PARTY_MUSL \
THIRD_PARTY_REGEX \ LIBC_STDIO \
LIBC_MEM \ THIRD_PARTY_GDTOA \
THIRD_PARTY_DLMALLOC \ THIRD_PARTY_REGEX \
LIBC_RUNTIME \ LIBC_THREAD \
THIRD_PARTY_NSYNC \ THIRD_PARTY_NSYNC_MALLOC \
LIBC_ELF \ LIBC_MEM \
LIBC_CALLS \ THIRD_PARTY_DLMALLOC \
LIBC_SYSV_CALLS \ LIBC_RUNTIME \
LIBC_NT_PSAPI \ THIRD_PARTY_NSYNC \
LIBC_NT_POWRPROF \ LIBC_ELF \
LIBC_NT_PDH \ LIBC_CALLS \
LIBC_NT_GDI32 \ LIBC_SYSV_CALLS \
LIBC_NT_COMDLG32 \ LIBC_VGA \
LIBC_NT_URL \ LIBC_NT_PSAPI \
LIBC_NT_USER32 \ LIBC_NT_POWRPROF \
LIBC_NT_NTDLL \ LIBC_NT_PDH \
LIBC_NT_ADVAPI32 \ LIBC_NT_GDI32 \
LIBC_FMT \ LIBC_NT_COMDLG32 \
THIRD_PARTY_COMPILER_RT \ LIBC_NT_URL \
LIBC_THREAD \ LIBC_NT_USER32 \
LIBC_TINYMATH \ LIBC_NT_NTDLL \
THIRD_PARTY_XED \ LIBC_NT_ADVAPI32 \
LIBC_STR \ LIBC_FMT \
LIBC_SYSV \ THIRD_PARTY_COMPILER_RT \
LIBC_INTRIN \ LIBC_TINYMATH \
LIBC_NT_KERNEL32 \ THIRD_PARTY_XED \
LIBC_NEXGEN32E \ LIBC_STR \
LIBC_VGA LIBC_SYSV \
LIBC_INTRIN \
LIBC_NT_KERNEL32 \
LIBC_NEXGEN32E
COSMOPOLITAN_HEADERS = \ COSMOPOLITAN_HEADERS = \
APE \ APE \
LIBC \ LIBC \
LIBC_CALLS \ LIBC_CALLS \
LIBC_DNS \ LIBC_DNS \
LIBC_ELF \ LIBC_ELF \
LIBC_FMT \ LIBC_FMT \
LIBC_INTRIN \ LIBC_INTRIN \
LIBC_LOG \ LIBC_LOG \
LIBC_MEM \ LIBC_MEM \
LIBC_NEXGEN32E \ LIBC_NEXGEN32E \
LIBC_NT \ LIBC_NT \
LIBC_RUNTIME \ LIBC_RUNTIME \
LIBC_SOCK \ LIBC_SOCK \
LIBC_STDIO \ LIBC_STDIO \
THIRD_PARTY_NSYNC \ THIRD_PARTY_NSYNC \
THIRD_PARTY_XED \ THIRD_PARTY_XED \
LIBC_STR \ LIBC_STR \
LIBC_SYSV \ LIBC_SYSV \
LIBC_THREAD \ LIBC_THREAD \
LIBC_TIME \ LIBC_TIME \
LIBC_TINYMATH \ LIBC_TINYMATH \
LIBC_X \ LIBC_X \
LIBC_ZIPOS \ LIBC_ZIPOS \
LIBC_VGA \ LIBC_VGA \
NET_HTTP \ NET_HTTP \
THIRD_PARTY_DLMALLOC \ THIRD_PARTY_DLMALLOC \
THIRD_PARTY_GDTOA \ THIRD_PARTY_GDTOA \
THIRD_PARTY_GETOPT \ THIRD_PARTY_GETOPT \
THIRD_PARTY_MUSL \ THIRD_PARTY_MUSL \
THIRD_PARTY_ZLIB \ THIRD_PARTY_ZLIB \
THIRD_PARTY_ZLIB_GZ \ THIRD_PARTY_ZLIB_GZ \
THIRD_PARTY_REGEX THIRD_PARTY_REGEX
o/$(MODE)/cosmopolitan.a: \ o/$(MODE)/cosmopolitan.a: \
@ -370,7 +374,7 @@ o/cosmopolitan.h: \
$(file >$(TMPDIR)/$(subst /,_,$@),libc/integral/normalize.inc $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))) $(file >$(TMPDIR)/$(subst /,_,$@),libc/integral/normalize.inc $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)))
@$(COMPILE) -AROLLUP -T$@ o/$(MODE)/tool/build/rollup.com @$(TMPDIR)/$(subst /,_,$@) >$@ @$(COMPILE) -AROLLUP -T$@ o/$(MODE)/tool/build/rollup.com @$(TMPDIR)/$(subst /,_,$@) >$@
o/cosmopolitan.html: .UNSANDBOXED = 1 o/cosmopolitan.html: private .UNSANDBOXED = 1
o/cosmopolitan.html: \ o/cosmopolitan.html: \
o/$(MODE)/third_party/chibicc/chibicc.com.dbg \ o/$(MODE)/third_party/chibicc/chibicc.com.dbg \
$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))) \ $(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))) \

View file

@ -163,15 +163,15 @@ o/$(MODE)%/.zip.o: %
# and it would be too costly in terms of make latency to have every # and it would be too costly in terms of make latency to have every
# header file depend on $(HDRS) and $(INCS). # header file depend on $(HDRS) and $(INCS).
o/%.h.ok: .UNSANDBOXED = 1 o/%.h.ok: private .UNSANDBOXED = 1
o/%.h.ok: %.h o/%.h.ok: %.h
@$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $< @$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $<
o/$(MODE)/%.h.ok: .UNSANDBOXED = 1 o/$(MODE)/%.h.ok: private .UNSANDBOXED = 1
o/$(MODE)/%.h.ok: %.h o/$(MODE)/%.h.ok: %.h
@$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $< @$(COMPILE) -ACHECK.h $(COMPILE.c) -xc -g0 -o $@ $<
o/$(MODE)/%.hh.ok: .UNSANDBOXED = 1 o/$(MODE)/%.hh.ok: private .UNSANDBOXED = 1
o/$(MODE)/%.hh.ok: %.hh o/$(MODE)/%.hh.ok: %.hh
@$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $<
@ -179,7 +179,7 @@ o/%.okk: .UNSANDBOXED = 1
o/%.okk: % o/%.okk: %
@$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $<
o/$(MODE)/%.okk: .UNSANDBOXED = 1 o/$(MODE)/%.okk: private .UNSANDBOXED = 1
o/$(MODE)/%.okk: % o/$(MODE)/%.okk: %
@$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $< @$(COMPILE) -ACHECK.h $(COMPILE.cxx) -xc++ -g0 -o $@ $<
@ -207,19 +207,19 @@ MAKE_SYMTAB_ZIP = \
################################################################################ ################################################################################
# EMACS ASSEMBLY GENERATION # EMACS ASSEMBLY GENERATION
o/$(MODE)/%-gcc.asm: .UNSANDBOXED = 1 o/$(MODE)/%-gcc.asm: private .UNSANDBOXED = 1
o/$(MODE)/%-gcc.asm: %.c o/$(MODE)/%-gcc.asm: %.c
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
o/$(MODE)/%-gcc.asm: .UNSANDBOXED = 1 o/$(MODE)/%-gcc.asm: private .UNSANDBOXED = 1
o/$(MODE)/%-gcc.asm: %.cc o/$(MODE)/%-gcc.asm: %.cc
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.cxx) -S -g0 $(OUTPUT_OPTION) $< @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.cxx) -S -g0 $(OUTPUT_OPTION) $<
o/$(MODE)/%-clang.asm: .UNSANDBOXED = 1 o/$(MODE)/%-clang.asm: private .UNSANDBOXED = 1
o/$(MODE)/%-clang.asm: %.c o/$(MODE)/%-clang.asm: %.c
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $< @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -S -g0 $(OUTPUT_OPTION) $<
o/$(MODE)/%-clang.asm: CC = $(CLANG) o/$(MODE)/%-clang.asm: CC = $(CLANG)
o/$(MODE)/%-clang.asm: .UNSANDBOXED = 1 o/$(MODE)/%-clang.asm: private .UNSANDBOXED = 1
o/$(MODE)/%-clang.asm: %.cc o/$(MODE)/%-clang.asm: %.cc
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.cxx) -S -g0 $(OUTPUT_OPTION) $< @$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.cxx) -S -g0 $(OUTPUT_OPTION) $<

View file

@ -81,6 +81,7 @@ EXAMPLES_DIRECTDEPS = \
THIRD_PARTY_MBEDTLS \ THIRD_PARTY_MBEDTLS \
THIRD_PARTY_MUSL \ THIRD_PARTY_MUSL \
THIRD_PARTY_NSYNC \ THIRD_PARTY_NSYNC \
THIRD_PARTY_NSYNC_MEM \
THIRD_PARTY_QUICKJS \ THIRD_PARTY_QUICKJS \
THIRD_PARTY_STB \ THIRD_PARTY_STB \
THIRD_PARTY_XED \ THIRD_PARTY_XED \

11
libc/isystem/nsync.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_H_
#include "third_party/nsync/counter.h"
#include "third_party/nsync/cv.h"
#include "third_party/nsync/debug.h"
#include "third_party/nsync/mu.h"
#include "third_party/nsync/mu_wait.h"
#include "third_party/nsync/note.h"
#include "third_party/nsync/once.h"
#include "third_party/nsync/waiter.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_ATOMIC_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_ATOMIC_H_
#include "third_party/nsync/atomic.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_ATOMIC_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_COUNTER_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_COUNTER_H_
#include "third_party/nsync/counter.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_COUNTER_H_ */

4
libc/isystem/nsync_cv.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_CV_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_CV_H_
#include "third_party/nsync/cv.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_CV_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_DEBUG_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_DEBUG_H_
#include "third_party/nsync/debug.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_DEBUG_H_ */

4
libc/isystem/nsync_mu.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_MU_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_MU_H_
#include "third_party/nsync/mu.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_MU_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_MU_WAIT_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_MU_WAIT_H_
#include "third_party/nsync/mu_wait.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_MU_WAIT_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_NOTE_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_NOTE_H_
#include "third_party/nsync/note.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_NOTE_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_ONCE_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_ONCE_H_
#include "third_party/nsync/once.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_ONCE_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_TIME_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_TIME_H_
#include "third_party/nsync/time.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_TIME_H_ */

View file

@ -0,0 +1,4 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_WAITER_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_WAITER_H_
#include "third_party/nsync/waiter.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_NSYNC_WAITER_H_ */

View file

@ -34,7 +34,8 @@ LIBC_THREAD_A_DIRECTDEPS = \
LIBC_SYSV \ LIBC_SYSV \
LIBC_SYSV_CALLS \ LIBC_SYSV_CALLS \
LIBC_NEXGEN32E \ LIBC_NEXGEN32E \
THIRD_PARTY_NSYNC THIRD_PARTY_NSYNC \
THIRD_PARTY_NSYNC_MEM
LIBC_THREAD_A_DEPS := \ LIBC_THREAD_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_THREAD_A_DIRECTDEPS),$($(x)))) $(call uniq,$(foreach x,$(LIBC_THREAD_A_DIRECTDEPS),$($(x))))

View file

@ -1,7 +1,7 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ #-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ #───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
o/$(MODE)/test/libc/release/cosmopolitan.zip: .UNSANDBOXED = 1 o/$(MODE)/test/libc/release/cosmopolitan.zip: private .UNSANDBOXED = 1
o/$(MODE)/test/libc/release/cosmopolitan.zip: \ o/$(MODE)/test/libc/release/cosmopolitan.zip: \
o/cosmopolitan.h \ o/cosmopolitan.h \
o/$(MODE)/ape/public/ape.lds \ o/$(MODE)/ape/public/ape.lds \

View file

@ -35,7 +35,8 @@ TEST_LIBC_THREAD_DIRECTDEPS = \
LIBC_THREAD \ LIBC_THREAD \
LIBC_TIME \ LIBC_TIME \
LIBC_TESTLIB \ LIBC_TESTLIB \
THIRD_PARTY_NSYNC THIRD_PARTY_NSYNC \
THIRD_PARTY_NSYNC_MEM
TEST_LIBC_THREAD_DEPS := \ TEST_LIBC_THREAD_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_THREAD_DIRECTDEPS),$($(x)))) $(call uniq,$(foreach x,$(TEST_LIBC_THREAD_DIRECTDEPS),$($(x))))

View file

@ -1,7 +1,12 @@
# *NSYNC # *NSYNC
The `THIRD_PARTY_NSYNC` and `LIBC_THREAD` packages include source code *NSYNC is a library providing scalable synchronization primitives. The
from *NSYNC. Here's the latest upstream synchronization point: following packages are provided:
- `THIRD_PARTY_NSYNC` has `nsync_mu` which doesn't depend on malloc().
- `THIRD_PARTY_NSYNC_MEM` has the rest of *NSYNC, e.g. `nsync_cv`.
The origin of this code is here:
git@github.com:google/nsync git@github.com:google/nsync
ac5489682760393fe21bd2a8e038b528442412a7 (1.25.0) ac5489682760393fe21bd2a8e038b528442412a7 (1.25.0)

43
third_party/nsync/compat.S vendored Normal file
View file

@ -0,0 +1,43 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
nsync_time_now:
jmp _timespec_real
.endfn nsync_time_now,globl
nsync_time_add:
jmp _timespec_add
.endfn nsync_time_add,globl
nsync_time_sub:
jmp _timespec_sub
.endfn nsync_time_sub,globl
nsync_time_cmp:
jmp _timespec_cmp
.endfn nsync_time_cmp,globl
nsync_time_ms:
jmp _timespec_frommillis
.endfn nsync_time_ms,globl
nsync_time_us:
jmp _timespec_frommicros
.endfn nsync_time_us,globl

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/intrin/strace.internal.h"
#include "libc/calls/struct/timespec.internal.h" #include "libc/calls/struct/timespec.internal.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/futex.h" #include "libc/sysv/consts/futex.h"
#include "libc/thread/thread.h" #include "libc/thread/thread.h"
#include "third_party/nsync/common.internal.h" #include "third_party/nsync/common.internal.h"
@ -34,30 +34,15 @@
int _futex (int *, int, int, const struct timespec *, int *, int); int _futex (int *, int, int, const struct timespec *, int *, int);
static int FUTEX_WAIT_; static int FUTEX_WAIT_;
static int FUTEX_WAKE_;
static int FUTEX_PRIVATE_FLAG_; static int FUTEX_PRIVATE_FLAG_;
static bool FUTEX_IS_SUPPORTED; static bool FUTEX_IS_SUPPORTED;
bool FUTEX_TIMEOUT_IS_ABSOLUTE; bool FUTEX_TIMEOUT_IS_ABSOLUTE;
__attribute__((__constructor__)) static void sync_futex_init_ (void) { __attribute__((__constructor__)) static void nsync_futex_init_ (void) {
int x = 0; int x = 0;
FUTEX_WAKE_ = FUTEX_WAKE; if (!(FUTEX_IS_SUPPORTED = IsLinux() || IsOpenbsd()))
return;
if (IsLinux () &&
_futex (&x, FUTEX_WAIT_BITSET, 1, 0, 0,
FUTEX_BITSET_MATCH_ANY) == -EAGAIN) {
FUTEX_WAIT_ = FUTEX_WAIT_BITSET;
FUTEX_TIMEOUT_IS_ABSOLUTE = true;
} else {
FUTEX_WAIT_ = FUTEX_WAIT;
}
if (IsOpenbsd () ||
(IsLinux () &&
!_futex (&x, FUTEX_WAKE_PRIVATE, 1, 0, 0, 0))) {
FUTEX_PRIVATE_FLAG_ = FUTEX_PRIVATE_FLAG;
}
// In our testing, we found that the monotonic clock on various // In our testing, we found that the monotonic clock on various
// popular systems (such as Linux, and some BSD variants) was no // popular systems (such as Linux, and some BSD variants) was no
@ -72,10 +57,23 @@ __attribute__((__constructor__)) static void sync_futex_init_ (void) {
if (IsLinux () && if (IsLinux () &&
_futex (&x, FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME, _futex (&x, FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME,
1, 0, 0, FUTEX_BITSET_MATCH_ANY) == -EAGAIN) { 1, 0, 0, FUTEX_BITSET_MATCH_ANY) == -EAGAIN) {
FUTEX_WAIT_ |= FUTEX_CLOCK_REALTIME; FUTEX_WAIT_ = FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME;
FUTEX_PRIVATE_FLAG_ = FUTEX_PRIVATE_FLAG;
FUTEX_TIMEOUT_IS_ABSOLUTE = true;
} else if (IsLinux () &&
_futex (&x, FUTEX_WAIT_BITSET, 1, 0, 0,
FUTEX_BITSET_MATCH_ANY) == -EAGAIN) {
FUTEX_WAIT_ = FUTEX_WAIT_BITSET;
FUTEX_PRIVATE_FLAG_ = FUTEX_PRIVATE_FLAG;
FUTEX_TIMEOUT_IS_ABSOLUTE = true;
} else if (IsOpenbsd () ||
(IsLinux () &&
!_futex (&x, FUTEX_WAKE_PRIVATE, 1, 0, 0, 0))) {
FUTEX_WAIT_ = FUTEX_WAIT;
FUTEX_PRIVATE_FLAG_ = FUTEX_PRIVATE_FLAG;
} else {
FUTEX_WAIT_ = FUTEX_WAIT;
} }
FUTEX_IS_SUPPORTED = IsLinux() || IsOpenbsd();
} }
int nsync_futex_wait_ (int *p, int expect, char pshare, struct timespec *timeout) { int nsync_futex_wait_ (int *p, int expect, char pshare, struct timespec *timeout) {
@ -108,7 +106,7 @@ int nsync_futex_wake_ (int *p, int count, char pshare) {
int rc, op; int rc, op;
int wake (void *, int, int) asm ("_futex"); int wake (void *, int, int) asm ("_futex");
if (FUTEX_IS_SUPPORTED) { if (FUTEX_IS_SUPPORTED) {
op = FUTEX_WAKE_; op = FUTEX_WAKE;
if (pshare == PTHREAD_PROCESS_PRIVATE) { if (pshare == PTHREAD_PROCESS_PRIVATE) {
op |= FUTEX_PRIVATE_FLAG_; op |= FUTEX_PRIVATE_FLAG_;
} }

55
third_party/nsync/mem/mem.mk vendored Normal file
View file

@ -0,0 +1,55 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += THIRD_PARTY_NSYNC_MEM
THIRD_PARTY_NSYNC_MEM_SRCS = $(THIRD_PARTY_NSYNC_MEM_A_SRCS)
THIRD_PARTY_NSYNC_MEM_HDRS = $(THIRD_PARTY_NSYNC_MEM_A_HDRS)
THIRD_PARTY_NSYNC_MEM_ARTIFACTS += THIRD_PARTY_NSYNC_MEM_A
THIRD_PARTY_NSYNC_MEM = $(THIRD_PARTY_NSYNC_MEM_A_DEPS) $(THIRD_PARTY_NSYNC_MEM_A)
THIRD_PARTY_NSYNC_MEM_A = o/$(MODE)/third_party/nsync/mem/nsync.a
THIRD_PARTY_NSYNC_MEM_A_FILES := $(wildcard third_party/nsync/mem/*)
THIRD_PARTY_NSYNC_MEM_A_HDRS = $(filter %.h,$(THIRD_PARTY_NSYNC_MEM_A_FILES))
THIRD_PARTY_NSYNC_MEM_A_SRCS = $(filter %.c,$(THIRD_PARTY_NSYNC_MEM_A_FILES))
THIRD_PARTY_NSYNC_MEM_A_OBJS = $(THIRD_PARTY_NSYNC_MEM_A_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_NSYNC_MEM_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_MEM \
LIBC_STUBS \
LIBC_SYSV \
THIRD_PARTY_NSYNC
THIRD_PARTY_NSYNC_MEM_A_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_NSYNC_MEM_A_DIRECTDEPS),$($(x))))
THIRD_PARTY_NSYNC_MEM_A_CHECKS = \
$(THIRD_PARTY_NSYNC_MEM_A).pkg \
$(THIRD_PARTY_NSYNC_MEM_A_HDRS:%=o/$(MODE)/%.ok)
$(THIRD_PARTY_NSYNC_MEM_A): \
third_party/nsync/mem/ \
$(THIRD_PARTY_NSYNC_MEM_A).pkg \
$(THIRD_PARTY_NSYNC_MEM_A_OBJS)
$(THIRD_PARTY_NSYNC_MEM_A).pkg: \
$(THIRD_PARTY_NSYNC_MEM_A_OBJS) \
$(foreach x,$(THIRD_PARTY_NSYNC_MEM_A_DIRECTDEPS),$($(x)_A).pkg)
$(THIRD_PARTY_NSYNC_MEM_A_OBJS): private \
OVERRIDE_CCFLAGS += \
-ffunction-sections \
-fdata-sections
THIRD_PARTY_NSYNC_MEM_LIBS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)))
THIRD_PARTY_NSYNC_MEM_SRCS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)_SRCS))
THIRD_PARTY_NSYNC_MEM_CHECKS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)_CHECKS))
THIRD_PARTY_NSYNC_MEM_OBJS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)_OBJS))
$(THIRD_PARTY_NSYNC_MEM_OBJS): third_party/nsync/mem/nsync.mk
.PHONY: o/$(MODE)/third_party/nsync/mem
o/$(MODE)/third_party/nsync/mem: $(THIRD_PARTY_NSYNC_MEM_CHECKS)

0
third_party/nsync/mem/nsync.mk vendored Executable file
View file

View file

@ -11,10 +11,16 @@ THIRD_PARTY_NSYNC = $(THIRD_PARTY_NSYNC_A_DEPS) $(THIRD_PARTY_NSYNC_A)
THIRD_PARTY_NSYNC_A = o/$(MODE)/third_party/nsync/nsync.a THIRD_PARTY_NSYNC_A = o/$(MODE)/third_party/nsync/nsync.a
THIRD_PARTY_NSYNC_A_FILES := $(wildcard third_party/nsync/*) THIRD_PARTY_NSYNC_A_FILES := $(wildcard third_party/nsync/*)
THIRD_PARTY_NSYNC_A_HDRS = $(filter %.h,$(THIRD_PARTY_NSYNC_A_FILES)) THIRD_PARTY_NSYNC_A_HDRS = $(filter %.h,$(THIRD_PARTY_NSYNC_A_FILES))
THIRD_PARTY_NSYNC_A_SRCS = $(filter %.c,$(THIRD_PARTY_NSYNC_A_FILES)) THIRD_PARTY_NSYNC_A_SRCS_C = $(filter %.c,$(THIRD_PARTY_NSYNC_A_FILES))
THIRD_PARTY_NSYNC_A_SRCS_S = $(filter %.S,$(THIRD_PARTY_NSYNC_A_FILES))
THIRD_PARTY_NSYNC_A_SRCS = \
$(THIRD_PARTY_NSYNC_A_SRCS_S) \
$(THIRD_PARTY_NSYNC_A_SRCS_C)
THIRD_PARTY_NSYNC_A_OBJS = \ THIRD_PARTY_NSYNC_A_OBJS = \
$(THIRD_PARTY_NSYNC_A_SRCS:%.c=o/$(MODE)/%.o) $(THIRD_PARTY_NSYNC_A_SRCS_C:%.c=o/$(MODE)/%.o) \
$(THIRD_PARTY_NSYNC_A_SRCS_S:%.S=o/$(MODE)/%.o)
THIRD_PARTY_NSYNC_A_DIRECTDEPS = \ THIRD_PARTY_NSYNC_A_DIRECTDEPS = \
LIBC_CALLS \ LIBC_CALLS \
@ -54,4 +60,6 @@ THIRD_PARTY_NSYNC_OBJS = $(foreach x,$(THIRD_PARTY_NSYNC_ARTIFACTS),$($(x)_OBJS)
$(THIRD_PARTY_NSYNC_OBJS): third_party/nsync/nsync.mk $(THIRD_PARTY_NSYNC_OBJS): third_party/nsync/nsync.mk
.PHONY: o/$(MODE)/third_party/nsync .PHONY: o/$(MODE)/third_party/nsync
o/$(MODE)/third_party/nsync: $(THIRD_PARTY_NSYNC_CHECKS) o/$(MODE)/third_party/nsync: \
o/$(MODE)/third_party/nsync/mem \
$(THIRD_PARTY_NSYNC_CHECKS)