summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/work_thread.c
blob: 38d87470f01a7b7ad877311791de0fe6ae8689dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*
 * work_thread.c - threads implementation for blocking worker child.
 */
#include <config.h>
#include "ntp_workimpl.h"

#ifdef WORK_THREAD

#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#ifndef SYS_WINNT
#include <pthread.h>
#endif

#include "ntp_stdlib.h"
#include "ntp_malloc.h"
#include "ntp_syslog.h"
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_assert.h"
#include "ntp_unixtime.h"
#include "timespecops.h"
#include "ntp_worker.h"

#define CHILD_EXIT_REQ	((blocking_pipe_header *)(intptr_t)-1)
#define CHILD_GONE_RESP	CHILD_EXIT_REQ
#define WORKITEMS_ALLOC_INC	16
#define RESPONSES_ALLOC_INC	4

#ifndef THREAD_MINSTACKSIZE
#define THREAD_MINSTACKSIZE	(64U * 1024)
#endif

#ifndef DEVOLATILE
#define DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var))
#endif

#ifdef SYS_WINNT
# define thread_exit(c)	_endthreadex(c)
# define tickle_sem	SetEvent
#else
# define thread_exit(c)	pthread_exit((void*)(size_t)(c))
# define tickle_sem	sem_post
#endif

#ifdef WORK_PIPE
addremove_io_fd_func		addremove_io_fd;
#else
addremove_io_semaphore_func	addremove_io_semaphore;
#endif

static	void	start_blocking_thread(blocking_child *);
static	void	start_blocking_thread_internal(blocking_child *);
static	void	prepare_child_sems(blocking_child *);
static	int	wait_for_sem(sem_ref, struct timespec *);
static	void	ensure_workitems_empty_slot(blocking_child *);
static	void	ensure_workresp_empty_slot(blocking_child *);
static	int	queue_req_pointer(blocking_child *, blocking_pipe_header *);
static	void	cleanup_after_child(blocking_child *);
#ifdef SYS_WINNT
u_int	WINAPI	blocking_thread(void *);
#else
void *		blocking_thread(void *);
#endif
#ifndef SYS_WINNT
static	void	block_thread_signals(sigset_t *);
#endif


void
exit_worker(
	int	exitcode
	)
{
	thread_exit(exitcode);	/* see #define thread_exit */
}


int
worker_sleep(
	blocking_child *	c,
	time_t			seconds
	)
{
	struct timespec	until;
	int		rc;

# ifdef HAVE_CLOCK_GETTIME
	if (0 != clock_gettime(CLOCK_REALTIME, &until)) {
		msyslog(LOG_ERR, "worker_sleep: clock_gettime() failed: %m");
		return -1;
	}
# else
	if (0 != getclock(TIMEOFDAY, &until)) {
		msyslog(LOG_ERR, "worker_sleep: getclock() failed: %m");
		return -1;
	}
# endif
	until.tv_sec += seconds;
	do {
		rc = wait_for_sem(c->wake_scheduled_sleep, &until);
	} while (-1 == rc && EINTR == errno);
	if (0 == rc)
		return -1;
	if (-1 == rc && ETIMEDOUT == errno)
		return 0;
	msyslog(LOG_ERR, "worker_sleep: sem_timedwait: %m");
	return -1;
}


void
interrupt_worker_sleep(void)
{
	u_int			idx;
	blocking_child *	c;

	for (idx = 0; idx < blocking_children_alloc; idx++) {
		c = blocking_children[idx];
		if (NULL == c || NULL == c->wake_scheduled_sleep)
			continue;
		tickle_sem(c->wake_scheduled_sleep);
	}
}


static void
ensure_workitems_empty_slot(
	blocking_child *c
	)
{
	const size_t	each = sizeof(blocking_children[0]->workitems[0]);
	size_t		new_alloc;
	size_t		old_octets;
	size_t		new_octets;
	void *		nonvol_workitems;


	if (c->workitems != NULL &&
	    NULL == c->workitems[c->next_workitem])
		return;

	new_alloc = c->workitems_alloc + WORKITEMS_ALLOC_INC;
	old_octets = c->workitems_alloc * each;
	new_octets = new_alloc * each;
	nonvol_workitems = DEVOLATILE(void *, c->workitems);
	c->workitems = erealloc_zero(nonvol_workitems, new_octets,
				     old_octets);
	if (0 == c->next_workitem)
		c->next_workitem = c->workitems_alloc;
	c->workitems_alloc = new_alloc;
}


static void
ensure_workresp_empty_slot(
	blocking_child *c
	)
{
	const size_t	each = sizeof(blocking_children[0]->responses[0]);
	size_t		new_alloc;
	size_t		old_octets;
	size_t		new_octets;
	void *		nonvol_responses;

	if (c->responses != NULL &&
	    NULL == c->responses[c->next_response])
		return;

	new_alloc = c->responses_alloc + RESPONSES_ALLOC_INC;
	old_octets = c->responses_alloc * each;
	new_octets = new_alloc * each;
	nonvol_responses = DEVOLATILE(void *, c->responses);
	c->responses = erealloc_zero(nonvol_responses, new_octets,
				     old_octets);
	if (0 == c->next_response)
		c->next_response = c->responses_alloc;
	c->responses_alloc = new_alloc;
}


/*
 * queue_req_pointer() - append a work item or idle exit request to
 *			 blocking_workitems[].
 */
static int
queue_req_pointer(
	blocking_child	*	c,
	blocking_pipe_header *	hdr
	)
{
	c->workitems[c->next_workitem] = hdr;
	c->next_workitem = (1 + c->next_workitem) % c->workitems_alloc;

	/*
	 * We only want to signal the wakeup event if the child is
	 * blocking on it, which is indicated by setting the blocking
	 * event.  Wait with zero timeout to test.
	 */
	/* !!!! if (WAIT_OBJECT_0 == WaitForSingleObject(c->child_is_blocking, 0)) */
		tickle_sem(c->blocking_req_ready);

	return 0;
}


int
send_blocking_req_internal(
	blocking_child *	c,
	blocking_pipe_header *	hdr,
	void *			data
	)
{
	blocking_pipe_header *	threadcopy;
	size_t			payload_octets;

	REQUIRE(hdr != NULL);
	REQUIRE(data != NULL);
	DEBUG_REQUIRE(BLOCKING_REQ_MAGIC == hdr->magic_sig);

	if (hdr->octets <= sizeof(*hdr))
		return 1;	/* failure */
	payload_octets = hdr->octets - sizeof(*hdr);

	ensure_workitems_empty_slot(c);
	if (NULL == c->thread_ref) {
		ensure_workresp_empty_slot(c);
		start_blocking_thread(c);
	}

	threadcopy = emalloc(hdr->octets);
	memcpy(threadcopy, hdr, sizeof(*hdr));
	memcpy((char *)threadcopy + sizeof(*hdr), data, payload_octets);

	return queue_req_pointer(c, threadcopy);
}


blocking_pipe_header *
receive_blocking_req_internal(
	blocking_child *	c
	)
{
	blocking_pipe_header *	req;
	int			rc;

	/*
	 * Child blocks here when idle.  SysV semaphores maintain a
	 * count and release from sem_wait() only when it reaches 0.
	 * Windows auto-reset events are simpler, and multiple SetEvent
	 * calls before any thread waits result in a single wakeup.
	 * On Windows, the child drains all workitems each wakeup, while
	 * with SysV semaphores wait_sem() is used before each item.
	 */
#ifdef SYS_WINNT
	while (NULL == c->workitems[c->next_workeritem]) {
		/* !!!! SetEvent(c->child_is_blocking); */
		rc = wait_for_sem(c->blocking_req_ready, NULL);
		INSIST(0 == rc);
		/* !!!! ResetEvent(c->child_is_blocking); */
	}
#else
	do {
		rc = wait_for_sem(c->blocking_req_ready, NULL);
	} while (-1 == rc && EINTR == errno);
	INSIST(0 == rc);
#endif

	req = c->workitems[c->next_workeritem];
	INSIST(NULL != req);
	c->workitems[c->next_workeritem] = NULL;
	c->next_workeritem = (1 + c->next_workeritem) %
				c->workitems_alloc;

	if (CHILD_EXIT_REQ == req) {	/* idled out */
		send_blocking_resp_internal(c, CHILD_GONE_RESP);
		req = NULL;
	}

	return req;
}


int
send_blocking_resp_internal(
	blocking_child *	c,
	blocking_pipe_header *	resp
	)
{
	ensure_workresp_empty_slot(c);

	c->responses[c->next_response] = resp;
	c->next_response = (1 + c->next_response) % c->responses_alloc;

#ifdef WORK_PIPE
	write(c->resp_write_pipe, "", 1);
#else
	tickle_sem(c->blocking_response_ready);
#endif

	return 0;
}


#ifndef WORK_PIPE
void
handle_blocking_resp_sem(
	void *	context
	)
{
	HANDLE			ready;
	blocking_child *	c;
	u_int			idx;

	ready = (HANDLE)context;
	c = NULL;
	for (idx = 0; idx < blocking_children_alloc; idx++) {
		c = blocking_children[idx];
		if (c != NULL && c->thread_ref != NULL &&
		    ready == c->blocking_response_ready)
			break;
	}
	if (idx < blocking_children_alloc)
		process_blocking_resp(c);
}
#endif	/* !WORK_PIPE */


blocking_pipe_header *
receive_blocking_resp_internal(
	blocking_child *	c
	)
{
	blocking_pipe_header *	removed;
#ifdef WORK_PIPE
	int			rc;
	char			scratch[32];

	do {
		rc = read(c->resp_read_pipe, scratch, sizeof(scratch));
	} while (-1 == rc && EINTR == errno);
#endif
	removed = c->responses[c->next_workresp];
	if (NULL != removed) {
		c->responses[c->next_workresp] = NULL;
		c->next_workresp = (1 + c->next_workresp) %
				   c->responses_alloc;
		DEBUG_ENSURE(CHILD_GONE_RESP == removed ||
			     BLOCKING_RESP_MAGIC == removed->magic_sig);
	}
	if (CHILD_GONE_RESP == removed) {
		cleanup_after_child(c);
		removed = NULL;
	}

	return removed;
}


static void
start_blocking_thread(
	blocking_child *	c
	)
{

	DEBUG_INSIST(!c->reusable);

	prepare_child_sems(c);
	start_blocking_thread_internal(c);
}


static void
start_blocking_thread_internal(
	blocking_child *	c
	)
#ifdef SYS_WINNT
{
	thr_ref	blocking_child_thread;
	u_int	blocking_thread_id;
	BOOL	resumed;

	(*addremove_io_semaphore)(c->blocking_response_ready, FALSE);
	blocking_child_thread =
		(HANDLE)_beginthreadex(
			NULL,
			0,
			&blocking_thread,
			c,
			CREATE_SUSPENDED,
			&blocking_thread_id);

	if (NULL == blocking_child_thread) {
		msyslog(LOG_ERR, "start blocking thread failed: %m");
		exit(-1);
	}
	c->thread_id = blocking_thread_id;
	c->thread_ref = blocking_child_thread;
	/* remember the thread priority is only within the process class */
	if (!SetThreadPriority(blocking_child_thread,
			       THREAD_PRIORITY_BELOW_NORMAL))
		msyslog(LOG_ERR, "Error lowering blocking thread priority: %m");

	resumed = ResumeThread(blocking_child_thread);
	DEBUG_INSIST(resumed);
}
#else	/* pthreads start_blocking_thread_internal() follows */
{
# ifdef NEED_PTHREAD_INIT
	static int	pthread_init_called;
# endif
	pthread_attr_t	thr_attr;
	int		rc;
	int		saved_errno;
	int		pipe_ends[2];	/* read then write */
	int		is_pipe;
	int		flags;
	size_t		stacksize;
	sigset_t	saved_sig_mask;

# ifdef NEED_PTHREAD_INIT
	/*
	 * from lib/isc/unix/app.c:
	 * BSDI 3.1 seg faults in pthread_sigmask() if we don't do this.
	 */
	if (!pthread_init_called) {
		pthread_init();
		pthread_init_called = TRUE;
	}
# endif

	rc = pipe_socketpair(&pipe_ends[0], &is_pipe);
	if (0 != rc) {
		msyslog(LOG_ERR, "start_blocking_thread: pipe_socketpair() %m");
		exit(1);
	}
	c->resp_read_pipe = move_fd(pipe_ends[0]);
	c->resp_write_pipe = move_fd(pipe_ends[1]);
	c->ispipe = is_pipe;
	flags = fcntl(c->resp_read_pipe, F_GETFL, 0);
	if (-1 == flags) {
		msyslog(LOG_ERR, "start_blocking_thread: fcntl(F_GETFL) %m");
		exit(1);
	}
	rc = fcntl(c->resp_read_pipe, F_SETFL, O_NONBLOCK | flags);
	if (-1 == rc) {
		msyslog(LOG_ERR,
			"start_blocking_thread: fcntl(F_SETFL, O_NONBLOCK) %m");
		exit(1);
	}
	(*addremove_io_fd)(c->resp_read_pipe, c->ispipe, FALSE);
	pthread_attr_init(&thr_attr);
	pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
#if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \
    defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
	rc = pthread_attr_getstacksize(&thr_attr, &stacksize);
	if (-1 == rc) {
		msyslog(LOG_ERR,
			"start_blocking_thread: pthread_attr_getstacksize %m");
	} else if (stacksize < THREAD_MINSTACKSIZE) {
		rc = pthread_attr_setstacksize(&thr_attr,
					       THREAD_MINSTACKSIZE);
		if (-1 == rc)
			msyslog(LOG_ERR,
				"start_blocking_thread: pthread_attr_setstacksize(0x%lx -> 0x%lx) %m",
				(u_long)stacksize,
				(u_long)THREAD_MINSTACKSIZE);
	}
#else
	UNUSED_ARG(stacksize);
#endif
#if defined(PTHREAD_SCOPE_SYSTEM) && defined(NEED_PTHREAD_SCOPE_SYSTEM)
	pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
#endif
	c->thread_ref = emalloc_zero(sizeof(*c->thread_ref));
	block_thread_signals(&saved_sig_mask);
	rc = pthread_create(c->thread_ref, &thr_attr,
			    &blocking_thread, c);
	saved_errno = errno;
	pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
	pthread_attr_destroy(&thr_attr);
	if (0 != rc) {
		errno = saved_errno;
		msyslog(LOG_ERR, "pthread_create() blocking child: %m");
		exit(1);
	}
}
#endif


/*
 * block_thread_signals()
 *
 * Temporarily block signals used by ntpd main thread, so that signal
 * mask inherited by child threads leaves them blocked.  Returns prior
 * active signal mask via pmask, to be restored by the main thread
 * after pthread_create().
 */
#ifndef SYS_WINNT
void
block_thread_signals(
	sigset_t *	pmask
	)
{
	sigset_t	block;

	sigemptyset(&block);
# ifdef HAVE_SIGNALED_IO
#  ifdef SIGIO
	sigaddset(&block, SIGIO);
#  endif
#  ifdef SIGPOLL
	sigaddset(&block, SIGPOLL);
#  endif
# endif	/* HAVE_SIGNALED_IO */
	sigaddset(&block, SIGALRM);
	sigaddset(&block, MOREDEBUGSIG);
	sigaddset(&block, LESSDEBUGSIG);
# ifdef SIGDIE1
	sigaddset(&block, SIGDIE1);
# endif
# ifdef SIGDIE2
	sigaddset(&block, SIGDIE2);
# endif
# ifdef SIGDIE3
	sigaddset(&block, SIGDIE3);
# endif
# ifdef SIGDIE4
	sigaddset(&block, SIGDIE4);
# endif
# ifdef SIGBUS
	sigaddset(&block, SIGBUS);
# endif
	sigemptyset(pmask);
	pthread_sigmask(SIG_BLOCK, &block, pmask);
}
#endif	/* !SYS_WINNT */


/*
 * prepare_child_sems()
 *
 * create sync events (semaphores)
 * child_is_blocking initially unset
 * blocking_req_ready initially unset
 *
 * Child waits for blocking_req_ready to be set after
 * setting child_is_blocking.  blocking_req_ready and
 * blocking_response_ready are auto-reset, so wake one
 * waiter and become unset (unsignalled) in one operation.
 */
static void
prepare_child_sems(
	blocking_child *c
	)
#ifdef SYS_WINNT
{
	if (NULL == c->blocking_req_ready) {
		/* manual reset using ResetEvent() */
		/* !!!! c->child_is_blocking = CreateEvent(NULL, TRUE, FALSE, NULL); */
		/* auto reset - one thread released from wait each set */
		c->blocking_req_ready = CreateEvent(NULL, FALSE, FALSE, NULL);
		c->blocking_response_ready = CreateEvent(NULL, FALSE, FALSE, NULL);
		c->wake_scheduled_sleep = CreateEvent(NULL, FALSE, FALSE, NULL);
	} else {
		/* !!!! ResetEvent(c->child_is_blocking); */
		/* ResetEvent(c->blocking_req_ready); */
		/* ResetEvent(c->blocking_response_ready); */
		/* ResetEvent(c->wake_scheduled_sleep); */
	}
}
#else	/* pthreads prepare_child_sems() follows */
{
	size_t	octets;

	if (NULL == c->blocking_req_ready) {
		octets = sizeof(*c->blocking_req_ready);
		octets += sizeof(*c->wake_scheduled_sleep);
		/* !!!! octets += sizeof(*c->child_is_blocking); */
		c->blocking_req_ready = emalloc_zero(octets);;
		c->wake_scheduled_sleep = 1 + c->blocking_req_ready;
		/* !!!! c->child_is_blocking = 1 + c->wake_scheduled_sleep; */
	} else {
		sem_destroy(c->blocking_req_ready);
		sem_destroy(c->wake_scheduled_sleep);
		/* !!!! sem_destroy(c->child_is_blocking); */
	}
	sem_init(c->blocking_req_ready, FALSE, 0);
	sem_init(c->wake_scheduled_sleep, FALSE, 0);
	/* !!!! sem_init(c->child_is_blocking, FALSE, 0); */
}
#endif


static int
wait_for_sem(
	sem_ref			sem,
	struct timespec *	timeout		/* wall-clock */
	)
#ifdef SYS_WINNT
{
	struct timespec now;
	struct timespec delta;
	DWORD		msec;
	DWORD		rc;

	if (NULL == timeout) {
		msec = INFINITE;
	} else {
		getclock(TIMEOFDAY, &now);
		delta = sub_tspec(*timeout, now);
		if (delta.tv_sec < 0) {
			msec = 0;
		} else if ((delta.tv_sec + 1) >= (MAXDWORD / 1000)) {
			msec = INFINITE;
		} else {
			msec = 1000 * (DWORD)delta.tv_sec;
			msec += delta.tv_nsec / (1000 * 1000);
		}
	}
	rc = WaitForSingleObject(sem, msec);
	if (WAIT_OBJECT_0 == rc)
		return 0;
	if (WAIT_TIMEOUT == rc) {
		errno = ETIMEDOUT;
		return -1;
	}
	msyslog(LOG_ERR, "WaitForSingleObject unexpected 0x%x", rc);
	errno = EFAULT;
	return -1;
}
#else	/* pthreads wait_for_sem() follows */
{
	int rc;

	if (NULL == timeout)
		rc = sem_wait(sem);
	else
		rc = sem_timedwait(sem, timeout);

	return rc;
}
#endif


/*
 * blocking_thread - thread functions have WINAPI calling convention
 */
#ifdef SYS_WINNT
u_int
WINAPI
#else
void *
#endif
blocking_thread(
	void *	ThreadArg
	)
{
	blocking_child *c;

	c = ThreadArg;
	exit_worker(blocking_child_common(c));

	/* NOTREACHED */
	return 0;
}


/*
 * req_child_exit() runs in the parent.
 */
int
req_child_exit(
	blocking_child *c
	)
{
	return queue_req_pointer(c, CHILD_EXIT_REQ);
}


/*
 * cleanup_after_child() runs in parent.
 */
static void
cleanup_after_child(
	blocking_child *	c
	)
{
	u_int	idx;

	DEBUG_INSIST(!c->reusable);
#ifdef SYS_WINNT
	INSIST(CloseHandle(c->thread_ref));
#else
	free(c->thread_ref);
#endif
	c->thread_ref = NULL;
	c->thread_id = 0;
#ifdef WORK_PIPE
	DEBUG_INSIST(-1 != c->resp_read_pipe);
	DEBUG_INSIST(-1 != c->resp_write_pipe);
	(*addremove_io_fd)(c->resp_read_pipe, c->ispipe, TRUE);
	close(c->resp_write_pipe);
	close(c->resp_read_pipe);
	c->resp_write_pipe = -1;
	c->resp_read_pipe = -1;
#else
	DEBUG_INSIST(NULL != c->blocking_response_ready);
	(*addremove_io_semaphore)(c->blocking_response_ready, TRUE);
#endif
	for (idx = 0; idx < c->workitems_alloc; idx++)
		c->workitems[idx] = NULL;
	c->next_workitem = 0;
	c->next_workeritem = 0;
	for (idx = 0; idx < c->responses_alloc; idx++)
		c->responses[idx] = NULL;
	c->next_response = 0;
	c->next_workresp = 0;
	c->reusable = TRUE;
}


#else	/* !WORK_THREAD follows */
char work_thread_nonempty_compilation_unit;
#endif
OpenPOWER on IntegriCloud