tasks revision 9bff67898d55cddfcec9ce30cc2b1bb6211ec691
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David LawrenceCopyright (C) 1999, 2000 Internet Software Consortium.
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David LawrenceSee COPYRIGHT in the source root or http://www.isc.org/copyright for terms.
9bff67898d55cddfcec9ce30cc2b1bb6211ec691David 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