📄 t_tasks.c
字号:
t2(void) { t_assert("tasks", 2, T_REQUIRED, a2); if (threaded) t_result(t_tasks2()); else require_threads();}#define T3_NEVENTS 256static int T3_flag;static int T3_nevents;static int T3_nsdevents;static isc_mutex_t T3_mx;static isc_condition_t T3_cv;static int T3_nfails;static int T3_nprobs;static voidt3_sde1(isc_task_t *task, isc_event_t *event) { task = task; if (T3_nevents != T3_NEVENTS) { t_info("Some events were not processed\n"); ++T3_nprobs; } if (T3_nsdevents == 1) { ++T3_nsdevents; } else { t_info("Shutdown events not processed in LIFO order\n"); ++T3_nfails; } isc_event_free(&event);}static voidt3_sde2(isc_task_t *task, isc_event_t *event) { task = task; if (T3_nevents != T3_NEVENTS) { t_info("Some events were not processed\n"); ++T3_nprobs; } if (T3_nsdevents == 0) { ++T3_nsdevents; } else { t_info("Shutdown events not processed in LIFO order\n"); ++T3_nfails; } isc_event_free(&event);}static voidt3_event1(isc_task_t *task, isc_event_t *event) { isc_result_t isc_result; task = task; isc_result = isc_mutex_lock(&T3_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_lock failed %s\n", isc_result_totext(isc_result)); ++T3_nprobs; } while (T3_flag != 1) { (void) isc_condition_wait(&T3_cv, &T3_mx); } isc_result = isc_mutex_unlock(&T3_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_unlock failed %s\n", isc_result_totext(isc_result)); ++T3_nprobs; } isc_event_free(&event);}static voidt3_event2(isc_task_t *task, isc_event_t *event) { task = task; ++T3_nevents; isc_event_free(&event);}static intt_tasks3(void) { int cnt; int result; char *p; isc_mem_t *mctx; isc_taskmgr_t *tmgr; isc_task_t *task; unsigned int workers; isc_event_t *event; isc_result_t isc_result; isc_eventtype_t event_type; T3_flag = 0; T3_nevents = 0; T3_nsdevents = 0; T3_nfails = 0; T3_nprobs = 0; event_type = 3; 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)); return(T_UNRESOLVED); } isc_result = isc_mutex_init(&T3_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_init failed %s\n", isc_result_totext(isc_result)); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_result = isc_condition_init(&T3_cv); if (isc_result != ISC_R_SUCCESS) { t_info("isc_condition_init failed %s\n", isc_result_totext(isc_result)); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } 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); return(T_UNRESOLVED); } isc_result = isc_mutex_lock(&T3_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_lock failed %s\n", isc_result_totext(isc_result)); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } 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_mutex_unlock(&T3_mx); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } /* * This event causes the task to wait on T3_cv. */ event = isc_event_allocate(mctx, &senders[1], event_type, t3_event1, NULL, sizeof(*event)); isc_task_send(task, &event); /* * Now we fill up the task's event queue with some events. */ for (cnt = 0; cnt < T3_NEVENTS; ++cnt) { event = isc_event_allocate(mctx, &senders[1], event_type, t3_event2, NULL, sizeof(*event)); isc_task_send(task, &event); } /* * Now we register two shutdown events. */ isc_result = isc_task_onshutdown(task, t3_sde1, NULL); if (isc_result != ISC_R_SUCCESS) { t_info("isc_task_send failed %s\n", isc_result_totext(isc_result)); isc_mutex_unlock(&T3_mx); isc_task_destroy(&task); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_result = isc_task_onshutdown(task, t3_sde2, NULL); if (isc_result != ISC_R_SUCCESS) { t_info("isc_task_send failed %s\n", isc_result_totext(isc_result)); isc_mutex_unlock(&T3_mx); isc_task_destroy(&task); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_task_shutdown(task); /* * Now we free the task by signaling T3_cv. */ T3_flag = 1; isc_result = isc_condition_signal(&T3_cv); if (isc_result != ISC_R_SUCCESS) { t_info("isc_task_send failed %s\n", isc_result_totext(isc_result)); ++T3_nprobs; } isc_result = isc_mutex_unlock(&T3_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_task_send failed %s\n", isc_result_totext(isc_result)); ++T3_nprobs; } isc_task_detach(&task); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); if (T3_nsdevents != 2) { t_info("T3_nsdevents == %d, expected 2\n", T3_nsdevents); ++T3_nfails; } if (T3_nevents != T3_nevents) { t_info("T3_nevents == %d, expected 2\n", T3_nevents); ++T3_nfails; } result = T_UNRESOLVED; if (T3_nfails != 0) result = T_FAIL; else if ((T3_nfails == 0) && (T3_nprobs == 0)) result = T_PASS; return(result);}static const char *a3 = "When isc_task_shutdown() is called, any shutdown " "events that have been requested via prior " "isc_task_onshutdown() calls are posted in " "LIFO order.";static voidt3(void) { t_assert("tasks", 3, T_REQUIRED, a3); if (threaded) t_result(t_tasks3()); else require_threads();}static isc_mutex_t T4_mx;static isc_condition_t T4_cv;static int T4_flag;static int T4_nprobs;static int T4_nfails;static voidt4_event1(isc_task_t *task, isc_event_t *event) { isc_result_t isc_result; UNUSED(task); isc_result = isc_mutex_lock(&T4_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_lock failed %s\n", isc_result_totext(isc_result)); ++T4_nprobs; } while (T4_flag != 1) { (void) isc_condition_wait(&T4_cv, &T4_mx); } isc_result = isc_mutex_unlock(&T4_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_unlock failed %s\n", isc_result_totext(isc_result)); ++T4_nprobs; } isc_event_free(&event);}static voidt4_sde(isc_task_t *task, isc_event_t *event) { UNUSED(task); /* * No-op. */ isc_event_free(&event);}static intt_tasks4(void) { int result; char *p; isc_mem_t *mctx; isc_taskmgr_t *tmgr; isc_task_t *task; unsigned int workers; isc_result_t isc_result; isc_eventtype_t event_type; isc_event_t *event; T4_nprobs = 0; T4_nfails = 0; T4_flag = 0; result = T_UNRESOLVED; event_type = 4; 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)); return(T_UNRESOLVED); } isc_result = isc_mutex_init(&T4_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_init failed %s\n", isc_result_totext(isc_result)); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_result = isc_condition_init(&T4_cv); if (isc_result != ISC_R_SUCCESS) { t_info("isc_condition_init failed %s\n", isc_result_totext(isc_result)); DESTROYLOCK(&T4_mx); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } 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)); DESTROYLOCK(&T4_mx); isc_condition_destroy(&T4_cv); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_result = isc_mutex_lock(&T4_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_lock failed %s\n", isc_result_totext(isc_result)); DESTROYLOCK(&T4_mx); isc_condition_destroy(&T4_cv); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } 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(&T4_mx); isc_condition_destroy(&T4_cv); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } /* * This event causes the task to wait on T4_cv. */ event = isc_event_allocate(mctx, &senders[1], event_type, t4_event1, NULL, sizeof(*event)); isc_task_send(task, &event); isc_task_shutdown(task); isc_result = isc_task_onshutdown(task, t4_sde, NULL); if (isc_result != ISC_R_SHUTTINGDOWN) { t_info("isc_task_onshutdown returned %s\n", isc_result_totext(isc_result)); ++T4_nfails; } /* * Release the task. */ T4_flag = 1; isc_result = isc_condition_signal(&T4_cv); if (isc_result != ISC_R_SUCCESS) { t_info("isc_condition_signal failed %s\n", isc_result_totext(isc_result)); ++T4_nprobs; } isc_result = isc_mutex_unlock(&T4_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_unlock failed %s\n", isc_result_totext(isc_result)); ++T4_nprobs; } isc_task_detach(&task); isc_taskmgr_destroy(&tmgr); isc_mem_destroy(&mctx); isc_condition_destroy(&T4_cv); DESTROYLOCK(&T4_mx); result = T_UNRESOLVED; if (T4_nfails != 0) result = T_FAIL; else if ((T4_nfails == 0) && (T4_nprobs == 0)) result = T_PASS; return(result);}static const char *a4 = "After isc_task_shutdown() has been called, any call to " "isc_task_onshutdown() will return ISC_R_SHUTTINGDOWN.";static voidt4(void) { t_assert("tasks", 4, T_REQUIRED, a4); if (threaded) t_result(t_tasks4()); else require_threads();}static int T7_nprobs;static int T7_eflag;static int T7_sdflag;static isc_mutex_t T7_mx;static isc_condition_t T7_cv;static int T7_nfails;static voidt7_event1(isc_task_t *task, isc_event_t *event) { UNUSED(task); ++T7_eflag; isc_event_free(&event);}static voidt7_sde(isc_task_t *task, isc_event_t *event) { isc_result_t isc_result; UNUSED(task); isc_result = isc_mutex_lock(&T7_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_lock failed %s\n", isc_result_totext(isc_result)); ++T7_nprobs; } ++T7_sdflag; isc_result = isc_condition_signal(&T7_cv); if (isc_result != ISC_R_SUCCESS) { t_info("isc_condition_signal failed %s\n", isc_result_totext(isc_result)); ++T7_nprobs; } 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_event_free(&event);}static intt_tasks7(void) { int result; char *p; isc_mem_t *mctx; isc_taskmgr_t *tmgr; isc_task_t *task; unsigned int workers; isc_result_t isc_result; isc_eventtype_t event_type; isc_event_t *event; isc_time_t now; isc_interval_t interval; T7_nprobs = 0; T7_nfails = 0; T7_sdflag = 0; T7_eflag = 0; result = T_UNRESOLVED; event_type = 7; 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)); return(T_UNRESOLVED); } isc_result = isc_mutex_init(&T7_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_init failed %s\n", isc_result_totext(isc_result)); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_result = isc_condition_init(&T7_cv); if (isc_result != ISC_R_SUCCESS) { t_info("isc_condition_init failed %s\n", isc_result_totext(isc_result)); DESTROYLOCK(&T7_mx); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } 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)); DESTROYLOCK(&T7_mx); isc_condition_destroy(&T7_cv); isc_mem_destroy(&mctx); return(T_UNRESOLVED); } isc_result = isc_mutex_lock(&T7_mx); if (isc_result != ISC_R_SUCCESS) { t_info("isc_mutex_lock failed %s\n",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -