Drop support for THREADSAFE on Windows XP This makes libgit2 require Windows Vista or newer if it is going to be compiled with the THREADSAFE option
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1c70ec2..019777e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -287,8 +287,13 @@ FILE(GLOB SRC_H include/git2.h include/git2/*.h include/git2/sys/*.h)
# On Windows use specific platform sources
IF (WIN32 AND NOT CYGWIN)
- ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0501)
+ ADD_DEFINITIONS(-DWIN32)
FILE(GLOB SRC_OS src/win32/*.c src/win32/*.h)
+ IF (THREADSAFE)
+ ADD_DEFINITIONS(-D_WIN32_WINNT=0x0600)
+ ELSE()
+ ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
+ ENDIF()
ELSEIF (AMIGA)
ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R)
FILE(GLOB SRC_OS src/amiga/*.c src/amiga/*.h)
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 819e24e..371dc0b 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -40,6 +40,10 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
+#if defined(GIT_WIN32) && _WIN32_WINNT < 0x0600
+# error "Unsupported Windows version for thread support"
+#endif
+
#define git_thread pthread_t
#define git_thread_create(thread, attr, start_routine, arg) \
pthread_create(thread, attr, start_routine, arg)
@@ -62,7 +66,15 @@ typedef git_atomic git_atomic_ssize;
#define git_cond_signal(c) pthread_cond_signal(c)
#define git_cond_broadcast(c) pthread_cond_broadcast(c)
-/* Pthreads rwlock */
+/* Pthread (-ish) rwlock
+ *
+ * This differs from normal pthreads rwlocks in two ways:
+ * 1. Separate APIs for releasing read locks and write locks (as
+ * opposed to the pure POSIX API which only has one unlock fn)
+ * 2. You should not use recursive read locks (i.e. grabbing a read
+ * lock in a thread that already holds a read lock) because the
+ * Windows implementation doesn't support it
+ */
#define git_rwlock pthread_rwlock_t
#define git_rwlock_init(a) pthread_rwlock_init(a, NULL)
#define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a)