ObjFW  Diff

Differences From Artifact [0a8dcabb44]:

To Artifact [dc3b3466a2]:


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
52
53
#ifdef _WIN32
#include <windows.h>
#endif

#import "OFMacros.h"

struct locks_s {
	id		obj;
	size_t		count;
	size_t		recursion;
#ifndef _WIN32
	pthread_t	thread;
	pthread_mutex_t	mutex;
#else
	HANDLE		thread;
	HANDLE		mutex;
#endif
};

#ifndef _WIN32
static pthread_mutex_t mutex;
#else
static HANDLE mutex;
#endif
static struct locks_s *locks = NULL;
static size_t num_locks = 0;

#ifndef _WIN32
static OF_INLINE BOOL
mutex_new(pthread_mutex_t *m)







|
|
|

|
|

|
|






|







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
52
53
#ifdef _WIN32
#include <windows.h>
#endif

#import "OFMacros.h"

struct locks_s {
	id		 obj;
	size_t		 count;
	size_t		 recursion;
#ifndef _WIN32
	pthread_t	 thread;
	pthread_mutex_t	 mutex;
#else
	DWORD		 thread;
	CRITICAL_SECTION mutex;
#endif
};

#ifndef _WIN32
static pthread_mutex_t mutex;
#else
static CRITICAL_SECTION mutex;
#endif
static struct locks_s *locks = NULL;
static size_t num_locks = 0;

#ifndef _WIN32
static OF_INLINE BOOL
mutex_new(pthread_mutex_t *m)
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96

97
98
99
100
101
102

103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
static OF_INLINE pthread_t
thread_current()
{
	return pthread_self();
}
#else
static OF_INLINE BOOL
mutex_new(HANDLE *m)
{

	return (((*m = CreateMutex(NULL, FALSE, NULL)) != NULL) ? YES : NO);
}

static OF_INLINE BOOL
mutex_free(HANDLE *m)
{

	return (CloseHandle(*m) ? YES : NO);
}

static OF_INLINE BOOL
mutex_lock(HANDLE *m)
{

	return (WaitForSingleObject(*m, INFINITE) == WAIT_OBJECT_0 ? YES : NO);
}

static OF_INLINE BOOL
mutex_unlock(HANDLE *m)
{

	return (ReleaseMutex(*m) ? YES : NO);
}

static OF_INLINE BOOL
thread_is_current(HANDLE t)
{
	return (t == GetCurrentThread() ? YES : NO);
}

static OF_INLINE HANDLE
thread_current()
{
	return GetCurrentThread();
}
#endif

BOOL
objc_sync_init()
{
	return (mutex_new(&mutex) ? YES : NO);







|

>
|



|

>
|



|

>
|



|

>
|



|

|


|


|







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
static OF_INLINE pthread_t
thread_current()
{
	return pthread_self();
}
#else
static OF_INLINE BOOL
mutex_new(CRITICAL_SECTION *m)
{
	InitializeCriticalSection(m);
	return YES;
}

static OF_INLINE BOOL
mutex_free(CRITICAL_SECTION *m)
{
	DeleteCriticalSection(m);
	return YES;
}

static OF_INLINE BOOL
mutex_lock(CRITICAL_SECTION *m)
{
	EnterCriticalSection(m);
	return YES;
}

static OF_INLINE BOOL
mutex_unlock(CRITICAL_SECTION *m)
{
	LeaveCriticalSection(m);
	return YES;
}

static OF_INLINE BOOL
thread_is_current(DWORD t)
{
	return (t == GetCurrentThreadId() ? YES : NO);
}

static OF_INLINE DWORD
thread_current()
{
	return GetCurrentThreadId();
}
#endif

BOOL
objc_sync_init()
{
	return (mutex_new(&mutex) ? YES : NO);