Skip to content

Commit

Permalink
Merge pull request google-research#1127 from google-research/fix-maco…
Browse files Browse the repository at this point in the history
…s-pthread-key

Allow for OS-dependent pthread_key_t
  • Loading branch information
dougalm authored Oct 17, 2022
2 parents 040fe0c + 289184b commit d116661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib/ImpToLLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,13 @@ getDyvarKey v = do

-- This is actually implementation-dependent, but we verify that it's true in dexrt.cpp
pthreadKeyTy :: L.Type
#if defined(linux_HOST_OS)
pthreadKeyTy = i32
#elif defined(darwin_HOST_OS)
pthreadKeyTy = i64
#else
# error Unsupported OS
#endif

pthread_setspecific :: ExternFunSpec
pthread_setspecific = ExternFunSpec "pthread_setspecific" i32 [] [] [pthreadKeyTy, hostVoidp]
Expand Down
10 changes: 9 additions & 1 deletion src/lib/dexrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
#include <type_traits>
#include <cstdint>

#if defined(__linux__)
static_assert(std::is_same<pthread_key_t, std::uint32_t>::value,
"Expected pthread_key_t to be an uint32_t!");
"On linux, expected pthread_key_t to be an uint32_t");
#elif defined(__APPLE__)
static_assert(std::is_same<pthread_key_t, unsigned long>::value,
"On macOS, Expected pthread_key_t to be an unsigned long");
static_assert(sizeof(unsigned long) == 8, "Expected 64-bit unsigned long");
#else
# error Unsupported OS
#endif

#ifdef DEX_LIVE
#include <png.h>
Expand Down

0 comments on commit d116661

Please sign in to comment.