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

@ -22,12 +22,12 @@
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/thread/spawn.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#define _TLSZ ((intptr_t)_tls_size)
#define _TLDZ ((intptr_t)_tdata_size)
#define _TIBZ sizeof(struct cthread_descriptor_t)
#define _MEMZ ROUNDUP(_TLSZ + _TIBZ, _Alignof(struct cthread_descriptor_t))
#define _TIBZ sizeof(struct CosmoTib)
#define _MEMZ ROUNDUP(_TLSZ + _TIBZ, _Alignof(struct CosmoTib))
/**
* Allocates thread-local storage memory for new thread.
@ -35,18 +35,18 @@
*/
char *_mktls(char **out_tib) {
char *tls;
cthread_t tib;
struct CosmoTib *tib;
// Allocate enough TLS memory for all the GNU Linuker (_tls_size)
// organized _Thread_local data, as well as Cosmpolitan Libc (64)
if (!(tls = calloc(1, _MEMZ))) return 0;
// set up thread information block
tib = (cthread_t)(tls + _MEMZ - _TIBZ);
tib->self = tib;
tib->self2 = tib;
tib->err = 0;
tib->tid = -1;
tib = (struct CosmoTib *)(tls + _MEMZ - _TIBZ);
tib->tib_self = tib;
tib->tib_self2 = tib;
tib->tib_errno = 0;
tib->tib_tid = -1;
memmove(tls, _tdata_start, _TLDZ);
if (out_tib) {