ObjFW  Diff

Differences From Artifact [42e8f34c96]:

To Artifact [f1fb27ae31]:


12
13
14
15
16
17
18


19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27







+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <errno.h>

#import "OFCondition.h"
#import "OFDate.h"

#import "OFConditionBroadcastFailedException.h"
#import "OFConditionSignalFailedException.h"
#import "OFConditionStillWaitingException.h"
45
46
47
48
49
50
51
52
53




54
55


56
57
58
59
60
61
62
63
64


65
66
67
68
69










70
71
72
73
74
75

76
77
78
79
80
81
82


83
84
85
86
87
88
89


90
91
47
48
49
50
51
52
53


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75

76
77
78
79
80
81
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







-
-
+
+
+
+


+
+








-
+
+




-
+
+
+
+
+
+
+
+
+
+




-
-
+






-
+
+






-
+
+


	_conditionInitialized = true;

	return self;
}

- (void)dealloc
{
	if (_conditionInitialized)
		if (!of_condition_free(&_condition))
	if (_conditionInitialized) {
		if (!of_condition_free(&_condition)) {
			OF_ENSURE(errno == EBUSY);

			@throw [OFConditionStillWaitingException
			    exceptionWithCondition: self];
		}
	}

	[super dealloc];
}

- (void)wait
{
	if (!of_condition_wait(&_condition, &_mutex))
		@throw [OFConditionWaitFailedException
		    exceptionWithCondition: self];
		    exceptionWithCondition: self
				     errNo: errno];
}

- (bool)waitForTimeInterval: (of_time_interval_t)timeInterval
{
	return of_condition_timed_wait(&_condition, &_mutex, timeInterval);
	if (!of_condition_timed_wait(&_condition, &_mutex, timeInterval)) {
		if (errno == ETIMEDOUT)
			return false;
		else
			@throw [OFConditionWaitFailedException
			    exceptionWithCondition: self
					     errNo: errno];
	}

	return true;
}

- (bool)waitUntilDate: (OFDate *)date
{
	return of_condition_timed_wait(&_condition, &_mutex,
	    date.timeIntervalSinceNow);
	return [self waitForTimeInterval: date.timeIntervalSinceNow];
}

- (void)signal
{
	if (!of_condition_signal(&_condition))
		@throw [OFConditionSignalFailedException
		    exceptionWithCondition: self];
		    exceptionWithCondition: self
				     errNo: errno];
}

- (void)broadcast
{
	if (!of_condition_broadcast(&_condition))
		@throw [OFConditionBroadcastFailedException
		    exceptionWithCondition: self];
		    exceptionWithCondition: self
				     errNo: errno];
}
@end