99e207809793732e3e47da3a1cab6925b6eee8e9William King/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1998-2001, 2004, 2005, 2007, 2009, 2011, 2013-2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews/* $Id: t_tasks.c,v 1.49 2011/07/27 07:45:55 marka Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <config.h>
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <stdlib.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <unistd.h>
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#ifdef HAVE_INTTYPES_H
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#include <inttypes.h> /* uintptr_t */
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews#endif
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/condition.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/mem.h>
b9e8ad0f49b416afda1e752aa5c3910f8aa34fffAndreas Gustafsson#include <isc/platform.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/task.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/time.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/timer.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/util.h>
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <tests/t_api.h>
99e207809793732e3e47da3a1cab6925b6eee8e9William King
54a5ca24e1ba1f39f462c0b9052c9f4b29958c93Mark Andrews
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#ifdef ISC_PLATFORM_USETHREADS
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrenceisc_boolean_t threaded = ISC_TRUE;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrenceisc_boolean_t threaded = ISC_FALSE;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence#endif
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrewsstatic int senders[4];
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrencestatic void
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrencerequire_threads(void) {
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_info("This test requires threads\n");
1d8abe0521c8e084dfcdd821173c10e0b416aeb3Mark Andrews t_result(T_THREADONLY);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence return;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence}
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrencet1_callback(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King int i;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int j;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence UNUSED(task);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King j = 0;
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (i = 0; i < 1000000; i++)
99e207809793732e3e47da3a1cab6925b6eee8e9William King j += 100;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("task %s\n", (char *)event->ev_arg);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt1_shutdown(isc_task_t *task, isc_event_t *event) {
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("shutdown %s\n", (char *)event->ev_arg);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
c403d3f7d6cb17406e9be03a330ed5cf91619abcDavid Lawrencemy_tick(isc_task_t *task, isc_event_t *event) {
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence UNUSED(task);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("%s\n", (char *)event->ev_arg);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King/*
99e207809793732e3e47da3a1cab6925b6eee8e9William King * Adapted from RTH's original task_test program
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsstatic char one[] = "1";
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsstatic char two[] = "2";
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsstatic char three[] = "3";
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsstatic char four[] = "4";
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsstatic char tick[] = "tick";
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrewsstatic char tock[] = "tock";
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks1(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_t *manager;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task3;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task4;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_timermgr_t *timgr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_timer_t *ti1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_timer_t *ti2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_time_t absolute;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_interval_t interval;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King manager = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King task1 = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King task2 = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King task3 = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King task4 = NULL;
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence mctx = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (workers < 1) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Bad config value for ISC_TASK_WORKERS, %d\n", workers);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &manager);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task2);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task3);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(manager, 0, &task4);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task1, t1_shutdown, one);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task2, t1_shutdown, two);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task3, t1_shutdown, three);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews isc_result = isc_task_onshutdown(task4, t1_shutdown, four);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King timgr = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_timermgr_create(mctx, &timgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_timermgr_create %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ti1 = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_time_settoepoch(&absolute);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_interval_set(&interval, 1, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_timer_create(timgr, isc_timertype_ticker,
99e207809793732e3e47da3a1cab6925b6eee8e9William King &absolute, &interval,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews task1, my_tick, tick, &ti1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_timer_create %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ti2 = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_time_settoepoch(&absolute);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_interval_set(&interval, 1, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_timer_create(timgr, isc_timertype_ticker,
99e207809793732e3e47da3a1cab6925b6eee8e9William King &absolute, &interval,
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews task2, my_tick, tock, &ti2);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_timer_create %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#ifndef WIN32
99e207809793732e3e47da3a1cab6925b6eee8e9William King sleep(2);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#else
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews Sleep(2000);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#endif
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King /*
99e207809793732e3e47da3a1cab6925b6eee8e9William King * Note: (void *)1 is used as a sender here, since some compilers
99e207809793732e3e47da3a1cab6925b6eee8e9William King * don't like casting a function pointer to a (void *).
99e207809793732e3e47da3a1cab6925b6eee8e9William King *
99e207809793732e3e47da3a1cab6925b6eee8e9William King * In a real use, it is more likely the sender would be a
99e207809793732e3e47da3a1cab6925b6eee8e9William King * structure (socket, timer, task, etc) but this is just a test
99e207809793732e3e47da3a1cab6925b6eee8e9William King * program.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, one,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task1, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, two,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task2, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, three,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task3, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, four,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task4, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, two,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task2, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, three,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task3, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
44c6deacdd7cea39c267fabd3e35f8abdc1ce24cMark Andrews event = isc_event_allocate(mctx, (void *)1, 1, t1_callback, four,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task4, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson (void)isc_task_purge(task3, NULL, 0, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task2);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task3);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task4);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#ifndef WIN32
99e207809793732e3e47da3a1cab6925b6eee8e9William King sleep(10);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#else
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews Sleep(10000);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#endif
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_timer_detach(&ti1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_timer_detach(&ti2);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_timermgr_destroy(&timgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&manager);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_PASS);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a1 = "The task subsystem can create and manage tasks";
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet1(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King int result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 1, T_REQUIRED, "%s", a1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = t_tasks1();
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_result(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
e1bb80ea30482d37abf16cd9621045f873c57e74William King#define T2_NTASKS 10000
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_event_t *T2_event;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_taskmgr_t *T2_manager;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_mem_t *T2_mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_condition_t T2_cv;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_mutex_t T2_mx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T2_done;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T2_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T2_nfails;
93a16701383bbc91e6915d41d1ed827ce8b92246William Kingstatic int T2_ntasks;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt2_shutdown(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (event->ev_arg != NULL) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff isc_task_destroy((isc_task_t**) &event->ev_arg);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King else {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T2_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T2_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_done = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_signal(&T2_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T2_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T2_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T2_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&T2_event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&T2_manager);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&T2_mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencet2_callback(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *newtask;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
93a16701383bbc91e6915d41d1ed827ce8b92246William King ++T2_ntasks;
93a16701383bbc91e6915d41d1ed827ce8b92246William King
93a16701383bbc91e6915d41d1ed827ce8b92246William King if (T_debug && ((T2_ntasks % 100) == 0)) {
93a16701383bbc91e6915d41d1ed827ce8b92246William King t_info("T2_ntasks %d\n", T2_ntasks);
93a16701383bbc91e6915d41d1ed827ce8b92246William King }
93a16701383bbc91e6915d41d1ed827ce8b92246William King
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (event->ev_arg) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews event->ev_arg = (void *)(((uintptr_t) event->ev_arg) - 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Create a new task and forward the message.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King newtask = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(T2_manager, 0, &newtask);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T2_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(newtask, t2_shutdown,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (void *)task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown failed %d\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T2_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(newtask, &event);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Time to unwind, shutdown should perc back up.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt_tasks2(void) {
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews uintptr_t ntasks;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_manager = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_done = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_nprobs = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_nfails = 0;
93a16701383bbc91e6915d41d1ed827ce8b92246William King T2_ntasks = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (workers < 1) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Bad config value for ISC_TASK_WORKERS, %d\n", workers);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASKS_MIN");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King ntasks = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King else
99e207809793732e3e47da3a1cab6925b6eee8e9William King ntasks = T2_NTASKS;
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews if (ntasks == 0U) {
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews t_info("Bad config value for ISC_TASKS_MIN, %lu\n",
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews (unsigned long)ntasks);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews t_info("Testing with %lu tasks\n", (unsigned long)ntasks);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_init(&T2_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_init(&T2_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &T2_mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(T2_mctx, workers, 0, &T2_manager);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King T2_event = isc_event_allocate(T2_mctx, (void *)1, 1, t2_callback,
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson (void *)ntasks, sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T2_event == NULL) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_event_allocate failed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T2_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King t2_callback(NULL, T2_event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T2_done == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_wait(&T2_cv, &T2_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_wait failed %d\n", isc_result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((T2_nfails == 0) && (T2_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (T2_nfails != 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a2 = "The task subsystem can create ISC_TASKS_MIN tasks";
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet2(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 2, T_REQUIRED, "%s", a2);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks2());
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T3_NEVENTS 256
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T3_flag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T3_nevents;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T3_nsdevents;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_mutex_t T3_mx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_condition_t T3_cv;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T3_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3_sde1(isc_task_t *task, isc_event_t *event) {
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T3_nevents != T3_NEVENTS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Some events were not processed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T3_nsdevents == 1) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nsdevents;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Shutdown events not processed in LIFO order\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3_sde2(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T3_nevents != T3_NEVENTS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Some events were not processed\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T3_nsdevents == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nsdevents;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("Shutdown events not processed in LIFO order\n");
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T3_flag != 1) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King (void) isc_condition_wait(&T3_cv, &T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3_event2(isc_task_t *task, isc_event_t *event) {
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nevents;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks3(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King int cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_t *tmgr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_eventtype_t event_type;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King T3_flag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T3_nevents = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T3_nsdevents = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T3_nfails = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T3_nprobs = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King event_type = 3;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King mctx = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_init(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_init(&T3_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tmgr = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King task = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(tmgr, 0, &task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_mutex_unlock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * This event causes the task to wait on T3_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type, t3_event1,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews NULL, sizeof(*event));
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (void) isc_mutex_unlock(&T3_mx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_taskmgr_destroy(&tmgr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_mem_destroy(&mctx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews return(T_UNRESOLVED);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now we fill up the task's event queue with some events.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (cnt = 0; cnt < T3_NEVENTS; ++cnt) {
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type,
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley t3_event2, NULL, sizeof(*event));
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (void) isc_mutex_unlock(&T3_mx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_taskmgr_destroy(&tmgr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_mem_destroy(&mctx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews return(T_UNRESOLVED);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now we register two shutdown events.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t3_sde1, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_send failed %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_totext(isc_result));
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_mutex_unlock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t3_sde2, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_send failed %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_totext(isc_result));
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_mutex_unlock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_shutdown(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now we free the task by signaling T3_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King T3_flag = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_signal(&T3_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews t_info("isc_condition_signal failed %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T3_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
8bd2b6923c282eee7d957bda830e74a0e5285f8fMark Andrews t_info("isc_mutex_unlock failed %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T3_nsdevents != 2) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("T3_nsdevents == %d, expected 2\n", T3_nsdevents);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T3_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T3_nfails != 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if ((T3_nfails == 0) && (T3_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a3 = "When isc_task_shutdown() is called, any shutdown "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "events that have been requested via prior "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "isc_task_onshutdown() calls are posted in "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "LIFO order.";
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt3(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 3, T_REQUIRED, "%s", a3);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks3());
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_mutex_t T4_mx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_condition_t T4_cv;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T4_flag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T4_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T4_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt4_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T4_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T4_flag != 1) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King (void) isc_condition_wait(&T4_cv, &T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T4_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt4_sde(isc_task_t *task, isc_event_t *event) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * No-op.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks4(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King int result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_t *tmgr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_eventtype_t event_type;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T4_nprobs = 0;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T4_nfails = 0;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T4_flag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley event_type = 4;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King mctx = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_init(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_condition_init(&T4_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tmgr = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T4_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T4_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_lock(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T4_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T4_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King task = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(tmgr, 0, &task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
b704d25ff33569a412f1a5a459dafabee326fa8fMark Andrews isc_result = isc_mutex_unlock(&T4_mx);
b704d25ff33569a412f1a5a459dafabee326fa8fMark Andrews if (isc_result != ISC_R_SUCCESS) {
b704d25ff33569a412f1a5a459dafabee326fa8fMark Andrews t_info("isc_mutex_unlock failed %s\n",
b704d25ff33569a412f1a5a459dafabee326fa8fMark Andrews isc_result_totext(isc_result));
b704d25ff33569a412f1a5a459dafabee326fa8fMark Andrews ++T4_nprobs;
b704d25ff33569a412f1a5a459dafabee326fa8fMark Andrews }
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T4_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T4_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * This event causes the task to wait on T4_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type, t4_event1,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews NULL, sizeof(*event));
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
e53e202ef3b51c58fb9abe0d15e3829a970b00e7Mark Andrews isc_result = isc_mutex_unlock(&T4_mx);
e53e202ef3b51c58fb9abe0d15e3829a970b00e7Mark Andrews if (isc_result != ISC_R_SUCCESS) {
e53e202ef3b51c58fb9abe0d15e3829a970b00e7Mark Andrews t_info("isc_mutex_unlock failed %s\n",
e53e202ef3b51c58fb9abe0d15e3829a970b00e7Mark Andrews isc_result_totext(isc_result));
e53e202ef3b51c58fb9abe0d15e3829a970b00e7Mark Andrews ++T4_nprobs;
e53e202ef3b51c58fb9abe0d15e3829a970b00e7Mark Andrews }
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews DESTROYLOCK(&T4_mx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (void) isc_condition_destroy(&T4_cv);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_taskmgr_destroy(&tmgr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_mem_destroy(&mctx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews return(T_UNRESOLVED);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_shutdown(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_task_onshutdown(task, t4_sde, NULL);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley if (isc_result != ISC_R_SHUTTINGDOWN) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T4_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Release the task.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T4_flag = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_condition_signal(&T4_cv);
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley if (isc_result != ISC_R_SUCCESS) {
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley t_info("isc_condition_signal failed %s\n",
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T4_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_unlock(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T4_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T4_cv);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T4_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley if (T4_nfails != 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley else if ((T4_nfails == 0) && (T4_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a4 =
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "After isc_task_shutdown() has been called, any call to "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "isc_task_onshutdown() will return ISC_R_SHUTTINGDOWN.";
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet4(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 4, T_REQUIRED, "%s", a4);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks4());
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleystatic int T7_nprobs;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleystatic int T7_eflag;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleystatic int T7_sdflag;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleystatic isc_mutex_t T7_mx;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleystatic isc_condition_t T7_cv;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrencestatic int T7_nfails;
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleyt7_event1(isc_task_t *task, isc_event_t *event) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_eflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleyt7_sde(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_lock(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_sdflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_condition_signal(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_unlock(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks7(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King int result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_t *tmgr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_eventtype_t event_type;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_time_t now;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_interval_t interval;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T7_nprobs = 0;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T7_nfails = 0;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T7_sdflag = 0;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley T7_eflag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley event_type = 7;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King mctx = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_init(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_condition_init(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tmgr = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_lock(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King task = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(tmgr, 0, &task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_task_onshutdown(task, t7_sde, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews event = isc_event_allocate(mctx, &senders[1], event_type, t7_event1,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews NULL, sizeof(*event));
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews DESTROYLOCK(&T7_mx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (void) isc_condition_destroy(&T7_cv);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_taskmgr_destroy(&tmgr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_mem_destroy(&mctx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews return(T_UNRESOLVED);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_shutdown(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_interval_set(&interval, 5, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley while (T7_sdflag == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_time_nowplusinterval(&now, &interval);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_time_nowplusinterval failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_condition_waituntil(&T7_cv, &T7_mx, &now);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_waituntil returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_FAIL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_result = isc_mutex_unlock(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T7_cv);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T7_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley if (T7_eflag == 0)
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley ++T7_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley if (T7_nfails != 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley else if ((T7_nfails == 0) && (T7_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a7 = "A call to isc_task_create() creates a task that can "
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley "receive events.";
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halleyt7(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 7, T_REQUIRED, "%s", a7);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks7());
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T10_SENDERCNT 3
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T10_TYPECNT 4
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T10_TAGCNT 5
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T10_NEVENTS (T10_SENDERCNT*T10_TYPECNT*T10_TAGCNT)
99e207809793732e3e47da3a1cab6925b6eee8e9William King#define T_CONTROL 99999
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T10_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T10_startflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T10_shutdownflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T10_eventcnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_mutex_t T10_mx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_condition_t T10_cv;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void *T10_purge_sender;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_eventtype_t T10_purge_type_first;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_eventtype_t T10_purge_type_last;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void *T10_purge_tag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T10_testrange;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt10_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T10_startflag == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_wait(&T10_cv, &T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt10_event2(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King int sender_match;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int type_match;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int tag_match;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King sender_match = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King type_match = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King tag_match = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T_debug) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("Event %p,%d,%p,%s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_sender,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (int)event->ev_type,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_tag,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_attributes & ISC_EVENTATTR_NOPURGE ?
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson "NP" : "P");
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews if ((T10_purge_sender == NULL) ||
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff (T10_purge_sender == event->ev_sender)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King sender_match = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T10_testrange == 0) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (T10_purge_type_first == event->ev_type) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King type_match = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if ((T10_purge_type_first <= event->ev_type) &&
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff (event->ev_type <= T10_purge_type_last)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King type_match = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((T10_purge_tag == NULL) ||
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff (T10_purge_tag == event->ev_tag)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King tag_match = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (sender_match && type_match && tag_match) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (event->ev_attributes & ISC_EVENTATTR_NOPURGE) {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("event %p,%d,%p matched but was not purgable\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_sender, (int)event->ev_type,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_tag);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_eventcnt;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson t_info("*** event %p,%d,%p not purged\n",
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson event->ev_sender, (int)event->ev_type,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event->ev_tag);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_eventcnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt10_sde(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_shutdownflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_signal(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T10_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrewst_taskpurge_x(int sender, int type, int tag, void *purge_sender,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence int purge_type_first, int purge_type_last, void *purge_tag,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence int exp_nevents, int *nfails, int *nprobs, int testrange)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence{
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_t *tmgr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_time_t now;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_interval_t interval;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int sender_cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int type_cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int tag_cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int event_cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int nevents;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *eventtab[T10_NEVENTS];
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_startflag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_shutdownflag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_eventcnt = 0;
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews T10_purge_sender = purge_sender;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_purge_type_first = (isc_eventtype_t) purge_type_first;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_purge_type_last = (isc_eventtype_t) purge_type_last;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_purge_tag = purge_tag;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_testrange = testrange;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King mctx = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_init(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_init(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tmgr = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King task = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(tmgr, 0, &task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t10_sde, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Block the task on T10_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)T_CONTROL,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t10_event1, NULL, sizeof(*event));
99e207809793732e3e47da3a1cab6925b6eee8e9William King
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_taskmgr_destroy(&tmgr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_mem_destroy(&mctx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews DESTROYLOCK(&T10_mx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (void) isc_condition_destroy(&T10_cv);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews ++*nprobs;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews return;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Fill the task's queue with some messages with varying
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * sender, type, tag, and purgable attribute values.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King event_cnt = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (sender_cnt = 0; sender_cnt < T10_SENDERCNT; ++sender_cnt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (type_cnt = 0; type_cnt < T10_TYPECNT; ++type_cnt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King for (tag_cnt = 0; tag_cnt < T10_TAGCNT; ++tag_cnt) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence eventtab[event_cnt] =
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_event_allocate(mctx,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews &senders[sender + sender_cnt],
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (isc_eventtype_t)(type + type_cnt),
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t10_event2, NULL, sizeof(*event));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (eventtab[event_cnt] == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_taskmgr_destroy(&tmgr);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_mem_destroy(&mctx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews DESTROYLOCK(&T10_mx);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews (void) isc_condition_destroy(&T10_cv);
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews ++*nprobs;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews return;
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews }
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence eventtab[event_cnt]->ev_tag =
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews (void *)((uintptr_t)tag + tag_cnt);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Make all odd message non-purgable.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if ((sender_cnt % 2) && (type_cnt %2) &&
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (tag_cnt %2))
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence eventtab[event_cnt]->ev_attributes |=
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence ISC_EVENTATTR_NOPURGE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++event_cnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley for (cnt = 0; cnt < event_cnt; ++cnt)
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &eventtab[cnt]);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T_debug)
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("%d events queued\n", cnt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (testrange == 0) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * We're testing isc_task_purge.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews nevents = isc_task_purge(task, purge_sender,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (isc_eventtype_t)purge_type_first,
99e207809793732e3e47da3a1cab6925b6eee8e9William King purge_tag);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (nevents != exp_nevents) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("*** isc_task_purge returned %d, expected %d\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King nevents, exp_nevents);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nfails;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else if (T_debug)
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_purge returned %d\n", nevents);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * We're testing isc_task_purgerange.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews nevents = isc_task_purgerange(task, purge_sender,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (isc_eventtype_t)purge_type_first,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (isc_eventtype_t)purge_type_last,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence purge_tag);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (nevents != exp_nevents) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t_info("*** isc_task_purgerange returned %d, "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "expected %d\n", nevents, exp_nevents);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nfails;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence } else if (T_debug)
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_purgerange returned %d\n", nevents);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Unblock the task, allowing event processing.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_startflag = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_signal(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_shutdown(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_interval_set(&interval, 5, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Wait for shutdown processing to complete.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T10_shutdownflag == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_time_nowplusinterval(&now, &interval);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_time_nowplusinterval failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_waituntil(&T10_cv, &T10_mx, &now);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_waituntil returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King return;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T10_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T10_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T10_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T_debug)
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("task processed %d events\n", T10_eventcnt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((T10_eventcnt + nevents) != event_cnt) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("*** processed %d, purged %d, total %d\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence T10_eventcnt, nevents, event_cnt);
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++*nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks10(void) {
afe871339abc32b19971656bf0ca8d1f25e1a2f7David Lawrence int result;
afe871339abc32b19971656bf0ca8d1f25e1a2f7David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_nprobs = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T10_nfails = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specific sender.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 2,4,8 expecting 1\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[2], 4, 4, (void *)8, 1, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T10_nprobs, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,8 expecting 3\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, (void *)8, 3, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T10_nprobs, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders, specified type, all tags.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,0 expecting 15\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, NULL, 15, &T10_nfails,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews &T10_nprobs, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specified tag, no such type.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,99,8 expecting 0\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 99, 99, (void *)8, 0, &T10_nfails,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T10_nprobs, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on specified sender, type, all tags.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,5,0 expecting 5\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[3], 5, 5, NULL, 5, &T10_nfails,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews &T10_nprobs, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((T10_nfails == 0) && (T10_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (T10_nfails != 0)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a10 =
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "A call to isc_task_purge(task, sender, type, tag) "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "purges all events of type 'type' and with tag 'tag' "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "not marked as unpurgable from sender from the task's "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "queue and returns the number of events purged.";
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt10(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 10, T_REQUIRED, "%s", a10);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks10());
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T11_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T11_startflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T11_shutdownflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T11_eventcnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_mutex_t T11_mx;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic isc_condition_t T11_cv;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt11_event1(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
56e85a97bb913177a1459d8447281a9893e90037Mark Andrews UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T11_startflag == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_wait(&T11_cv, &T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt11_event2(isc_task_t *task, isc_event_t *event) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_eventcnt;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt11_sde(isc_task_t *task, isc_event_t *event) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence UNUSED(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_shutdownflag;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_signal(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_free(&event);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt_tasks11(int purgable) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King char *p;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_t *mctx;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_t *tmgr;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_t *task;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_boolean_t rval;
99e207809793732e3e47da3a1cab6925b6eee8e9William King unsigned int workers;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_t isc_result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_event_t *event1;
eaf3e2217c8b627a70d11bed095eff38d222586bBob Halley isc_event_t *event2, *event2_clone;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_time_t now;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_interval_t interval;
99e207809793732e3e47da3a1cab6925b6eee8e9William King int result;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King T11_startflag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T11_shutdownflag = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T11_eventcnt = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = 2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King p = t_getenv("ISC_TASK_WORKERS");
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (p != NULL)
99e207809793732e3e47da3a1cab6925b6eee8e9William King workers = atoi(p);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King mctx = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mem_create(0, 0, &mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mem_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_init(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_init(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_init failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King tmgr = NULL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_taskmgr_create(mctx, workers, 0, &tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_taskmgr_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T11_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King task = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley isc_result = isc_task_create(tmgr, 0, &task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_create failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T11_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_task_onshutdown(task, t11_sde, NULL);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_onshutdown returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_destroy(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T11_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(T_UNRESOLVED);
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Block the task on T11_cv.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event1 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t11_event1, NULL, sizeof(*event1));
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event1 == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater isc_taskmgr_destroy(&tmgr);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater isc_mem_destroy(&mctx);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater DESTROYLOCK(&T11_mx);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater (void) isc_condition_destroy(&T11_cv);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater return(T_UNRESOLVED);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater }
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence event2 = isc_event_allocate(mctx, (void *)1, (isc_eventtype_t)1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t11_event2, NULL, sizeof(*event2));
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews if (event2 == NULL) {
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews t_info("isc_event_allocate failed\n");
cbf59e5887d69fca6fe86a1ee5fcc82dded14babMark Andrews isc_task_destroy(&task);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater isc_taskmgr_destroy(&tmgr);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater isc_mem_destroy(&mctx);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater DESTROYLOCK(&T11_mx);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater (void) isc_condition_destroy(&T11_cv);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater return(T_UNRESOLVED);
78851905629bcf5261beb93652839ee717a11b1eAutomatic Updater }
eaf3e2217c8b627a70d11bed095eff38d222586bBob Halley event2_clone = event2;
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (purgable)
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff event2->ev_attributes &= ~ISC_EVENTATTR_NOPURGE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff event2->ev_attributes |= ISC_EVENTATTR_NOPURGE;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
271d5bfc5ca8d746b535d1522f2aa9389ece2a7eBob Halley isc_task_send(task, &event2);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
eaf3e2217c8b627a70d11bed095eff38d222586bBob Halley rval = isc_task_purgeevent(task, event2_clone);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (rval != (purgable ? ISC_TRUE : ISC_FALSE)) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_task_purgeevent returned %s, expected %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (rval ? "ISC_TRUE" : "ISC_FALSE"),
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (purgable ? "ISC_TRUE" : "ISC_FALSE"));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_lock(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_lock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Unblock the task, allowing event processing.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King T11_startflag = 1;
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_signal(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_signal failed %s\n",
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_shutdown(task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_interval_set(&interval, 5, 0);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Wait for shutdown processing to complete.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King while (T11_shutdownflag == 0) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_time_nowplusinterval(&now, &interval);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_time_nowplusinterval failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_condition_waituntil(&T11_cv, &T11_mx, &now);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_condition_waituntil returned %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_result = isc_mutex_unlock(&T11_mx);
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (isc_result != ISC_R_SUCCESS) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("isc_mutex_unlock failed %s\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence isc_result_totext(isc_result));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_task_detach(&task);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_taskmgr_destroy(&tmgr);
99e207809793732e3e47da3a1cab6925b6eee8e9William King isc_mem_destroy(&mctx);
bf7c02293f883118784f7952944fa3e2bce98078Brian Wellington DESTROYLOCK(&T11_mx);
92f26881551da924db36b179757a2d7ea7fc2209Francis Dupont (void) isc_condition_destroy(&T11_cv);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if (T11_eventcnt != (purgable ? 0 : 1)) {
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence t_info("Event was %s purged\n",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence (purgable ? "not" : "unexpectedly"));
99e207809793732e3e47da3a1cab6925b6eee8e9William King ++T11_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William King }
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((T11_nfails == 0) && (T11_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (T11_nfails)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a11 =
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "When the event is marked as purgable, a call to "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "isc_task_purgeevent(task, event) purges the event 'event' "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "from the task's queue and returns ISC_TRUE.";
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt11(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 11, T_REQUIRED, "%s", a11);
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks11(1));
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a12 =
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "When the event is not marked as purgable, a call to "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "isc_task_purgeevent(task, event) does not purge the "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "event 'event' from the task's queue and returns "
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "ISC_FALSE.";
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks12(void) {
99e207809793732e3e47da3a1cab6925b6eee8e9William King return(t_tasks11(0));
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt12(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 12, T_REQUIRED, "%s", a12);
4c110ccec1f5a396464ec2aecaff451c8e858248Andreas Gustafsson
4c110ccec1f5a396464ec2aecaff451c8e858248Andreas Gustafsson if (threaded)
4c110ccec1f5a396464ec2aecaff451c8e858248Andreas Gustafsson t_result(t_tasks12());
4c110ccec1f5a396464ec2aecaff451c8e858248Andreas Gustafsson else
4c110ccec1f5a396464ec2aecaff451c8e858248Andreas Gustafsson require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T13_nfails;
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int T13_nprobs;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *a13 =
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "A call to "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "isc_event_purgerange(task, sender, first, last, tag) "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "purges all events not marked unpurgable from "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "sender 'sender' and of type within the range 'first' "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "to 'last' inclusive from the task's event queue and "
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence "returns the number of tasks purged.";
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingstatic int
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencet_tasks13(void) {
afe871339abc32b19971656bf0ca8d1f25e1a2f7David Lawrence int result;
afe871339abc32b19971656bf0ca8d1f25e1a2f7David Lawrence
99e207809793732e3e47da3a1cab6925b6eee8e9William King T13_nfails = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King T13_nprobs = 0;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * First let's try the same cases we used in t10.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specific sender.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 2,4,8 expecting 1\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[2], 4, 4, (void *)8, 1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,8 expecting 3\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, (void *)8, 3,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders, specified type, all tags.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4,0 expecting 15\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 4, NULL, 15, &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specified tag, no such type.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,99,8 expecting 0\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 99, 99, (void *)8, 0,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on specified sender, type, all tags.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 3,5,0 expecting 5\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[3], 5, 5, 0, 5, &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Now let's try some ranges.
99e207809793732e3e47da3a1cab6925b6eee8e9William King */
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purgerange on 2,4-5,8 expecting 2\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[2], 4, 5, (void *)8, 1,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,4-5,8 expecting 5\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 4, 5, (void *)8, 5,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on all senders, specified type, all tags.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,5-6,0 expecting 28\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 5, 6, NULL, 28, &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on a specified tag, no such type.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 0,99-101,8 expecting 0\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, NULL, 99, 101, (void *)8, 0,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence &T13_nfails, &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Try purging on specified sender, type, all tags.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
99e207809793732e3e47da3a1cab6925b6eee8e9William King t_info("testing purge on 3,5-6,0 expecting 10\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_taskpurge_x(1, 4, 7, &senders[3], 5, 6, NULL, 10, &T13_nfails,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews &T13_nprobs, 1);
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_UNRESOLVED;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
99e207809793732e3e47da3a1cab6925b6eee8e9William King if ((T13_nfails == 0) && (T13_nprobs == 0))
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_PASS;
99e207809793732e3e47da3a1cab6925b6eee8e9William King else if (T13_nfails)
99e207809793732e3e47da3a1cab6925b6eee8e9William King result = T_FAIL;
99e207809793732e3e47da3a1cab6925b6eee8e9William King
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence return (result);
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
9f44e95160bae777bcebe9cf216107de628bb1c0David Lawrencestatic void
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingt13(void) {
f148f53794956f491f6527430a93c2c8d884a212Mark Andrews t_assert("tasks", 13, T_REQUIRED, "%s", a13);
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence if (threaded)
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence t_result(t_tasks13());
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence else
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence require_threads();
99e207809793732e3e47da3a1cab6925b6eee8e9William King}
99e207809793732e3e47da3a1cab6925b6eee8e9William King
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson#define T14_NTASKS 10
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson#define T14_EXCLTASK 6
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrewsint t14_exclusiveerror = ISC_R_SUCCESS;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonint t14_error = 0;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonint t14_done = 0;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonint spin(int n);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonint t14_active[T14_NTASKS];
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonstatic void
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssont14_callback(isc_task_t *task, isc_event_t *event) {
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews int taskno = *(int *)(event->ev_arg);
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater t_info("task enter %d\n", taskno);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (taskno == T14_EXCLTASK) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson int i;
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t14_exclusiveerror = isc_task_beginexclusive(task);
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews if (t14_exclusiveerror == ISC_R_SUCCESS)
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t_info("task %d got exclusive access\n", taskno);
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews else
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t_info("task %d failed to got exclusive access: %d\n",
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews taskno, t14_exclusiveerror);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++) {
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater t_info("task %d state %d\n", i , t14_active[i]);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (t14_active[i])
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t14_error++;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_task_endexclusive(task);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t14_done = 1;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson } else {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t14_active[taskno]++;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson (void) spin(10000000);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t14_active[taskno]--;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("task exit %d\n", taskno);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (t14_done) {
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews isc_mem_put(event->ev_destroy_arg, event->ev_arg, sizeof (int));
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_event_free(&event);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson } else {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_task_send(task, &event);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson}
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonint spin(int n) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson int i;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson int r = 0;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < n; i++) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson r += i;
54b4a8d3451f65434f9dddec6b252c7e5e0b1624Andreas Gustafsson if (r > 1000000)
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson r = 0;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return (r);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson}
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonstatic int
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssont_tasks14(void) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson char *p;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_mem_t *mctx;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_taskmgr_t *manager;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_task_t *tasks[T14_NTASKS];
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson unsigned int workers;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result_t isc_result;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson int i;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson manager = NULL;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson mctx = NULL;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++)
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson tasks[i] = NULL;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson workers = 4;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson p = t_getenv("ISC_TASK_WORKERS");
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (p != NULL)
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson workers = atoi(p);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (workers < 1) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("Bad config value for ISC_TASK_WORKERS, %d\n", workers);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_UNRESOLVED);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result = isc_mem_create(0, 0, &mctx);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (isc_result != ISC_R_SUCCESS) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_mem_create failed %d\n", isc_result);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_UNRESOLVED);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result = isc_taskmgr_create(mctx, workers, 0, &manager);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (isc_result != ISC_R_SUCCESS) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_taskmgr_create failed %d\n", isc_result);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_FAIL);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_event_t *event;
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews int *v;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_result = isc_task_create(manager, 0, &tasks[i]);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (isc_result != ISC_R_SUCCESS) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_task_create failed %d\n", isc_result);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_FAIL);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews v = isc_mem_get(mctx, sizeof *v);
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews if (v == NULL) {
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews isc_task_detach(&tasks[i]);
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews t_info("isc_mem_get failed\n");
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews return(T_FAIL);
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews }
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews *v = i;
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews
95799c090cc4aae52c57feaba43fbf2d62586a76David Lawrence event = isc_event_allocate(mctx, NULL, 1, t14_callback,
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews v, sizeof(*event));
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson if (event == NULL) {
3b9a0696f99c40222e50ddae4d0dd9611737c1daMark Andrews isc_mem_put(mctx, v, sizeof *v);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_info("isc_event_allocate failed\n");
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_UNRESOLVED);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_task_send(tasks[i], &event);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson for (i = 0; i < T14_NTASKS; i++) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_task_detach(&tasks[i]);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_taskmgr_destroy(&manager);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews if (t14_exclusiveerror != ISC_R_SUCCESS || t14_error) {
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews if (t14_exclusiveerror != ISC_R_SUCCESS)
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t_info("isc_task_beginexclusive() failed\n");
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews if (t14_error)
2674e1a455d4f71de09b2b60e7a8304b9a305588Mark Andrews t_info("mutual access occurred\n");
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_FAIL);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson }
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson isc_mem_destroy(&mctx);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson return(T_PASS);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson}
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssonstatic void
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafssont14(void) {
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson int result;
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater t_assert("tasks", 14, T_REQUIRED, "%s",
3319413a678915b8b37aff0dbcc78a69ae58b5bbAutomatic Updater "isc_task_beginexclusive() gets exclusive access");
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson result = t_tasks14();
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson t_result(result);
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson}
b27b26d710d0c05b023c92ee5081dd2f0a240167Andreas Gustafsson
99e207809793732e3e47da3a1cab6925b6eee8e9William Kingtestspec_t T_testlist[] = {
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t1, "basic task subsystem" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t2, "maxtasks" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t3, "isc_task_shutdown" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t4, "isc_task_shutdown" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t7, "isc_task_create" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t10, "isc_task_purge" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t11, "isc_task_purgeevent" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t12, "isc_task_purgeevent" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t13, "isc_task_purgerange" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) t14, "isc_task_beginexclusive" },
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews { (PFV) 0, NULL }
99e207809793732e3e47da3a1cab6925b6eee8e9William King};
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#ifdef WIN32
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrewsint
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrewsmain(int argc, char **argv) {
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews t_settests(T_testlist);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews return (t_main(argc, argv));
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews}
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews#endif