MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / get_thread_id

Function get_thread_id

source/extern/rpmalloc.c:788–818  ·  view source on GitHub ↗

Fast thread ID

Source from the content-addressed store, hash-verified

786
787//! Fast thread ID
788static inline uintptr_t
789get_thread_id(void) {
790#if defined(_WIN32)
791 return (uintptr_t)((void*)NtCurrentTeb());
792#elif (defined(__GNUC__) || defined(__clang__)) && !defined(__CYGWIN__)
793 uintptr_t tid;
794# if defined(__i386__)
795 __asm__("movl %%gs:0, %0" : "=r" (tid) : : );
796# elif defined(__x86_64__)
797# if defined(__MACH__)
798 __asm__("movq %%gs:0, %0" : "=r" (tid) : : );
799# else
800 __asm__("movq %%fs:0, %0" : "=r" (tid) : : );
801# endif
802# elif defined(__arm__)
803 __asm__ volatile ("mrc p15, 0, %0, c13, c0, 3" : "=r" (tid));
804# elif defined(__aarch64__)
805# if defined(__MACH__)
806 // tpidr_el0 likely unused, always return 0 on iOS
807 __asm__ volatile ("mrs %0, tpidrro_el0" : "=r" (tid));
808# else
809 __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tid));
810# endif
811# else
812# error This platform needs implementation of get_thread_id()
813# endif
814 return tid;
815#else
816# error This platform needs implementation of get_thread_id()
817#endif
818}
819
820//! Set the current thread heap
821static void

Calls

no outgoing calls

Tested by

no test coverage detected