mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 19:28:29 +00:00
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:
parent
e9272f03fb
commit
155b378a39
199 changed files with 526 additions and 685 deletions
|
@ -34,7 +34,7 @@
|
|||
// @see test/libc/runtime/gc_test.c
|
||||
// @threadsafe
|
||||
__gc: mov %fs:0,%rcx # __get_tls()
|
||||
mov 0x18(%rcx),%rcx # cthread_t::garbages
|
||||
mov 0x18(%rcx),%rcx # tls::garbages
|
||||
decl (%rcx) # ++g->i
|
||||
mov (%rcx),%r8d # r8 = g->i
|
||||
mov 8(%rcx),%r9 # r9 = g->p
|
||||
|
|
|
@ -35,7 +35,7 @@ _gclongjmp:
|
|||
mov %rsp,%rbp
|
||||
.profilable
|
||||
mov %fs:0,%r12 # __get_tls()
|
||||
mov 0x18(%r12),%r12 # cthread_t::garbages
|
||||
mov 0x18(%r12),%r12 # Tls::garbages
|
||||
test %r12,%r12
|
||||
jz 0f
|
||||
movl (%r12),%r13d # garbages.i
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_GETTLS_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_GETTLS_H_
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
/**
|
||||
* Returns location of thread information block.
|
||||
*
|
||||
* This can't be used in privileged functions.
|
||||
*/
|
||||
static noasan inline char *__get_tls(void) {
|
||||
char *tib;
|
||||
asm("mov\t%%fs:0,%0" : "=r"(tib) : /* no inputs */ : "memory");
|
||||
return tib;
|
||||
}
|
||||
#endif /* GNU x86-64 */
|
||||
|
||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
/**
|
||||
* Returns location of thread information block.
|
||||
*
|
||||
* This should be favored over __get_tls() for .privileged code that
|
||||
* can't be self-modified by __enable_tls().
|
||||
*/
|
||||
static noasan inline char *__get_tls_privileged(void) {
|
||||
char *tib, *lin = (char *)0x30;
|
||||
if (IsLinux() || IsFreebsd() || IsNetbsd() || IsOpenbsd() || IsMetal()) {
|
||||
asm("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
} else {
|
||||
asm("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
if (IsWindows()) {
|
||||
tib = *(char **)(tib + 0x1480 + __tls_index * 8);
|
||||
}
|
||||
}
|
||||
return tib;
|
||||
}
|
||||
#endif /* GNU x86-64 */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_GETTLS_H_ */
|
|
@ -16,7 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
/**
|
||||
* Contains TID of main thread or 0 if threading isn't enabled.
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_THREADED_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_THREADED_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern int __threaded;
|
||||
extern bool __tls_enabled;
|
||||
extern unsigned __tls_index;
|
||||
|
||||
void TlsIsRequired(void);
|
||||
void *__initialize_tls(char[64]);
|
||||
void __install_tls(char[64]);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_THREADED_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue