From a1d34bc000cee6d72c3b5e329faa58424641611f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 30 Dec 2008 21:49:38 -0800 Subject: 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 --- src/git/errors.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/git/errors.h') diff --git a/src/git/errors.h b/src/git/errors.h index 18eb2b8ad..37870a4c5 100644 --- a/src/git/errors.h +++ b/src/git/errors.h @@ -13,8 +13,15 @@ GIT_BEGIN_DECL /** The git errno. */ +#if defined(GIT_TLS) GIT_EXTERN(int) GIT_TLS git_errno; +#elif defined(GIT_HAS_PTHREAD) +# define git_errno (*git__errno_storage()) +GIT_EXTERN(int *) git__errno_storage(void); + +#endif + /** * strerror() for the Git library * @param num The error code to explain -- cgit v1.2.1