| 257 | } |
| 258 | |
| 259 | void init_main_thread_stack() { |
| 260 | #ifdef __APPLE__ |
| 261 | auto self = pthread_self(); |
| 262 | stack_size = pthread_get_stacksize_np(self); |
| 263 | stackful_alloc_top = (char*) pthread_get_stackaddr_np(self); |
| 264 | #elif defined(_WIN64) |
| 265 | ULONG_PTR stack_low, stack_high; |
| 266 | GetCurrentThreadStackLimits(&stack_low, &stack_high); |
| 267 | stackful_alloc_top = (char*)stack_low; |
| 268 | stack_size = stack_high - stack_low; |
| 269 | #elif defined(__linux__) |
| 270 | pthread_attr_t gattr; |
| 271 | pthread_getattr_np(pthread_self(), &gattr); |
| 272 | pthread_attr_getstack(&gattr, |
| 273 | (void**)&stackful_alloc_top, &stack_size); |
| 274 | pthread_attr_destroy(&gattr); |
| 275 | #else |
| 276 | static_assert(false, "unsupported platform"); |
| 277 | #endif |
| 278 | } |
| 279 | |
| 280 | void die() __attribute__((always_inline)); |
| 281 | void dequeue_ready_atomic(states newstat = states::READY); |