Git 2.23
[gitweb.git] / compat / win32 / pthread.c
index 631c0a46ea3ddc4daaa773128b4a3e7a001653de..2e7eead42cb008980c7a3b4de63050897c2996da 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2009 Andrzej K. Haczewski <ahaczewski@gmail.com>
  *
- * DISCLAMER: The implementation is Git-specific, it is subset of original
+ * DISCLAIMER: The implementation is Git-specific, it is subset of original
  * Pthreads API, without lots of other features that Git doesn't use.
  * Git also makes sure that the passed arguments are valid, so there's
  * no need for double-checking.
@@ -16,6 +16,7 @@
 static unsigned __stdcall win32_start_routine(void *arg)
 {
        pthread_t *thread = arg;
+       thread->tid = GetCurrentThreadId();
        thread->arg = thread->start_routine(thread->arg);
        return 0;
 }
@@ -49,62 +50,9 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
        }
 }
 
-int pthread_cond_init(pthread_cond_t *cond, const void *unused)
+pthread_t pthread_self(void)
 {
-       cond->waiters = 0;
-
-       cond->sema = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
-       if (!cond->sema)
-               die("CreateSemaphore() failed");
-       return 0;
-}
-
-int pthread_cond_destroy(pthread_cond_t *cond)
-{
-       CloseHandle(cond->sema);
-       cond->sema = NULL;
-
-       return 0;
-}
-
-int pthread_cond_wait(pthread_cond_t *cond, CRITICAL_SECTION *mutex)
-{
-       InterlockedIncrement(&cond->waiters);
-
-       /*
-        * Unlock external mutex and wait for signal.
-        * NOTE: we've held mutex locked long enough to increment
-        * waiters count above, so there's no problem with
-        * leaving mutex unlocked before we wait on semaphore.
-        */
-       LeaveCriticalSection(mutex);
-
-       /* let's wait - ignore return value */
-       WaitForSingleObject(cond->sema, INFINITE);
-
-       /* we're done waiting, so make sure we decrease waiters count */
-       InterlockedDecrement(&cond->waiters);
-
-       /* lock external mutex again */
-       EnterCriticalSection(mutex);
-
-       return 0;
-}
-
-int pthread_cond_signal(pthread_cond_t *cond)
-{
-       /*
-        * Access to waiters count is atomic; see "Interlocked Variable Access"
-        * http://msdn.microsoft.com/en-us/library/ms684122(VS.85).aspx
-        */
-       int have_waiters = cond->waiters > 0;
-
-       /*
-        * Signal only when there are waiters
-        */
-       if (have_waiters)
-               return ReleaseSemaphore(cond->sema, 1, NULL) ?
-                       0 : err_win_to_posix(GetLastError());
-       else
-               return 0;
+       pthread_t t = { NULL };
+       t.tid = GetCurrentThreadId();
+       return t;
 }