task.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2009-2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2001, 2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 #ifndef ISC_TASK_H
00021 #define ISC_TASK_H 1
00022 
00023 /*****
00024  ***** Module Info
00025  *****/
00026 
00027 /*! \file isc/task.h
00028  * \brief The task system provides a lightweight execution context, which is
00029  * basically an event queue.
00030 
00031  * When a task's event queue is non-empty, the
00032  * task is runnable.  A small work crew of threads, typically one per CPU,
00033  * execute runnable tasks by dispatching the events on the tasks' event
00034  * queues.  Context switching between tasks is fast.
00035  *
00036  * \li MP:
00037  *      The module ensures appropriate synchronization of data structures it
00038  *      creates and manipulates.
00039  *      The caller must ensure that isc_taskmgr_destroy() is called only
00040  *      once for a given manager.
00041  *
00042  * \li Reliability:
00043  *      No anticipated impact.
00044  *
00045  * \li Resources:
00046  *      TBS
00047  *
00048  * \li Security:
00049  *      No anticipated impact.
00050  *
00051  * \li Standards:
00052  *      None.
00053  *
00054  * \section purge Purging and Unsending
00055  *
00056  * Events which have been queued for a task but not delivered may be removed
00057  * from the task's event queue by purging or unsending.
00058  *
00059  * With both types, the caller specifies a matching pattern that selects
00060  * events based upon their sender, type, and tag.
00061  *
00062  * Purging calls isc_event_free() on the matching events.
00063  *
00064  * Unsending returns a list of events that matched the pattern.
00065  * The caller is then responsible for them.
00066  *
00067  * Consumers of events should purge, not unsend.
00068  *
00069  * Producers of events often want to remove events when the caller indicates
00070  * it is no longer interested in the object, e.g. by canceling a timer.
00071  * Sometimes this can be done by purging, but for some event types, the
00072  * calls to isc_event_free() cause deadlock because the event free routine
00073  * wants to acquire a lock the caller is already holding.  Unsending instead
00074  * of purging solves this problem.  As a general rule, producers should only
00075  * unsend events which they have sent.
00076  */
00077 
00078 
00079 /***
00080  *** Imports.
00081  ***/
00082 
00083 #include <isc/eventclass.h>
00084 #include <isc/json.h>
00085 #include <isc/lang.h>
00086 #include <isc/stdtime.h>
00087 #include <isc/types.h>
00088 #include <isc/xml.h>
00089 
00090 #define ISC_TASKEVENT_FIRSTEVENT        (ISC_EVENTCLASS_TASK + 0)
00091 #define ISC_TASKEVENT_SHUTDOWN          (ISC_EVENTCLASS_TASK + 1)
00092 #define ISC_TASKEVENT_TEST              (ISC_EVENTCLASS_TASK + 1)
00093 #define ISC_TASKEVENT_LASTEVENT         (ISC_EVENTCLASS_TASK + 65535)
00094 
00095 /*****
00096  ***** Tasks.
00097  *****/
00098 
00099 ISC_LANG_BEGINDECLS
00100 
00101 /***
00102  *** Types
00103  ***/
00104 
00105 typedef enum {
00106                 isc_taskmgrmode_normal = 0,
00107                 isc_taskmgrmode_privileged
00108 } isc_taskmgrmode_t;
00109 
00110 /*% Task and task manager methods */
00111 typedef struct isc_taskmgrmethods {
00112         void            (*destroy)(isc_taskmgr_t **managerp);
00113         void            (*setmode)(isc_taskmgr_t *manager,
00114                                    isc_taskmgrmode_t mode);
00115         isc_taskmgrmode_t (*mode)(isc_taskmgr_t *manager);
00116         isc_result_t    (*taskcreate)(isc_taskmgr_t *manager,
00117                                       unsigned int quantum,
00118                                       isc_task_t **taskp);
00119         void (*setexcltask)(isc_taskmgr_t *mgr, isc_task_t *task);
00120         isc_result_t (*excltask)(isc_taskmgr_t *mgr, isc_task_t **taskp);
00121 } isc_taskmgrmethods_t;
00122 
00123 typedef struct isc_taskmethods {
00124         void (*attach)(isc_task_t *source, isc_task_t **targetp);
00125         void (*detach)(isc_task_t **taskp);
00126         void (*destroy)(isc_task_t **taskp);
00127         void (*send)(isc_task_t *task, isc_event_t **eventp);
00128         void (*sendanddetach)(isc_task_t **taskp, isc_event_t **eventp);
00129         unsigned int (*unsend)(isc_task_t *task, void *sender, isc_eventtype_t type,
00130                                void *tag, isc_eventlist_t *events);
00131         isc_result_t (*onshutdown)(isc_task_t *task, isc_taskaction_t action,
00132                                    void *arg);
00133         void (*shutdown)(isc_task_t *task);
00134         void (*setname)(isc_task_t *task, const char *name, void *tag);
00135         unsigned int (*purgeevents)(isc_task_t *task, void *sender,
00136                                     isc_eventtype_t type, void *tag);
00137         unsigned int (*purgerange)(isc_task_t *task, void *sender,
00138                                    isc_eventtype_t first, isc_eventtype_t last,
00139                                    void *tag);
00140         isc_result_t (*beginexclusive)(isc_task_t *task);
00141         void (*endexclusive)(isc_task_t *task);
00142     void (*setprivilege)(isc_task_t *task, isc_boolean_t priv);
00143     isc_boolean_t (*privilege)(isc_task_t *task);
00144 } isc_taskmethods_t;
00145 
00146 /*%
00147  * This structure is actually just the common prefix of a task manager
00148  * object implementation's version of an isc_taskmgr_t.
00149  * \brief
00150  * Direct use of this structure by clients is forbidden.  task implementations
00151  * may change the structure.  'magic' must be ISCAPI_TASKMGR_MAGIC for any
00152  * of the isc_task_ routines to work.  task implementations must maintain
00153  * all task invariants.
00154  */
00155 struct isc_taskmgr {
00156         unsigned int            impmagic;
00157         unsigned int            magic;
00158         isc_taskmgrmethods_t    *methods;
00159 };
00160 
00161 #define ISCAPI_TASKMGR_MAGIC    ISC_MAGIC('A','t','m','g')
00162 #define ISCAPI_TASKMGR_VALID(m) ((m) != NULL && \
00163                                  (m)->magic == ISCAPI_TASKMGR_MAGIC)
00164 
00165 /*%
00166  * This is the common prefix of a task object.  The same note as
00167  * that for the taskmgr structure applies.
00168  */
00169 struct isc_task {
00170         unsigned int            impmagic;
00171         unsigned int            magic;
00172         isc_taskmethods_t       *methods;
00173 };
00174 
00175 #define ISCAPI_TASK_MAGIC       ISC_MAGIC('A','t','s','t')
00176 #define ISCAPI_TASK_VALID(s)    ((s) != NULL && \
00177                                  (s)->magic == ISCAPI_TASK_MAGIC)
00178 
00179 isc_result_t
00180 isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
00181                 isc_task_t **taskp);
00182 /*%<
00183  * Create a task.
00184  *
00185  * Notes:
00186  *
00187  *\li   If 'quantum' is non-zero, then only that many events can be dispatched
00188  *      before the task must yield to other tasks waiting to execute.  If
00189  *      quantum is zero, then the default quantum of the task manager will
00190  *      be used.
00191  *
00192  *\li   The 'quantum' option may be removed from isc_task_create() in the
00193  *      future.  If this happens, isc_task_getquantum() and
00194  *      isc_task_setquantum() will be provided.
00195  *
00196  * Requires:
00197  *
00198  *\li   'manager' is a valid task manager.
00199  *
00200  *\li   taskp != NULL && *taskp == NULL
00201  *
00202  * Ensures:
00203  *
00204  *\li   On success, '*taskp' is bound to the new task.
00205  *
00206  * Returns:
00207  *
00208  *\li   #ISC_R_SUCCESS
00209  *\li   #ISC_R_NOMEMORY
00210  *\li   #ISC_R_UNEXPECTED
00211  *\li   #ISC_R_SHUTTINGDOWN
00212  */
00213 
00214 void
00215 isc_task_attach(isc_task_t *source, isc_task_t **targetp);
00216 /*%<
00217  * Attach *targetp to source.
00218  *
00219  * Requires:
00220  *
00221  *\li   'source' is a valid task.
00222  *
00223  *\li   'targetp' points to a NULL isc_task_t *.
00224  *
00225  * Ensures:
00226  *
00227  *\li   *targetp is attached to source.
00228  */
00229 
00230 void
00231 isc_task_detach(isc_task_t **taskp);
00232 /*%<
00233  * Detach *taskp from its task.
00234  *
00235  * Requires:
00236  *
00237  *\li   '*taskp' is a valid task.
00238  *
00239  * Ensures:
00240  *
00241  *\li   *taskp is NULL.
00242  *
00243  *\li   If '*taskp' is the last reference to the task, the task is idle (has
00244  *      an empty event queue), and has not been shutdown, the task will be
00245  *      shutdown.
00246  *
00247  *\li   If '*taskp' is the last reference to the task and
00248  *      the task has been shutdown,
00249  *              all resources used by the task will be freed.
00250  */
00251 
00252 void
00253 isc_task_send(isc_task_t *task, isc_event_t **eventp);
00254 /*%<
00255  * Send '*event' to 'task'.
00256  *
00257  * Requires:
00258  *
00259  *\li   'task' is a valid task.
00260  *\li   eventp != NULL && *eventp != NULL.
00261  *
00262  * Ensures:
00263  *
00264  *\li   *eventp == NULL.
00265  */
00266 
00267 void
00268 isc_task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp);
00269 /*%<
00270  * Send '*event' to '*taskp' and then detach '*taskp' from its
00271  * task.
00272  *
00273  * Requires:
00274  *
00275  *\li   '*taskp' is a valid task.
00276  *\li   eventp != NULL && *eventp != NULL.
00277  *
00278  * Ensures:
00279  *
00280  *\li   *eventp == NULL.
00281  *
00282  *\li   *taskp == NULL.
00283  *
00284  *\li   If '*taskp' is the last reference to the task, the task is
00285  *      idle (has an empty event queue), and has not been shutdown,
00286  *      the task will be shutdown.
00287  *
00288  *\li   If '*taskp' is the last reference to the task and
00289  *      the task has been shutdown,
00290  *              all resources used by the task will be freed.
00291  */
00292 
00293 
00294 unsigned int
00295 isc_task_purgerange(isc_task_t *task, void *sender, isc_eventtype_t first,
00296                     isc_eventtype_t last, void *tag);
00297 /*%<
00298  * Purge events from a task's event queue.
00299  *
00300  * Requires:
00301  *
00302  *\li   'task' is a valid task.
00303  *
00304  *\li   last >= first
00305  *
00306  * Ensures:
00307  *
00308  *\li   Events in the event queue of 'task' whose sender is 'sender', whose
00309  *      type is >= first and <= last, and whose tag is 'tag' will be purged,
00310  *      unless they are marked as unpurgable.
00311  *
00312  *\li   A sender of NULL will match any sender.  A NULL tag matches any
00313  *      tag.
00314  *
00315  * Returns:
00316  *
00317  *\li   The number of events purged.
00318  */
00319 
00320 unsigned int
00321 isc_task_purge(isc_task_t *task, void *sender, isc_eventtype_t type,
00322                void *tag);
00323 /*%<
00324  * Purge events from a task's event queue.
00325  *
00326  * Notes:
00327  *
00328  *\li   This function is equivalent to
00329  *
00330  *\code
00331  *              isc_task_purgerange(task, sender, type, type, tag);
00332  *\endcode
00333  *
00334  * Requires:
00335  *
00336  *\li   'task' is a valid task.
00337  *
00338  * Ensures:
00339  *
00340  *\li   Events in the event queue of 'task' whose sender is 'sender', whose
00341  *      type is 'type', and whose tag is 'tag' will be purged, unless they
00342  *      are marked as unpurgable.
00343  *
00344  *\li   A sender of NULL will match any sender.  A NULL tag matches any
00345  *      tag.
00346  *
00347  * Returns:
00348  *
00349  *\li   The number of events purged.
00350  */
00351 
00352 isc_boolean_t
00353 isc_task_purgeevent(isc_task_t *task, isc_event_t *event);
00354 /*%<
00355  * Purge 'event' from a task's event queue.
00356  *
00357  * XXXRTH:  WARNING:  This method may be removed before beta.
00358  *
00359  * Notes:
00360  *
00361  *\li   If 'event' is on the task's event queue, it will be purged,
00362  *      unless it is marked as unpurgeable.  'event' does not have to be
00363  *      on the task's event queue; in fact, it can even be an invalid
00364  *      pointer.  Purging only occurs if the event is actually on the task's
00365  *      event queue.
00366  *
00367  * \li  Purging never changes the state of the task.
00368  *
00369  * Requires:
00370  *
00371  *\li   'task' is a valid task.
00372  *
00373  * Ensures:
00374  *
00375  *\li   'event' is not in the event queue for 'task'.
00376  *
00377  * Returns:
00378  *
00379  *\li   #ISC_TRUE                       The event was purged.
00380  *\li   #ISC_FALSE                      The event was not in the event queue,
00381  *                                      or was marked unpurgeable.
00382  */
00383 
00384 unsigned int
00385 isc_task_unsendrange(isc_task_t *task, void *sender, isc_eventtype_t first,
00386                      isc_eventtype_t last, void *tag, isc_eventlist_t *events);
00387 /*%<
00388  * Remove events from a task's event queue.
00389  *
00390  * Requires:
00391  *
00392  *\li   'task' is a valid task.
00393  *
00394  *\li   last >= first.
00395  *
00396  *\li   *events is a valid list.
00397  *
00398  * Ensures:
00399  *
00400  *\li   Events in the event queue of 'task' whose sender is 'sender', whose
00401  *      type is >= first and <= last, and whose tag is 'tag' will be dequeued
00402  *      and appended to *events.
00403  *
00404  *\li   A sender of NULL will match any sender.  A NULL tag matches any
00405  *      tag.
00406  *
00407  * Returns:
00408  *
00409  *\li   The number of events unsent.
00410  */
00411 
00412 unsigned int
00413 isc_task_unsend(isc_task_t *task, void *sender, isc_eventtype_t type,
00414                 void *tag, isc_eventlist_t *events);
00415 /*%<
00416  * Remove events from a task's event queue.
00417  *
00418  * Notes:
00419  *
00420  *\li   This function is equivalent to
00421  *
00422  *\code
00423  *              isc_task_unsendrange(task, sender, type, type, tag, events);
00424  *\endcode
00425  *
00426  * Requires:
00427  *
00428  *\li   'task' is a valid task.
00429  *
00430  *\li   *events is a valid list.
00431  *
00432  * Ensures:
00433  *
00434  *\li   Events in the event queue of 'task' whose sender is 'sender', whose
00435  *      type is 'type', and whose tag is 'tag' will be dequeued and appended
00436  *      to *events.
00437  *
00438  * Returns:
00439  *
00440  *\li   The number of events unsent.
00441  */
00442 
00443 isc_result_t
00444 isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action,
00445                     void *arg);
00446 /*%<
00447  * Send a shutdown event with action 'action' and argument 'arg' when
00448  * 'task' is shutdown.
00449  *
00450  * Notes:
00451  *
00452  *\li   Shutdown events are posted in LIFO order.
00453  *
00454  * Requires:
00455  *
00456  *\li   'task' is a valid task.
00457  *
00458  *\li   'action' is a valid task action.
00459  *
00460  * Ensures:
00461  *
00462  *\li   When the task is shutdown, shutdown events requested with
00463  *      isc_task_onshutdown() will be appended to the task's event queue.
00464  *
00465 
00466  * Returns:
00467  *
00468  *\li   #ISC_R_SUCCESS
00469  *\li   #ISC_R_NOMEMORY
00470  *\li   #ISC_R_TASKSHUTTINGDOWN                 Task is shutting down.
00471  */
00472 
00473 void
00474 isc_task_shutdown(isc_task_t *task);
00475 /*%<
00476  * Shutdown 'task'.
00477  *
00478  * Notes:
00479  *
00480  *\li   Shutting down a task causes any shutdown events requested with
00481  *      isc_task_onshutdown() to be posted (in LIFO order).  The task
00482  *      moves into a "shutting down" mode which prevents further calls
00483  *      to isc_task_onshutdown().
00484  *
00485  *\li   Trying to shutdown a task that has already been shutdown has no
00486  *      effect.
00487  *
00488  * Requires:
00489  *
00490  *\li   'task' is a valid task.
00491  *
00492  * Ensures:
00493  *
00494  *\li   Any shutdown events requested with isc_task_onshutdown() have been
00495  *      posted (in LIFO order).
00496  */
00497 
00498 void
00499 isc_task_destroy(isc_task_t **taskp);
00500 /*%<
00501  * Destroy '*taskp'.
00502  *
00503  * Notes:
00504  *
00505  *\li   This call is equivalent to:
00506  *
00507  *\code
00508  *              isc_task_shutdown(*taskp);
00509  *              isc_task_detach(taskp);
00510  *\endcode
00511  *
00512  * Requires:
00513  *
00514  *      '*taskp' is a valid task.
00515  *
00516  * Ensures:
00517  *
00518  *\li   Any shutdown events requested with isc_task_onshutdown() have been
00519  *      posted (in LIFO order).
00520  *
00521  *\li   *taskp == NULL
00522  *
00523  *\li   If '*taskp' is the last reference to the task,
00524  *              all resources used by the task will be freed.
00525  */
00526 
00527 void
00528 isc_task_setname(isc_task_t *task, const char *name, void *tag);
00529 /*%<
00530  * Name 'task'.
00531  *
00532  * Notes:
00533  *
00534  *\li   Only the first 15 characters of 'name' will be copied.
00535  *
00536  *\li   Naming a task is currently only useful for debugging purposes.
00537  *
00538  * Requires:
00539  *
00540  *\li   'task' is a valid task.
00541  */
00542 
00543 const char *
00544 isc_task_getname(isc_task_t *task);
00545 /*%<
00546  * Get the name of 'task', as previously set using isc_task_setname().
00547  *
00548  * Notes:
00549  *\li   This function is for debugging purposes only.
00550  *
00551  * Requires:
00552  *\li   'task' is a valid task.
00553  *
00554  * Returns:
00555  *\li   A non-NULL pointer to a null-terminated string.
00556  *      If the task has not been named, the string is
00557  *      empty.
00558  *
00559  */
00560 
00561 void *
00562 isc_task_gettag(isc_task_t *task);
00563 /*%<
00564  * Get the tag value for  'task', as previously set using isc_task_settag().
00565  *
00566  * Notes:
00567  *\li   This function is for debugging purposes only.
00568  *
00569  * Requires:
00570  *\li   'task' is a valid task.
00571  */
00572 
00573 isc_result_t
00574 isc_task_beginexclusive(isc_task_t *task);
00575 /*%<
00576  * Request exclusive access for 'task', which must be the calling
00577  * task.  Waits for any other concurrently executing tasks to finish their
00578  * current event, and prevents any new events from executing in any of the
00579  * tasks sharing a task manager with 'task'.
00580  *
00581  * The exclusive access must be relinquished by calling
00582  * isc_task_endexclusive() before returning from the current event handler.
00583  *
00584  * Requires:
00585  *\li   'task' is the calling task.
00586  *
00587  * Returns:
00588  *\li   #ISC_R_SUCCESS          The current task now has exclusive access.
00589  *\li   #ISC_R_LOCKBUSY         Another task has already requested exclusive
00590  *                              access.
00591  */
00592 
00593 void
00594 isc_task_endexclusive(isc_task_t *task);
00595 /*%<
00596  * Relinquish the exclusive access obtained by isc_task_beginexclusive(),
00597  * allowing other tasks to execute.
00598  *
00599  * Requires:
00600  *\li   'task' is the calling task, and has obtained
00601  *              exclusive access by calling isc_task_spl().
00602  */
00603 
00604 void
00605 isc_task_getcurrenttime(isc_task_t *task, isc_stdtime_t *t);
00606 /*%<
00607  * Provide the most recent timestamp on the task.  The timestamp is considered
00608  * as the "current time" in the second-order granularity.
00609  *
00610  * Requires:
00611  *\li   'task' is a valid task.
00612  *\li   't' is a valid non NULL pointer.
00613  *
00614  * Ensures:
00615  *\li   '*t' has the "current time".
00616  */
00617 
00618 isc_boolean_t
00619 isc_task_exiting(isc_task_t *t);
00620 /*%<
00621  * Returns ISC_TRUE if the task is in the process of shutting down,
00622  * ISC_FALSE otherwise.
00623  *
00624  * Requires:
00625  *\li   'task' is a valid task.
00626  */
00627 
00628 void
00629 isc_task_setprivilege(isc_task_t *task, isc_boolean_t priv);
00630 /*%<
00631  * Set or unset the task's "privileged" flag depending on the value of
00632  * 'priv'.
00633  *
00634  * Under normal circumstances this flag has no effect on the task behavior,
00635  * but when the task manager has been set to privileged execution mode via
00636  * isc_taskmgr_setmode(), only tasks with the flag set will be executed,
00637  * and all other tasks will wait until they're done.  Once all privileged
00638  * tasks have finished executing, the task manager will automatically
00639  * return to normal execution mode and nonprivileged task can resume.
00640  *
00641  * Requires:
00642  *\li   'task' is a valid task.
00643  */
00644 
00645 isc_boolean_t
00646 isc_task_privilege(isc_task_t *task);
00647 /*%<
00648  * Returns the current value of the task's privilege flag.
00649  *
00650  * Requires:
00651  *\li   'task' is a valid task.
00652  */
00653 
00654 /*****
00655  ***** Task Manager.
00656  *****/
00657 
00658 isc_result_t
00659 isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
00660                         unsigned int workers, unsigned int default_quantum,
00661                         isc_taskmgr_t **managerp);
00662 isc_result_t
00663 isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
00664                    unsigned int default_quantum, isc_taskmgr_t **managerp);
00665 /*%<
00666  * Create a new task manager.  isc_taskmgr_createinctx() also associates
00667  * the new manager with the specified application context.
00668  *
00669  * Notes:
00670  *
00671  *\li   'workers' in the number of worker threads to create.  In general,
00672  *      the value should be close to the number of processors in the system.
00673  *      The 'workers' value is advisory only.  An attempt will be made to
00674  *      create 'workers' threads, but if at least one thread creation
00675  *      succeeds, isc_taskmgr_create() may return ISC_R_SUCCESS.
00676  *
00677  *\li   If 'default_quantum' is non-zero, then it will be used as the default
00678  *      quantum value when tasks are created.  If zero, then an implementation
00679  *      defined default quantum will be used.
00680  *
00681  * Requires:
00682  *
00683  *\li      'mctx' is a valid memory context.
00684  *
00685  *\li   workers > 0
00686  *
00687  *\li   managerp != NULL && *managerp == NULL
00688  *
00689  *\li   'actx' is a valid application context (for createinctx()).
00690  *
00691  * Ensures:
00692  *
00693  *\li   On success, '*managerp' will be attached to the newly created task
00694  *      manager.
00695  *
00696  * Returns:
00697  *
00698  *\li   #ISC_R_SUCCESS
00699  *\li   #ISC_R_NOMEMORY
00700  *\li   #ISC_R_NOTHREADS                No threads could be created.
00701  *\li   #ISC_R_UNEXPECTED               An unexpected error occurred.
00702  *\li   #ISC_R_SHUTTINGDOWN             The non-threaded, shared, task
00703  *                                      manager shutting down.
00704  */
00705 
00706 void
00707 isc_taskmgr_setmode(isc_taskmgr_t *manager, isc_taskmgrmode_t mode);
00708 
00709 isc_taskmgrmode_t
00710 isc_taskmgr_mode(isc_taskmgr_t *manager);
00711 /*%<
00712  * Set/get the current operating mode of the task manager.  Valid modes are:
00713  *
00714  *\li  isc_taskmgrmode_normal
00715  *\li  isc_taskmgrmode_privileged
00716  *
00717  * In privileged execution mode, only tasks that have had the "privilege"
00718  * flag set via isc_task_setprivilege() can be executed.  When all such
00719  * tasks are complete, the manager automatically returns to normal mode
00720  * and proceeds with running non-privileged ready tasks.  This means it is
00721  * necessary to have at least one privileged task waiting on the ready
00722  * queue *before* setting the manager into privileged execution mode,
00723  * which in turn means the task which calls this function should be in
00724  * task-exclusive mode when it does so.
00725  *
00726  * Requires:
00727  *
00728  *\li      'manager' is a valid task manager.
00729  */
00730 
00731 void
00732 isc_taskmgr_destroy(isc_taskmgr_t **managerp);
00733 /*%<
00734  * Destroy '*managerp'.
00735  *
00736  * Notes:
00737  *
00738  *\li   Calling isc_taskmgr_destroy() will shutdown all tasks managed by
00739  *      *managerp that haven't already been shutdown.  The call will block
00740  *      until all tasks have entered the done state.
00741  *
00742  *\li   isc_taskmgr_destroy() must not be called by a task event action,
00743  *      because it would block forever waiting for the event action to
00744  *      complete.  An event action that wants to cause task manager shutdown
00745  *      should request some non-event action thread of execution to do the
00746  *      shutdown, e.g. by signaling a condition variable or using
00747  *      isc_app_shutdown().
00748  *
00749  *\li   Task manager references are not reference counted, so the caller
00750  *      must ensure that no attempt will be made to use the manager after
00751  *      isc_taskmgr_destroy() returns.
00752  *
00753  * Requires:
00754  *
00755  *\li   '*managerp' is a valid task manager.
00756  *
00757  *\li   isc_taskmgr_destroy() has not be called previously on '*managerp'.
00758  *
00759  * Ensures:
00760  *
00761  *\li   All resources used by the task manager, and any tasks it managed,
00762  *      have been freed.
00763  */
00764 
00765 void
00766 isc_taskmgr_setexcltask(isc_taskmgr_t *mgr, isc_task_t *task);
00767 /*%<
00768  * Set a task which will be used for all task-exclusive operations.
00769  *
00770  * Requires:
00771  *\li   'manager' is a valid task manager.
00772  *
00773  *\li   'task' is a valid task.
00774  */
00775 
00776 isc_result_t
00777 isc_taskmgr_excltask(isc_taskmgr_t *mgr, isc_task_t **taskp);
00778 /*%<
00779  * Attach '*taskp' to the task set by isc_taskmgr_getexcltask().
00780  * This task should be used whenever running in task-exclusive mode,
00781  * so as to prevent deadlock between two exclusive tasks.
00782  *
00783  * Requires:
00784  *\li   'manager' is a valid task manager.
00785 
00786  *\li   taskp != NULL && *taskp == NULL
00787  */
00788 
00789 
00790 #ifdef HAVE_LIBXML2
00791 int
00792 isc_taskmgr_renderxml(isc_taskmgr_t *mgr, xmlTextWriterPtr writer);
00793 #endif
00794 
00795 #ifdef HAVE_JSON
00796 isc_result_t
00797 isc_taskmgr_renderjson(isc_taskmgr_t *mgr, json_object *tasksobj);
00798 #endif
00799 
00800 /*%<
00801  * See isc_taskmgr_create() above.
00802  */
00803 typedef isc_result_t
00804 (*isc_taskmgrcreatefunc_t)(isc_mem_t *mctx, unsigned int workers,
00805                            unsigned int default_quantum,
00806                            isc_taskmgr_t **managerp);
00807 
00808 isc_result_t
00809 isc_task_register(isc_taskmgrcreatefunc_t createfunc);
00810 /*%<
00811  * Register a new task management implementation and add it to the list of
00812  * supported implementations.  This function must be called when a different
00813  * event library is used than the one contained in the ISC library.
00814  */
00815 
00816 isc_result_t
00817 isc__task_register(void);
00818 /*%<
00819  * A short cut function that specifies the task management module in the ISC
00820  * library for isc_task_register().  An application that uses the ISC library
00821  * usually do not have to care about this function: it would call
00822  * isc_lib_register(), which internally calls this function.
00823  */
00824 
00825 ISC_LANG_ENDDECLS
00826 
00827 #endif /* ISC_TASK_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha