Reduce header complexity

- Remove most __ASSEMBLER__ __LINKER__ ifdefs
- Rename libc/intrin/bits.h to libc/serialize.h
- Block pthread cancelation in fchmodat() polyfill
- Remove `clang-format off` statements in third_party
This commit is contained in:
Justine Tunney 2023-11-28 14:24:28 -08:00
parent 96f979dfc5
commit fa20edc44d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3057 changed files with 410 additions and 4398 deletions

View file

@ -1,6 +1,5 @@
#ifndef NSYNC_ARRAY_H_
#define NSYNC_ARRAY_H_
/* clang-format off */
/* Return the number of elements in a C array a.
A constant expression if a is a constant expression. */

View file

@ -1,7 +1,6 @@
#ifndef NSYNC_ATOMIC_H_
#define NSYNC_ATOMIC_H_
#include "libc/atomic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define nsync_atomic_uint32_ atomic_uint
@ -12,5 +11,4 @@ COSMOPOLITAN_C_START_
#define NSYNC_ATOMIC_UINT32_PTR_(p) (p)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_ATOMIC_H_ */

View file

@ -3,7 +3,6 @@
#include "libc/intrin/atomic.h"
#include "libc/intrin/cmpxchg.h"
#include "third_party/nsync/atomic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* Atomic operations on nsync_atomic_uint32_ quantities
@ -118,5 +117,4 @@ static inline int atm_cas_seqcst_u32_(nsync_atomic_uint32_ *p, uint32_t o,
memory_order_release))
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_ATOMIC_INTERNAL_H_ */

View file

@ -39,7 +39,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* This package provides a mutex nsync_mu and a Mesa-style condition
* variable nsync_cv. */

View file

@ -10,7 +10,6 @@
#include "third_party/nsync/note.h"
#include "third_party/nsync/time.h"
#include "third_party/nsync/wait_s.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#ifdef MODE_DBG
@ -278,5 +277,4 @@ int nsync_sem_wait_with_cancel_(waiter *w, nsync_time abs_deadline,
nsync_note cancel_note);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_COMMON_H_ */

View file

@ -2,7 +2,6 @@
#define NSYNC_COUNTER_H_
#include "third_party/nsync/atomic.h"
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* An nsync_counter represents an unsigned integer that can count up and down,
@ -37,5 +36,4 @@ uint32_t nsync_counter_value(nsync_counter c);
uint32_t nsync_counter_wait(nsync_counter c, nsync_time abs_deadline);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_COUNTER_H_ */

View file

@ -3,7 +3,6 @@
#include "libc/intrin/dll.h"
#include "third_party/nsync/mu.h"
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define NSYNC_CV_INIT \
@ -157,5 +156,4 @@ int nsync_cv_wait_with_deadline_generic(nsync_cv *cv, void *mu,
struct nsync_note_s_ *cancel_note);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_CV_H_ */

View file

@ -2,7 +2,6 @@
#define NSYNC_DEBUG_H_
#include "third_party/nsync/cv.h"
#include "third_party/nsync/mu.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* Debugging operations for mutexes and condition variables.
@ -35,5 +34,4 @@ char *nsync_mu_debugger(nsync_mu *mu);
char *nsync_cv_debugger(nsync_cv *cv);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_DEBUG_H_ */

View file

@ -53,7 +53,6 @@
#include "third_party/nsync/common.internal.h"
#include "third_party/nsync/futex.internal.h"
#include "third_party/nsync/time.h"
// clang-format off
#define FUTEX_WAIT_BITS_ FUTEX_BITSET_MATCH_ANY

View file

@ -2,12 +2,10 @@
#define NSYNC_FUTEX_INTERNAL_H_
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int nsync_futex_wake_(_Atomic(int) *, int, char);
int nsync_futex_wait_(_Atomic(int) *, int, char, const struct timespec *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_FUTEX_INTERNAL_H_ */

View file

@ -1,6 +1,5 @@
#ifndef NSYNC_TESTING_HEAP_H_
#define NSYNC_TESTING_HEAP_H_
/* clang-format off */
/* A heap.
Optionally, elements may have storage for the index to allow deletions from

View file

@ -18,7 +18,6 @@
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "third_party/nsync/array.internal.h"
// clang-format off
void a_ensure_ (void *v, int delta, int sz) {
typedef A_TYPE (void *) a_void_ptr;

View file

@ -31,7 +31,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Internal details of nsync_counter. */
struct nsync_counter_s_ {

View file

@ -35,7 +35,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Initialize *cv. */
void nsync_cv_init (nsync_cv *cv) {

View file

@ -26,7 +26,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Routines for debugging. */

View file

@ -27,7 +27,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Attempt to remove waiter *w from *mu's
waiter queue. If successful, leave the lock held in mode *l_type, and

View file

@ -30,7 +30,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Locking discipline for the nsync_note implementation:

View file

@ -27,7 +27,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* An once_sync_s struct contains a lock, and a condition variable on which
threads may wait for an nsync_once to be initialized by another thread.

View file

@ -28,7 +28,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Wait until one of:
w->sem is non-zero----decrement it and return 0.

View file

@ -30,7 +30,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
int nsync_wait_n (void *mu, void (*lock) (void *), void (*unlock) (void *),
nsync_time abs_deadline,

View file

@ -28,7 +28,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Initialize *mu. */
void nsync_mu_init (nsync_mu *mu) {

View file

@ -2,7 +2,6 @@
#define NSYNC_MU_H_
#include "libc/intrin/dll.h"
#include "third_party/nsync/atomic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked.
@ -99,5 +98,4 @@ void nsync_mu_rassert_held(const nsync_mu *mu);
int nsync_mu_is_reader(const nsync_mu *mu);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_MU_H_ */

View file

@ -29,7 +29,6 @@ asm(".ident\t\"\\n\\n\
*NSYNC (Apache 2.0)\\n\
Copyright 2016 Google, Inc.\\n\
https://github.com/google/nsync\"");
// clang-format off
/* Initialize *s; the initial value is 0. */
void nsync_mu_semaphore_init (nsync_semaphore *s) {

View file

@ -1,7 +1,6 @@
#ifndef NSYNC_SEM_H_
#define NSYNC_SEM_H_
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
typedef struct nsync_semaphore_s_ {
@ -24,5 +23,4 @@ errno_t nsync_mu_semaphore_p_with_deadline(nsync_semaphore *s,
void nsync_mu_semaphore_v(nsync_semaphore *s);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_SEM_H_ */

View file

@ -2,7 +2,6 @@
#define COSMOPOLITAN_THIRD_PARTY_NSYNC_MU_SEMAPHORE_INTERNAL_H_
#include "third_party/nsync/mu_semaphore.h"
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void nsync_mu_semaphore_init_futex(nsync_semaphore *);
@ -21,5 +20,4 @@ errno_t nsync_mu_semaphore_p_with_deadline_gcd(nsync_semaphore *, nsync_time);
void nsync_mu_semaphore_v_gcd(nsync_semaphore *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_NSYNC_MU_SEMAPHORE_INTERNAL_H_ */

View file

@ -23,7 +23,6 @@
#include "third_party/nsync/atomic.internal.h"
#include "third_party/nsync/futex.internal.h"
#include "third_party/nsync/mu_semaphore.internal.h"
// clang-format off
/**
* @fileoverview Semaphores w/ Linux Futexes API.

View file

@ -31,7 +31,6 @@
#include "third_party/nsync/futex.internal.h"
#include "third_party/nsync/mu_semaphore.internal.h"
#include "third_party/nsync/time.h"
// clang-format off
/**
* @fileoverview Semaphores w/ Apple's Grand Central Dispatch API.

View file

@ -32,7 +32,6 @@
#include "libc/thread/thread.h"
#include "third_party/nsync/mu_semaphore.h"
#include "third_party/nsync/time.h"
// clang-format off
/**
* @fileoverview Semaphores w/ POSIX Semaphores API.

View file

@ -2,7 +2,6 @@
#define NSYNC_MU_WAIT_H_
#include "third_party/nsync/mu.h"
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
@ -114,5 +113,4 @@ int nsync_mu_wait_with_deadline(
void nsync_mu_unlock_without_wakeup(nsync_mu *mu);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_MU_WAIT_H_ */

View file

@ -1,7 +1,6 @@
#ifndef NSYNC_NOTE_H_
#define NSYNC_NOTE_H_
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* An nsync_note represents a single bit that can transition from 0 to 1
@ -47,5 +46,4 @@ int nsync_note_wait(nsync_note n, nsync_time abs_deadline);
nsync_time nsync_note_expiry(nsync_note n);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_NOTE_H_ */

View file

@ -1,7 +1,6 @@
#ifndef NSYNC_ONCE_H_
#define NSYNC_ONCE_H_
#include "third_party/nsync/atomic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* An nsync_once allows a function to be called exactly once, when first
@ -33,5 +32,4 @@ void nsync_run_once_arg_spin(nsync_once *once, void (*farg)(void *arg),
void *arg);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_ONCE_H_ */

View file

@ -21,7 +21,6 @@
#include "libc/intrin/describebacktrace.internal.h"
#include "libc/runtime/runtime.h"
#include "third_party/nsync/common.internal.h"
// clang-format off
/* Aborts after printing the nul-terminated string s[]. */
void nsync_panic_ (const char *s) {

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_NSYNC_RACES_INTERNAL_H_
#define COSMOPOLITAN_THIRD_PARTY_NSYNC_RACES_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* Annotations for race detectors. */
@ -32,5 +31,4 @@ NSYNC_C_END_
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_NSYNC_RACES_INTERNAL_H_ */

View file

@ -18,7 +18,6 @@
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/thread.h"
// clang-format off
#ifndef NSYNC_ATM_LOG
#define NSYNC_ATM_LOG 0

View file

@ -16,7 +16,6 @@
limitations under the License.
*/
#include "third_party/nsync/testing/closure.h"
// clang-format off
void nsync_start_thread_ (void (*f) (void *), void *arg);

View file

@ -1,6 +1,5 @@
#ifndef NSYNC_TESTING_CLOSURE_H_
#define NSYNC_TESTING_CLOSURE_H_
/* clang-format off */
#include "libc/mem/mem.h"
/* A run-once, self-freeing closure. */

View file

@ -20,7 +20,6 @@
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
// clang-format off
/* Verify the properties of a zero counter. */
static void test_counter_zero (testing t) {

View file

@ -23,7 +23,6 @@
#include "third_party/nsync/testing/closure.h"
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
// clang-format off
/* A cv_stress_data represents the data used by the threads of the tests below. */
typedef struct cv_stress_data_s {

View file

@ -30,7 +30,6 @@
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
#include "third_party/nsync/time.h"
// clang-format off
/* --------------------------- */

View file

@ -25,7 +25,6 @@
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
// clang-format off
/* Example use of CV.wait(): A priority queue of strings whose
"remove_with_deadline" operation has a deadline. */

View file

@ -22,7 +22,6 @@
#include "third_party/nsync/array.internal.h"
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
// clang-format off
/* This tests internal abstractions. */

View file

@ -25,7 +25,6 @@
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
#include "third_party/nsync/time.h"
// clang-format off
/* Test the behaviour of mu in situations where starvation might be expected. */

View file

@ -25,7 +25,6 @@
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
// clang-format off
/* The state shared between the threads in each of the tests below. */
typedef struct test_data_s {

View file

@ -25,7 +25,6 @@
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
// clang-format off
/* Example use of nsync_mu_wait(): A priority queue of strings whose
"remove_with_deadline" operation has a deadline. */

View file

@ -25,7 +25,6 @@
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
#include "third_party/nsync/time.h"
// clang-format off
/* --------------------------- */

View file

@ -21,7 +21,6 @@
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/testing/time_extra.h"
#include "third_party/nsync/time.h"
// clang-format off
/* Verify the properties of a prenotified note. */
static void test_note_prenotified (testing t) {

View file

@ -23,7 +23,6 @@
#include "third_party/nsync/testing/closure.h"
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
// clang-format off
/* This tests nsync_once */

View file

@ -27,7 +27,6 @@
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/testing.h"
#include "third_party/nsync/waiter.h"
// clang-format off
/* The benchmarks in this file use various mechanisms to
ping-pong back and forth between two threads as they count i from

View file

@ -19,7 +19,6 @@
#include "libc/mem/mem.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
// clang-format off
char *smprintf (const char *fmt, ...) {
int m = strlen (fmt) * 2 + 1;

View file

@ -17,7 +17,6 @@
*/
#include "libc/mem/mem.h"
#include "libc/thread/thread.h"
// clang-format off
struct thd_args {
void (*f) (void *);

View file

@ -33,7 +33,6 @@
#include "third_party/nsync/testing/closure.h"
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/time_extra.h"
// clang-format off
struct testing_base_s {
int flags; /* flags from testing_new(); r/o after init */

View file

@ -1,6 +1,5 @@
#ifndef NSYNC_TESTING_TESTING_H_
#define NSYNC_TESTING_TESTING_H_
/* clang-format off */
typedef struct testing_base_s *testing_base;
typedef const struct testing_base_s *const_testing_base;

View file

@ -20,7 +20,6 @@
#include "third_party/nsync/testing/smprintf.h"
#include "third_party/nsync/testing/time_extra.h"
#include "third_party/nsync/time.h"
// clang-format off
char *nsync_time_str (nsync_time t, int decimals) {
static const struct {

View file

@ -25,7 +25,6 @@
#include "third_party/nsync/testing/time_extra.h"
#include "third_party/nsync/time.h"
#include "third_party/nsync/waiter.h"
// clang-format off
static void decrement_at (nsync_counter c, nsync_time abs_deadline, nsync_counter done) {
nsync_time_sleep_until (abs_deadline);

View file

@ -1,7 +1,6 @@
#ifndef NSYNC_TIME_H_
#define NSYNC_TIME_H_
#include "libc/calls/struct/timespec.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define NSYNC_TIME_SEC(t) ((t).tv_sec)
@ -56,5 +55,4 @@ typedef struct timespec nsync_time;
#define nsync_time_s_ns(s, ns) ((nsync_time){(int64_t)(s), (unsigned)(ns)})
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_TIME_H_ */

View file

@ -2,7 +2,6 @@
#define COSMOPOLITAN_LIBC_THREAD_WAIT_INTERNAL_H_
#include "libc/intrin/dll.h"
#include "third_party/nsync/atomic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* Implementations of "struct nsync_waitable_s" must provide functions
@ -24,5 +23,4 @@ struct nsync_waiter_s {
void nsync_waiter_destroy(void *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_THREAD_WAIT_INTERNAL_H_ */

View file

@ -1,7 +1,6 @@
#ifndef NSYNC_WAITER_H_
#define NSYNC_WAITER_H_
#include "third_party/nsync/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* nsync_wait_n() allows the client to wait on multiple objects
@ -134,5 +133,4 @@ extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* NSYNC_WAITER_H_ */

View file

@ -20,7 +20,6 @@
#include "libc/intrin/strace.internal.h"
#include "libc/thread/thread.h"
#include "third_party/nsync/common.internal.h"
// clang-format off
void nsync_yield_ (void) {
pthread_yield ();