2021-10-13 18:26:05 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_THREAD_SELF_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_THREAD_SELF_H_
|
|
|
|
#include "libc/thread/descriptor.h"
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileoverview get the thread descriptor of the current thread
|
|
|
|
*/
|
|
|
|
|
2021-10-14 00:27:13 +00:00
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
2021-10-13 18:26:05 +00:00
|
|
|
inline cthread_t cthread_self(void) {
|
|
|
|
cthread_t self;
|
2021-10-14 00:27:13 +00:00
|
|
|
asm("mov\t%%fs:0,%0" : "=r"(self));
|
2021-10-13 18:26:05 +00:00
|
|
|
return self;
|
|
|
|
}
|
2021-10-14 00:27:13 +00:00
|
|
|
#else
|
|
|
|
cthread_t cthread_self(void);
|
|
|
|
#endif
|
2021-10-13 18:26:05 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
2021-10-14 00:27:13 +00:00
|
|
|
#endif /* COSMOPOLITAN_LIBC_THREAD_SELF_H_ */
|