thread.h 1.45 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3
 *
Vicent Marti committed
4 5
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
6 7
 */

8 9
#ifndef INCLUDE_win32_thread_h__
#define INCLUDE_win32_thread_h__
10

11
#include "common.h"
12 13 14 15 16 17 18

#if defined (_MSC_VER)
#	define GIT_RESTRICT __restrict
#else
#	define GIT_RESTRICT __restrict__
#endif

19 20 21
typedef struct {
	HANDLE thread;
	void *(*proc)(void *);
Philip Kelley committed
22 23
	void *param;
	void *result;
24
} git_thread;
25

26
typedef CRITICAL_SECTION git_mutex;
27
typedef HANDLE git_cond;
28

29 30
typedef struct { void *Ptr; } GIT_SRWLOCK;

31 32
typedef struct {
	union {
33
		GIT_SRWLOCK srwl;
34 35
		CRITICAL_SECTION csec;
	} native;
36
} git_rwlock;
37

38 39
int git_threads_init(void);

40
int git_thread_create(git_thread *GIT_RESTRICT,
41 42
	void *(*) (void *),
	void *GIT_RESTRICT);
43
int git_thread_join(git_thread *, void **);
44 45
size_t git_thread_currentid(void);
void git_thread_exit(void *);
Philip Kelley committed
46

47 48 49 50
int git_mutex_init(git_mutex *GIT_RESTRICT mutex);
int git_mutex_free(git_mutex *);
int git_mutex_lock(git_mutex *);
int git_mutex_unlock(git_mutex *);
51

52 53 54 55
int git_cond_init(git_cond *);
int git_cond_free(git_cond *);
int git_cond_wait(git_cond *, git_mutex *);
int git_cond_signal(git_cond *);
56

57 58 59 60 61 62
int git_rwlock_init(git_rwlock *GIT_RESTRICT lock);
int git_rwlock_rdlock(git_rwlock *);
int git_rwlock_rdunlock(git_rwlock *);
int git_rwlock_wrlock(git_rwlock *);
int git_rwlock_wrunlock(git_rwlock *);
int git_rwlock_free(git_rwlock *);
63

64
#endif