LibC: Make _get_uthread a macro

This allows nice inlining :)
This commit is contained in:
Bananymous 2025-08-03 19:33:01 +03:00
parent 4e705a91af
commit 4a95343936
3 changed files with 14 additions and 13 deletions

View File

@ -1,8 +1,6 @@
#include <errno.h>
#include <pthread.h>
extern uthread* _get_uthread();
int* __errno_location()
{
return &_get_uthread()->errno_;

View File

@ -87,6 +87,20 @@ struct uthread
#define _PTHREAD_ATFORK_CHILD 2
void _pthread_call_atfork(int state);
#if defined(__x86_64__)
#define _get_uthread() ({ \
struct uthread* __tmp; \
asm volatile("movq %%fs:0, %0" : "=r"(__tmp)); \
__tmp; \
})
#elif defined(__i686__)
#define _get_uthread() ({ \
struct uthread* __tmp; \
asm volatile("movl %%gs:0, %0" : "=r"(__tmp)); \
__tmp; \
})
#endif
int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void));
int pthread_attr_destroy(pthread_attr_t* attr);
int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* detachstate);

View File

@ -54,17 +54,6 @@ extern "C" void _pthread_trampoline_cpp(void* arg)
ASSERT_NOT_REACHED();
}
uthread* _get_uthread()
{
uthread* result;
#if ARCH(x86_64)
asm volatile("movq %%fs:0, %0" : "=r"(result));
#elif ARCH(i686)
asm volatile("movl %%gs:0, %0" : "=r"(result));
#endif
return result;
}
static void free_uthread(uthread* uthread)
{
if (uthread->dtv[0] == 0)