pthread.h 1.93 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 10 11 12 13 14 15 16 17 18 19 20 21
 */

#ifndef GIT_PTHREAD_H
#define GIT_PTHREAD_H

#include "../common.h"

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

typedef int pthread_mutexattr_t;
typedef int pthread_condattr_t;
typedef int pthread_attr_t;
22 23
typedef int pthread_rwlockattr_t;

24 25
typedef CRITICAL_SECTION pthread_mutex_t;
typedef HANDLE pthread_t;
26
typedef HANDLE pthread_cond_t;
27

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

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

37
#define PTHREAD_MUTEX_INITIALIZER  {(void*)-1}
38

39
int pthread_create(
40 41
	pthread_t *GIT_RESTRICT thread,
	const pthread_attr_t *GIT_RESTRICT attr,
42
	void *(*start_routine)(void*),
43
	void *GIT_RESTRICT arg);
44 45 46

int pthread_join(pthread_t, void **);

47
int pthread_mutex_init(
48 49
	pthread_mutex_t *GIT_RESTRICT mutex,
	const pthread_mutexattr_t *GIT_RESTRICT mutexattr);
50 51 52 53
int pthread_mutex_destroy(pthread_mutex_t *);
int pthread_mutex_lock(pthread_mutex_t *);
int pthread_mutex_unlock(pthread_mutex_t *);

54 55 56 57 58 59
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
int pthread_cond_destroy(pthread_cond_t *);
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
int pthread_cond_signal(pthread_cond_t *);
/* pthread_cond_broadcast is not supported on Win32 yet. */

60 61
int pthread_num_processors_np(void);

62
int pthread_rwlock_init(
63 64
	pthread_rwlock_t *GIT_RESTRICT lock,
	const pthread_rwlockattr_t *GIT_RESTRICT attr);
65 66 67 68 69 70
int pthread_rwlock_rdlock(pthread_rwlock_t *);
int pthread_rwlock_rdunlock(pthread_rwlock_t *);
int pthread_rwlock_wrlock(pthread_rwlock_t *);
int pthread_rwlock_wrunlock(pthread_rwlock_t *);
int pthread_rwlock_destroy(pthread_rwlock_t *);

71 72
extern int win32_pthread_initialize(void);

Vicent Marti committed
73
#endif