⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_tasks.c

📁 package of develop dns
💻 C
📖 第 1 页 / 共 4 页
字号:
		       isc_result_totext(isc_result));		DESTROYLOCK(&T7_mx);		isc_condition_destroy(&T7_cv);		isc_taskmgr_destroy(&tmgr);		isc_mem_destroy(&mctx);		return(T_FAIL);	}	task = NULL;	isc_result = isc_task_create(tmgr, 0, &task);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_task_create failed %s\n",		       isc_result_totext(isc_result));		DESTROYLOCK(&T7_mx);		isc_condition_destroy(&T7_cv);		isc_taskmgr_destroy(&tmgr);		isc_mem_destroy(&mctx);		return(T_FAIL);	}	isc_result = isc_task_onshutdown(task, t7_sde, NULL);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_task_onshutdown returned %s\n",		       isc_result_totext(isc_result));		DESTROYLOCK(&T7_mx);		isc_condition_destroy(&T7_cv);		isc_task_destroy(&task);		isc_taskmgr_destroy(&tmgr);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	event = isc_event_allocate(mctx, &senders[1], event_type, t7_event1,				   NULL, sizeof(*event));	isc_task_send(task, &event);	isc_task_shutdown(task);	interval.seconds = 5;	interval.nanoseconds = 0;	while (T7_sdflag == 0) {		isc_result = isc_time_nowplusinterval(&now, &interval);		if (isc_result != ISC_R_SUCCESS) {			t_info("isc_time_nowplusinterval failed %s\n",			       isc_result_totext(isc_result));			DESTROYLOCK(&T7_mx);			isc_condition_destroy(&T7_cv);			isc_task_destroy(&task);			isc_taskmgr_destroy(&tmgr);			isc_mem_destroy(&mctx);			return(T_UNRESOLVED);		}		isc_result = isc_condition_waituntil(&T7_cv, &T7_mx, &now);		if (isc_result != ISC_R_SUCCESS) {			t_info("isc_condition_waituntil returned %s\n",			       isc_result_totext(isc_result));			DESTROYLOCK(&T7_mx);			isc_condition_destroy(&T7_cv);			isc_task_destroy(&task);			isc_taskmgr_destroy(&tmgr);			isc_mem_destroy(&mctx);			return(T_FAIL);		}	}	isc_result = isc_mutex_unlock(&T7_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_unlock failed %s\n",		       isc_result_totext(isc_result));		++T7_nprobs;	}	isc_task_detach(&task);	isc_taskmgr_destroy(&tmgr);	isc_mem_destroy(&mctx);	isc_condition_destroy(&T7_cv);	DESTROYLOCK(&T7_mx);	result = T_UNRESOLVED;	if (T7_eflag == 0)		++T7_nfails;	if (T7_nfails != 0)		result = T_FAIL;	else if ((T7_nfails == 0) && (T7_nprobs == 0))		result = T_PASS;	return(result);}static const char *a7 =	"A call to isc_task_create() creates a task that can "			"receive events.";static voidt7(void) {	t_assert("tasks", 7, T_REQUIRED, a7);	if (threaded)		t_result(t_tasks7());	else		require_threads();}#define	T10_SENDERCNT	3#define	T10_TYPECNT	4#define	T10_TAGCNT	5#define	T10_NEVENTS	(T10_SENDERCNT*T10_TYPECNT*T10_TAGCNT)#define	T_CONTROL	99999static int		T10_nprobs;static int		T10_nfails;static int		T10_startflag;static int		T10_shutdownflag;static int		T10_eventcnt;static isc_mutex_t	T10_mx;static isc_condition_t	T10_cv;static void		*T10_purge_sender;static isc_eventtype_t	T10_purge_type_first;static isc_eventtype_t	T10_purge_type_last;static void		*T10_purge_tag;static int		T10_testrange;static voidt10_event1(isc_task_t *task, isc_event_t *event) {	isc_result_t	isc_result;	task = task;	isc_result = isc_mutex_lock(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_lock failed %s\n",		       isc_result_totext(isc_result));		++T10_nprobs;	}	while (T10_startflag == 0) {		isc_result = isc_condition_wait(&T10_cv, &T10_mx);		if (isc_result != ISC_R_SUCCESS) {			t_info("isc_mutex_lock failed %s\n",			       isc_result_totext(isc_result));			++T10_nprobs;		}	}	isc_result = isc_mutex_unlock(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_unlock failed %s\n",		       isc_result_totext(isc_result));		++T10_nprobs;	}	isc_event_free(&event);}static voidt10_event2(isc_task_t *task, isc_event_t *event) {	int	sender_match;	int	type_match;	int	tag_match;	task = task;	sender_match = 0;	type_match = 0;	tag_match = 0;	if (T_debug) {		t_info("Event %p,%d,%p,%s\n",		       event->ev_sender,		       (int)event->ev_type,		       event->ev_tag,		       event->ev_attributes & ISC_EVENTATTR_NOPURGE ?		       "NP" : "P");	}	if ((T10_purge_sender == NULL) ||	    (T10_purge_sender == event->ev_sender)) {		sender_match = 1;	}	if (T10_testrange == 0) {		if (T10_purge_type_first == event->ev_type) {			type_match = 1;		}	} else {		if ((T10_purge_type_first <= event->ev_type) &&		    (event->ev_type <= T10_purge_type_last)) {			type_match = 1;		}	}	if ((T10_purge_tag == NULL) ||	    (T10_purge_tag == event->ev_tag)) {		tag_match = 1;	}	if (sender_match && type_match && tag_match) {		if (event->ev_attributes & ISC_EVENTATTR_NOPURGE) {			t_info("event %p,%d,%p matched but was not purgable\n",				event->ev_sender, (int)event->ev_type,			       event->ev_tag);			++T10_eventcnt;		} else {			t_info("*** event %p,%d,%p not purged\n",			       event->ev_sender, (int)event->ev_type,			       event->ev_tag);		}	} else {		++T10_eventcnt;	}	isc_event_free(&event);}static voidt10_sde(isc_task_t *task, isc_event_t *event) {	isc_result_t	isc_result;	task = task;	isc_result = isc_mutex_lock(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_lock failed %s\n",		       isc_result_totext(isc_result));		++T10_nprobs;	}	++T10_shutdownflag;	isc_result = isc_condition_signal(&T10_cv);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_condition_signal failed %s\n",		       isc_result_totext(isc_result));		++T10_nprobs;	}	isc_result = isc_mutex_unlock(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_unlock failed %s\n",		       isc_result_totext(isc_result));		++T10_nprobs;	}	isc_event_free(&event);}static voidt_taskpurge_x(int sender, int type, int tag, void *purge_sender,	      int purge_type_first, int purge_type_last, void *purge_tag,	      int exp_nevents, int *nfails, int *nprobs, int testrange){	char		*p;	isc_mem_t	*mctx;	isc_taskmgr_t	*tmgr;	isc_task_t	*task;	unsigned int	workers;	isc_result_t	isc_result;	isc_event_t	*event;	isc_time_t	now;	isc_interval_t	interval;	int		sender_cnt;	int		type_cnt;	int		tag_cnt;	int		event_cnt;	int		cnt;	int		nevents;	isc_event_t	*eventtab[T10_NEVENTS];	T10_startflag = 0;	T10_shutdownflag = 0;	T10_eventcnt = 0;	T10_purge_sender = purge_sender;	T10_purge_type_first = (isc_eventtype_t) purge_type_first;	T10_purge_type_last = (isc_eventtype_t) purge_type_last;	T10_purge_tag = purge_tag;	T10_testrange = testrange;	workers = 2;	p = t_getenv("ISC_TASK_WORKERS");	if (p != NULL)		workers = atoi(p);	mctx = NULL;	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed %s\n",		       isc_result_totext(isc_result));		++*nprobs;		return;	}	isc_result = isc_mutex_init(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_init failed %s\n",		       isc_result_totext(isc_result));		isc_mem_destroy(&mctx);		++*nprobs;		return;	}	isc_result = isc_condition_init(&T10_cv);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_condition_init failed %s\n",		       isc_result_totext(isc_result));		isc_mem_destroy(&mctx);		DESTROYLOCK(&T10_mx);		++*nprobs;		return;	}	tmgr = NULL;	isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_taskmgr_create failed %s\n",		       isc_result_totext(isc_result));		isc_mem_destroy(&mctx);		DESTROYLOCK(&T10_mx);		isc_condition_destroy(&T10_cv);		++*nprobs;		return;	}	task = NULL;	isc_result = isc_task_create(tmgr, 0, &task);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_task_create failed %s\n",		       isc_result_totext(isc_result));		isc_taskmgr_destroy(&tmgr);		isc_mem_destroy(&mctx);		DESTROYLOCK(&T10_mx);		isc_condition_destroy(&T10_cv);		++*nprobs;		return;	}	isc_result = isc_task_onshutdown(task, t10_sde, NULL);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_task_onshutdown returned %s\n",		       isc_result_totext(isc_result));		isc_task_destroy(&task);		isc_taskmgr_destroy(&tmgr);		isc_mem_destroy(&mctx);		DESTROYLOCK(&T10_mx);		isc_condition_destroy(&T10_cv);		++*nprobs;		return;	}	/*	 * Block the task on T10_cv.	 */	event = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)T_CONTROL,				   t10_event1, NULL, sizeof(*event));	isc_task_send(task, &event);	/*	 * Fill the task's queue with some messages with varying	 * sender, type, tag, and purgable attribute values.	 */	event_cnt = 0;	for (sender_cnt = 0; sender_cnt < T10_SENDERCNT; ++sender_cnt) {		for (type_cnt = 0; type_cnt < T10_TYPECNT; ++type_cnt) {			for (tag_cnt = 0; tag_cnt < T10_TAGCNT; ++tag_cnt) {				eventtab[event_cnt] =					isc_event_allocate(mctx,					    &senders[sender + sender_cnt],					    (isc_eventtype_t)(type + type_cnt),					    t10_event2, NULL, sizeof(*event));				eventtab[event_cnt]->ev_tag =					(void *)((int)tag + tag_cnt);				/*				 * Make all odd message non-purgable.				 */				if ((sender_cnt % 2) && (type_cnt %2) &&				    (tag_cnt %2))					eventtab[event_cnt]->ev_attributes |=						ISC_EVENTATTR_NOPURGE;				++event_cnt;			}		}	}	for (cnt = 0; cnt < event_cnt; ++cnt)		isc_task_send(task, &eventtab[cnt]);	if (T_debug)		t_info("%d events queued\n", cnt);	if (testrange == 0) {		/*		 * We're testing isc_task_purge.		 */		nevents = isc_task_purge(task, purge_sender,					(isc_eventtype_t)purge_type_first,					purge_tag);		if (nevents != exp_nevents) {			t_info("*** isc_task_purge returned %d, expected %d\n",				nevents, exp_nevents);			++*nfails;		} else if (T_debug)			t_info("isc_task_purge returned %d\n", nevents);	} else {		/*		 * We're testing isc_task_purgerange.		 */		nevents = isc_task_purgerange(task, purge_sender,					     (isc_eventtype_t)purge_type_first,					     (isc_eventtype_t)purge_type_last,					     purge_tag);		if (nevents != exp_nevents) {			t_info("*** isc_task_purgerange returned %d, "			       "expected %d\n", nevents, exp_nevents);			++*nfails;		} else if (T_debug)			t_info("isc_task_purgerange returned %d\n", nevents);	}	isc_result = isc_mutex_lock(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_lock failed %s\n",		       isc_result_totext(isc_result));		isc_task_destroy(&task);		isc_taskmgr_destroy(&tmgr);		isc_mem_destroy(&mctx);		DESTROYLOCK(&T10_mx);		isc_condition_destroy(&T10_cv);		++*nprobs;		return;	}	/*	 * Unblock the task, allowing event processing.	 */	T10_startflag = 1;	isc_result = isc_condition_signal(&T10_cv);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_condition_signal failed %s\n",		       isc_result_totext(isc_result));		++*nprobs;	}	isc_task_shutdown(task);	interval.seconds = 5;	interval.nanoseconds = 0;	/*	 * Wait for shutdown processing to complete.	 */	while (T10_shutdownflag == 0) {		isc_result = isc_time_nowplusinterval(&now, &interval);		if (isc_result != ISC_R_SUCCESS) {			t_info("isc_time_nowplusinterval failed %s\n",			       isc_result_totext(isc_result));			isc_task_detach(&task);			isc_taskmgr_destroy(&tmgr);			isc_mem_destroy(&mctx);			DESTROYLOCK(&T10_mx);			isc_condition_destroy(&T10_cv);			++*nprobs;			return;		}		isc_result = isc_condition_waituntil(&T10_cv, &T10_mx, &now);		if (isc_result != ISC_R_SUCCESS) {			t_info("isc_condition_waituntil returned %s\n",			       isc_result_totext(isc_result));			isc_task_detach(&task);			isc_taskmgr_destroy(&tmgr);			isc_mem_destroy(&mctx);			DESTROYLOCK(&T10_mx);			isc_condition_destroy(&T10_cv);			++*nfails;			return;		}	}	isc_result = isc_mutex_unlock(&T10_mx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mutex_unlock failed %s\n",		       isc_result_totext(isc_result));		++*nprobs;	}	isc_task_detach(&task);	isc_taskmgr_destroy(&tmgr);	isc_mem_destroy(&mctx);	DESTROYLOCK(&T10_mx);	isc_condition_destroy(&T10_cv);	if (T_debug)		t_info("task processed %d events\n", T10_eventcnt);	if ((T10_eventcnt + nevents) != event_cnt) {		t_info("*** processed %d, purged %d, total %d\n",		       T10_eventcnt, nevents, event_cnt);		++*nfails;	}}static intt_tasks10(void) {	int	result;	T10_nprobs = 0;	T10_nfails = 0;	/*	 * Try purging on a specific sender.	 */	t_info("testing purge on 2,4,8 expecting 1\n");	t_taskpurge_x(1, 4, 7, &senders[2], 4, 4, (void *)8, 1, &T10_nfails,		      &T10_nprobs, 0);	/*	 * Try purging on all senders.	 */	t_info("testing purge on 0,4,8 expecting 3\n");	t_taskpurge_x(1, 4, 7, NULL, 4, 4, (void *)8, 3, &T10_nfails,		      &T10_nprobs, 0);	/*	 * Try purging on all senders, specified type, all tags.	 */	t_info("testing purge on 0,4,0 expecting 15\n");	t_taskpurge_x(1, 4, 7, NULL, 4, 4, NULL, 15, &T10_nfails,		      &T10_nprobs, 0);	/*	 * Try purging on a specified tag, no such type.	 */	t_info("testing purge on 0,99,8 expecting 0\n");	t_taskpurge_x(1, 4, 7, NULL, 99, 99, (void *)8, 0, &T10_nfails,		      &T10_nprobs, 0);	/*	 * Try purging on specified sender, type, all tags.	 */	t_info("testing purge on 0,5,0 expecting 5\n");	t_taskpurge_x(1, 4, 7, &senders[3], 5, 5, NULL, 5, &T10_nfails,		      &T10_nprobs, 0);	result = T_UNRESOLVED;	if ((T10_nfails == 0) && (T10_nprobs == 0))		result = T_PASS;	else if (T10_nfails != 0)		result = T_FAIL;	return(result);}static const char *a10 =			"A call to isc_task_purge(task, sender, type, tag) "			"purges all events of type 'type' and with tag 'tag' "			"not marked as unpurgable from sender from the task's "			"queue and returns the number of events purged.";static voidt10(void) {	t_assert("tasks", 10, T_REQUIRED, a10);	if (threaded)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -