ObjFW  Check-in [0e4c54215b]

Overview
Comment:Improve of_condition_wait error handling on Win32
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.8
Files: files | file ages | folders
SHA3-256: 0e4c54215b318369c51ec13b05d45d347531aa0c3307cb2b86fc9fd02f6954a9
User & Date: js on 2016-04-18 17:21:49
Other Links: branch diff | manifest | tags
Context
2016-04-18
17:22
OFThread: Fix missing include check-in: ad9813cef0 user: js tags: 0.8
17:21
Improve of_condition_wait error handling on Win32 check-in: 0e4c54215b user: js tags: 0.8
2016-03-28
19:35
URL encoding: Make sure an unsigned shift is used check-in: 31dbd46481 user: js tags: 0.8
Changes

Modified src/threading_winapi.m from [ecc9bb9249] to [1b66353934].

165
166
167
168
169
170
171


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

	return true;
}

bool
of_condition_wait(of_condition_t *condition, of_mutex_t *mutex)
{


	if (!of_mutex_unlock(mutex))
		return false;

	of_atomic_int_inc(&condition->count);

	if (WaitForSingleObject(condition->event, INFINITE) != WAIT_OBJECT_0) {
		of_mutex_lock(mutex);
		return false;
	}

	of_atomic_int_dec(&condition->count);

	if (!of_mutex_lock(mutex))
		return false;

	return true;
}

bool
of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex,
    of_time_interval_t timeout)
{


	if (!of_mutex_unlock(mutex))
		return false;

	of_atomic_int_inc(&condition->count);

	if (WaitForSingleObject(condition->event, timeout * 1000) !=
	    WAIT_OBJECT_0) {
		of_mutex_lock(mutex);
		return false;
	}

	of_atomic_int_dec(&condition->count);

	if (!of_mutex_lock(mutex))
		return false;

	return true;
}

bool
of_condition_free(of_condition_t *condition)
{
	if (condition->count != 0)
		return false;

	return CloseHandle(condition->event);
}







>
>




<
|
<
<
<
<





|






>
>




<
|
<
<
<
<
<





|










165
166
167
168
169
170
171
172
173
174
175
176
177

178




179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

197





198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

	return true;
}

bool
of_condition_wait(of_condition_t *condition, of_mutex_t *mutex)
{
	DWORD status;

	if (!of_mutex_unlock(mutex))
		return false;

	of_atomic_int_inc(&condition->count);

	status = WaitForSingleObject(condition->event, INFINITE);




	of_atomic_int_dec(&condition->count);

	if (!of_mutex_lock(mutex))
		return false;

	return (status == WAIT_OBJECT_0);
}

bool
of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex,
    of_time_interval_t timeout)
{
	DWORD status;

	if (!of_mutex_unlock(mutex))
		return false;

	of_atomic_int_inc(&condition->count);

	status = WaitForSingleObject(condition->event, timeout * 1000);





	of_atomic_int_dec(&condition->count);

	if (!of_mutex_lock(mutex))
		return false;

	return (status == WAIT_OBJECT_0);
}

bool
of_condition_free(of_condition_t *condition)
{
	if (condition->count != 0)
		return false;

	return CloseHandle(condition->event);
}