diff options
| author | Shawn O. Pearce <spearce@spearce.org> | 2008-12-30 21:49:38 -0800 |
|---|---|---|
| committer | Shawn O. Pearce <spearce@spearce.org> | 2008-12-30 21:56:11 -0800 |
| commit | a1d34bc000cee6d72c3b5e329faa58424641611f (patch) | |
| tree | 89d3150640c0ed5b386bc8113ac8999b20371ece /src/git/thread-utils.h | |
| parent | d74679498086d0fc2293dceb59155c696b11b86c (diff) | |
| download | libgit2-a1d34bc000cee6d72c3b5e329faa58424641611f.tar.gz | |
Support building on Mac OS X by using pthread_getspecific for TLS
The Mach-O format does not permit gcc to implement the __thread
TLS specification, so we must instead emulate it using a single
int cell allocated from memory and stored inside of the thread
specific data associated with the current pthread.
What makes this tricky is git_errno must be a valid lvalue, so
we really need to return a pointer to the caller and deference it
as part of the git_errno macro.
The GCC-specific __attribute__((constructor)) extension is used
to ensure the pthread_key_t is allocated before any Git functions
are executed in the library, as this is necessary to access our
thread specific storage.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/git/thread-utils.h')
| -rw-r--r-- | src/git/thread-utils.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/git/thread-utils.h b/src/git/thread-utils.h index c14aa17cb..8baf75bed 100644 --- a/src/git/thread-utils.h +++ b/src/git/thread-utils.h @@ -9,8 +9,15 @@ #define GIT_HAS_TLS 1 -#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || \ - defined(__xlc__) || defined(__xlC__) +#if defined(__APPLE__) && defined(__MACH__) +# undef GIT_TLS +# define GIT_HAS_PTHREAD + +#elif defined(__GNUC__) || \ + defined(__SUNPRO_C) || \ + defined(__SUNPRO_CC) || \ + defined(__xlc__) || \ + defined(__xlC__) # define GIT_TLS __thread #elif defined(__INTEL_COMPILER) @@ -20,7 +27,9 @@ # define GIT_TLS __thread # endif -#elif defined(_WIN32) || defined(_WIN32_CE) || defined(__BORLANDC__) +#elif defined(_WIN32) || \ + defined(_WIN32_CE) || \ + defined(__BORLANDC__) # define GIT_TLS __declspec(thread) #else |
