0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsCopyright (C) 1999-2001, 2004, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsThis Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark AndrewsLicense, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrewsfile, You can obtain one at http://mozilla.org/MPL/2.0/.
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David Lawrence
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews$Id: tasks,v 1.7 2004/03/05 05:04:47 marka Exp $
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David LawrenceChanges I made last week to the task code simplified the task shutdown
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrenceand termination model. Here's how things now work:
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David LawrenceWhen a task is shutdown:
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence Any "on shutdown" events for the task are posted
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The "shutting down" attribute of the task is set
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence Any attempts to add shutdown events with isc_task_onshutdown()
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence will fail, since the task is already shutting down
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David LawrenceTask shutdown can be initiated explicity, via a call to isc_task_shutdown(),
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrenceor implicitly, when the following conditions occur:
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The "shutting down" attribute of the task is not set
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The task has no references
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The task has an empty event queue
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David LawrenceTask termination occurs when:
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The "shutting down" attribute of the task is set
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The task has no references
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence
03f727fcc57f597c610fd7454a31980efa5ea036David Lawrence The task has an empty event queue
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceNotes from the task/event discussion led by Bob Halley on 13 March 2000:
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceA task is an event queue.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence (task) --V
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence (event)-->(event)-->(event)
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence (runnable queue)--V
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence (task)-->(task)-->(task)
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceNormally only one task manager in an application.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceTask becomes runnable if it has a non-empty event queue.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceOne or more worker threads run tasks.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceEvent routines should be relatively short.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceOnly one runnable queue that all workers share.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceEvents for a task are always posted serially. Multiple worker threads
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrencewill not be working on multiple events for one task at the same time.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrenceisc_event_send, posting an event, can't fail. It just adds an event
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrenceto the task queue.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceEvent action (callback) rules:
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence * no locks held on your behald when entering a callback.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence * not allowed to block, except when aquiring a lock.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence * not allowed to hold a lock when exiting the callback.
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceTIMERS?
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence
c192f12b0fecf3557f9e04875f81bd96b223c772David LawrenceOMAPI -- need taskmgr to omapi_lib_init
c192f12b0fecf3557f9e04875f81bd96b223c772David Lawrence -- one task per client connection