summaryrefslogtreecommitdiff
path: root/src/git
diff options
context:
space:
mode:
authorAndreas Ericsson <ae@op5.se>2008-11-18 19:06:25 +0100
committerShawn O. Pearce <spearce@spearce.org>2008-11-18 10:32:53 -0800
commit36f0f61fc8578478a9dc9b33a1a0d07cdb98a5e5 (patch)
tree14be9ebaa30a1d6085e889eecaf2a24968eea24e /src/git
parenta57e9a8cc15b61ae1ab908b362fd829b3e36e513 (diff)
downloadlibgit2-36f0f61fc8578478a9dc9b33a1a0d07cdb98a5e5.tar.gz
Add compiler/platform agnostic thread-local storage
It doesn't cover all cases, but we can work on those as we go along. For now, gcc, MSVC++, Intel C/C++, IBM XL C/C++, Sun Studio C/C++ and Borland C++ Builder are the supported compilers (although we boldly assume that they all are of a recent enough version to support thread-local storage). This is intended to be used in upcoming patches that implement graceful (but TLS-dependant) error-handling in the library. As an added bonus, we also bring the online_cpus() function from git.git to detect the number of usable cpu's. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/git')
-rw-r--r--src/git/thread-utils.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/git/thread-utils.h b/src/git/thread-utils.h
new file mode 100644
index 000000000..f2ddf1eec
--- /dev/null
+++ b/src/git/thread-utils.h
@@ -0,0 +1,25 @@
+#ifndef INCLUDE_git_thread_utils_h__
+#define INCLUDE_git_thread_utils_h__
+/*
+ * How TLS works is compiler+platform dependant
+ * Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage
+ * http://predef.sourceforge.net/precomp.html
+ */
+#define GIT_HAS_TLS 1
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || \
+ defined(__xlc__) || defined(__xlC__)
+# define GIT_TLS __thread
+#elif defined(__INTEL_COMPILER)
+# if defined(_WIN32) || defined(_WIN32_CE)
+# define GIT_TLS __declspec(thread)
+# else
+# define GIT_TLS __thread
+# endif
+#elif defined(_WIN32) || defined(_WIN32_CE) || defined(__BORLANDC__)
+# define GIT_TLS __declspec(thread)
+#else
+# undef GIT_HAS_TLS
+# define GIT_TLS /* nothing: tls vars are thread-global */
+#endif
+
+#endif /* INCLUDE_git_thread_utils_h__ */