1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
︙ | | | ︙ | |
20
21
22
23
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
54
55
56
57
|
#import "ObjFWRT.h"
#import "private.h"
#ifdef OF_HAVE_THREADS
# import "OFPlainMutex.h"
static struct lock {
id object;
int count;
OFPlainRecursiveMutex rmutex;
struct lock *next;
} *locks = NULL;
static OFPlainMutex mutex;
OF_CONSTRUCTOR()
{
if (OFPlainMutexNew(&mutex) != 0)
OBJC_ERROR("Failed to create mutex!");
}
#endif
int
objc_sync_enter(id object)
{
if (object == nil)
return 0;
#ifdef OF_HAVE_THREADS
struct lock *lock;
if (OFPlainMutexLock(&mutex) != 0)
OBJC_ERROR("Failed to lock mutex!");
/* Look if we already have a lock */
for (lock = locks; lock != NULL; lock = lock->next) {
if (lock->object != object)
|
|
|
|
|
20
21
22
23
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
54
55
56
57
|
#import "ObjFWRT.h"
#import "private.h"
#ifdef OF_HAVE_THREADS
# import "OFPlainMutex.h"
static struct Lock {
id object;
int count;
OFPlainRecursiveMutex rmutex;
struct Lock *next;
} *locks = NULL;
static OFPlainMutex mutex;
OF_CONSTRUCTOR()
{
if (OFPlainMutexNew(&mutex) != 0)
OBJC_ERROR("Failed to create mutex!");
}
#endif
int
objc_sync_enter(id object)
{
if (object == nil)
return 0;
#ifdef OF_HAVE_THREADS
struct Lock *lock;
if (OFPlainMutexLock(&mutex) != 0)
OBJC_ERROR("Failed to lock mutex!");
/* Look if we already have a lock */
for (lock = locks; lock != NULL; lock = lock->next) {
if (lock->object != object)
|
︙ | | | ︙ | |
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
int
objc_sync_exit(id object)
{
if (object == nil)
return 0;
#ifdef OF_HAVE_THREADS
struct lock *lock, *last = NULL;
if (OFPlainMutexLock(&mutex) != 0)
OBJC_ERROR("Failed to lock mutex!");
for (lock = locks; lock != NULL; lock = lock->next) {
if (lock->object != object) {
last = lock;
|
|
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
int
objc_sync_exit(id object)
{
if (object == nil)
return 0;
#ifdef OF_HAVE_THREADS
struct Lock *lock, *last = NULL;
if (OFPlainMutexLock(&mutex) != 0)
OBJC_ERROR("Failed to lock mutex!");
for (lock = locks; lock != NULL; lock = lock->next) {
if (lock->object != object) {
last = lock;
|
︙ | | | ︙ | |
126
127
128
129
130
131
132
133
134
135
136
137
|
if (OFPlainMutexUnlock(&mutex) != 0)
OBJC_ERROR("Failed to unlock mutex!");
return 0;
}
OBJC_ERROR("objc_sync_exit() was called for an object not locked!");
#else
return 0;
#endif
}
|
|
|
126
127
128
129
130
131
132
133
134
135
136
137
|
if (OFPlainMutexUnlock(&mutex) != 0)
OBJC_ERROR("Failed to unlock mutex!");
return 0;
}
OBJC_ERROR("objc_sync_exit() was called for an unlocked object!");
#else
return 0;
#endif
}
|