2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: taskpool.c,v 1.10.2.1 2004/03/09 06:11:52 marka Exp $ */
23 #include <isc/taskpool.h>
40 isc_taskpool_create(isc_taskmgr_t
*tmgr
, isc_mem_t
*mctx
,
41 unsigned int ntasks
, unsigned int quantum
,
42 isc_taskpool_t
**poolp
)
49 pool
= isc_mem_get(mctx
, sizeof *pool
);
51 return (ISC_R_NOMEMORY
);
53 pool
->ntasks
= ntasks
;
54 pool
->tasks
= isc_mem_get(mctx
, ntasks
* sizeof(isc_task_t
*));
55 for (i
= 0; i
< ntasks
; i
++)
56 pool
->tasks
[i
] = NULL
;
57 for (i
= 0; i
< ntasks
; i
++) {
58 result
= isc_task_create(tmgr
, quantum
, &pool
->tasks
[i
]);
59 if (result
!= ISC_R_SUCCESS
) {
60 isc_taskpool_destroy(&pool
);
65 return (ISC_R_SUCCESS
);
68 void isc_taskpool_gettask(isc_taskpool_t
*pool
, unsigned int hash
,
71 isc_task_attach(pool
->tasks
[hash
% pool
->ntasks
], targetp
);
75 isc_taskpool_destroy(isc_taskpool_t
**poolp
) {
77 isc_taskpool_t
*pool
= *poolp
;
78 for (i
= 0; i
< pool
->ntasks
; i
++) {
79 if (pool
->tasks
[i
] != NULL
) {
80 isc_task_detach(&pool
->tasks
[i
]);
83 isc_mem_put(pool
->mctx
, pool
->tasks
,
84 pool
->ntasks
* sizeof(isc_task_t
*));
85 isc_mem_put(pool
->mctx
, pool
, sizeof(*pool
));