| 1 | /* | ||
| 2 | * This file intentionally does not include the Perl headers. On some | ||
| 3 | * platforms (notably Windows) XSUB.h redirects stdio functions through | ||
| 4 | * the current Perl interpreter, which is exactly what we may not have | ||
| 5 | * when ffi_pl_closure_wrong_thread gets called. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include "ffi_platypus.h" | ||
| 11 | |||
| 12 | #if defined FFI_PL_THREAD_ID_TLS | ||
| 13 | |||
| 14 | #if defined FFI_PL_PROBE_TLS_C11 | ||
| 15 | static _Thread_local char marker; | ||
| 16 | #elif defined FFI_PL_PROBE_TLS_GNU | ||
| 17 | static __thread char marker; | ||
| 18 | #else | ||
| 19 | static __declspec(thread) char marker; | ||
| 20 | #endif | ||
| 21 | |||
| 22 | ffi_pl_thread_id | ||
| 23 | 194 | ffi_pl_thread_self(void) | |
| 24 | { | ||
| 25 | 194 | return ▮ | |
| 26 | } | ||
| 27 | |||
| 28 | #elif defined FFI_PL_THREAD_ID_WIN32 | ||
| 29 | |||
| 30 | #include <windows.h> | ||
| 31 | |||
| 32 | ffi_pl_thread_id | ||
| 33 | ffi_pl_thread_self(void) | ||
| 34 | { | ||
| 35 | return GetCurrentThreadId(); | ||
| 36 | } | ||
| 37 | |||
| 38 | #elif defined FFI_PL_THREAD_ID_PTHREAD | ||
| 39 | |||
| 40 | ffi_pl_thread_id | ||
| 41 | ffi_pl_thread_self(void) | ||
| 42 | { | ||
| 43 | return pthread_self(); | ||
| 44 | } | ||
| 45 | |||
| 46 | #endif | ||
| 47 | |||
| 48 | #ifdef FFI_PL_HAVE_THREAD_ID | ||
| 49 | |||
| 50 | int | ||
| 51 | 104 | ffi_pl_thread_equal(ffi_pl_thread_id a, ffi_pl_thread_id b) | |
| 52 | { | ||
| 53 | #ifdef FFI_PL_THREAD_ID_PTHREAD | ||
| 54 | return pthread_equal(a, b); | ||
| 55 | #else | ||
| 56 | 104 | return a == b; | |
| 57 | #endif | ||
| 58 | } | ||
| 59 | |||
| 60 | #endif | ||
| 61 | |||
| 62 | void | ||
| 63 | 0 | ffi_pl_closure_wrong_thread(void) | |
| 64 | { | ||
| 65 | 0 | fprintf(stderr, | |
| 66 | "FFI::Platypus: a closure was called from a thread other than the Perl\n" | ||
| 67 | "thread that created it. Closures may only be called from the Perl thread\n" | ||
| 68 | "that created them. See the FFI::Platypus FAQ entry \"Can I call a closure\n" | ||
| 69 | "from a thread created by a C library?\" for workarounds.\n" | ||
| 70 | ); | ||
| 71 | 0 | fflush(stderr); | |
| 72 | 0 | abort(); | |
| 73 | } |