mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
parent
13d67fed38
commit
b4e38851ff
2 changed files with 16 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
#ifndef LIBC_ISYSTEM_PTHREAD_H_
|
#ifndef LIBC_ISYSTEM_PTHREAD_H_
|
||||||
#define LIBC_ISYSTEM_PTHREAD_H_
|
#define LIBC_ISYSTEM_PTHREAD_H_
|
||||||
#include "libc/runtime/pthread.h"
|
#include "libc/intrin/pthread.h"
|
||||||
#endif /* LIBC_ISYSTEM_PTHREAD_H_ */
|
#endif /* LIBC_ISYSTEM_PTHREAD_H_ */
|
||||||
|
|
|
@ -56,7 +56,19 @@ STATIC_YOINK("_main_thread_ctor");
|
||||||
#define _MEMZ ROUNDUP(_TLSZ + _TIBZ, alignof(struct cthread_descriptor_t))
|
#define _MEMZ ROUNDUP(_TLSZ + _TIBZ, alignof(struct cthread_descriptor_t))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spawns thread.
|
* Spawns thread, e.g.
|
||||||
|
*
|
||||||
|
* int worker(void *arg, int tid) {
|
||||||
|
* const char *s = arg;
|
||||||
|
* printf("%s\n", s);
|
||||||
|
* return 0;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* int main() {
|
||||||
|
* struct spawn th;
|
||||||
|
* _spawn(worker, "hi", &th);
|
||||||
|
* _join(&th);
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* @param fun is thread worker callback, which receives `arg` and `ctid`
|
* @param fun is thread worker callback, which receives `arg` and `ctid`
|
||||||
* @param arg shall be passed to `fun`
|
* @param arg shall be passed to `fun`
|
||||||
|
@ -77,14 +89,14 @@ int _spawn(int fun(void *, int), void *arg, struct spawn *opt_out_thread) {
|
||||||
th = &ths;
|
th = &ths;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate enough TLS memory for all the GNU Linuker (_tls_size)
|
// allocate enough TLS memory for all the GNU Linuker (_tls_size)
|
||||||
// organized _Thread_local data, as well as Cosmpolitan Libc (64)
|
// organized _Thread_local data, as well as Cosmpolitan Libc (64)
|
||||||
if (!(th->tls = _mktls(&th->tib))) {
|
if (!(th->tls = _mktls(&th->tib))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
th->ctid = (int *)(th->tib + 0x38);
|
th->ctid = (int *)(th->tib + 0x38);
|
||||||
|
|
||||||
// We must use _mapstack() to allocate the stack because OpenBSD has
|
// we must use _mapstack() to allocate the stack because OpenBSD has
|
||||||
// very strict requirements for what's allowed to be used for stacks
|
// very strict requirements for what's allowed to be used for stacks
|
||||||
if (!(th->stk = _mapstack())) {
|
if (!(th->stk = _mapstack())) {
|
||||||
free(th->tls);
|
free(th->tls);
|
||||||
|
|
Loading…
Add table
Reference in a new issue