Tidy up the threading implementation

The organization of the source files is now much more rational.
Old experiments that didn't work out are now deleted. Naming of
things like files is now more intuitive.
This commit is contained in:
Justine Tunney 2022-09-10 02:56:25 -07:00
parent e9272f03fb
commit 155b378a39
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
199 changed files with 526 additions and 685 deletions

View file

@ -20,12 +20,10 @@
#include "libc/intrin/likely.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/gc.internal.h"
#include "libc/nexgen32e/gettls.h"
#include "libc/nexgen32e/stackframe.h"
#include "libc/nexgen32e/threaded.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
static inline bool PointerNotOwnedByParentStackFrame(struct StackFrame *frame,
struct StackFrame *parent,
@ -36,11 +34,11 @@ static inline bool PointerNotOwnedByParentStackFrame(struct StackFrame *frame,
static void TeardownGc(void) {
int i;
cthread_t tls;
struct Garbages *g;
struct CosmoTib *t;
if (__tls_enabled) {
tls = (cthread_t)__get_tls();
if ((g = tls->garbages)) {
t = __get_tls();
if ((g = t->tib_garbages)) {
// exit() currently doesn't use _gclongjmp() like pthread_exit()
// so we need to run the deferred functions manually.
while (g->i) {
@ -61,18 +59,18 @@ __attribute__((__constructor__)) static void InitializeGc(void) {
// then rewrite caller's return address on stack.
static void DeferFunction(struct StackFrame *frame, void *fn, void *arg) {
int n2;
cthread_t tls;
struct Garbage *p2;
struct Garbages *g;
TlsIsRequired();
tls = (cthread_t)__get_tls();
g = tls->garbages;
struct CosmoTib *t;
__require_tls();
t = __get_tls();
g = t->tib_garbages;
if (UNLIKELY(!g)) {
if (!(g = malloc(sizeof(struct Garbages)))) notpossible;
g->i = 0;
g->n = 4;
if (!(g->p = malloc(g->n * sizeof(struct Garbage)))) notpossible;
tls->garbages = g;
t->tib_garbages = g;
} else if (UNLIKELY(g->i == g->n)) {
p2 = g->p;
n2 = g->n + (g->n >> 1);