]> git.proxmox.com Git - libgit2.git/blob - src/win32/pthread.c
Update Copyright header
[libgit2.git] / src / win32 / pthread.c
1 /*
2 * Copyright (C) 2009-2012 the libgit2 contributors
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #include "pthread.h"
9
10 int pthread_create(pthread_t *GIT_RESTRICT thread,
11 const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr),
12 void *(*start_routine)(void*), void *GIT_RESTRICT arg)
13 {
14 GIT_UNUSED_ARG(attr);
15 *thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL);
16 return *thread ? GIT_SUCCESS : git__throw(GIT_EOSERR, "Failed to create pthread");
17 }
18
19 int pthread_join(pthread_t thread, void **value_ptr)
20 {
21 int ret;
22 ret = WaitForSingleObject(thread, INFINITE);
23 if (ret && value_ptr)
24 GetExitCodeThread(thread, (void*) value_ptr);
25 return -(!!ret);
26 }
27
28 int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex,
29 const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr))
30 {
31 GIT_UNUSED_ARG(mutexattr);
32 InitializeCriticalSection(mutex);
33 return 0;
34 }
35
36 int pthread_mutex_destroy(pthread_mutex_t *mutex)
37 {
38 DeleteCriticalSection(mutex);
39 return 0;
40 }
41
42 int pthread_mutex_lock(pthread_mutex_t *mutex)
43 {
44 EnterCriticalSection(mutex);
45 return 0;
46 }
47
48 int pthread_mutex_unlock(pthread_mutex_t *mutex)
49 {
50 LeaveCriticalSection(mutex);
51 return 0;
52 }
53
54 int pthread_num_processors_np(void)
55 {
56 DWORD_PTR p, s;
57 int n = 0;
58
59 if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s))
60 for (; p; p >>= 1)
61 n += p&1;
62
63 return n ? n : 1;
64 }
65