Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
BIND
Commits
bf6d2e39
Commit
bf6d2e39
authored
Oct 22, 1998
by
Bob Halley
Browse files
more renaming
parent
de9282a1
Changes
14
Hide whitespace changes
Inline
Side-by-side
bin/tests/task_test.c
View file @
bf6d2e39
...
...
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <isc/assertions.h>
#include <isc/memcluster.h>
#include <isc/task.h>
#include <isc/thread.h>
...
...
@@ -53,7 +54,7 @@ main(int argc, char *argv[]) {
unsigned
int
workers
;
isc_timermgr_t
timgr
;
isc_timer_t
ti1
,
ti2
;
o
s_time
_t
absolute
,
interval
;
s
truct
isc
_time
absolute
,
interval
;
if
(
argc
>
1
)
workers
=
atoi
(
argv
[
1
]);
...
...
@@ -63,12 +64,17 @@ main(int argc, char *argv[]) {
INSIST
(
isc_memctx_create
(
0
,
0
,
&
mctx
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_taskmgr_create
(
mctx
,
workers
,
0
,
&
manager
)
==
workers
);
INSIST
(
isc_taskmgr_create
(
mctx
,
workers
,
0
,
&
manager
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"1"
,
0
,
&
t1
));
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"2"
,
0
,
&
t2
));
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"3"
,
0
,
&
t3
));
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"4"
,
0
,
&
t4
));
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"1"
,
0
,
&
t1
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"2"
,
0
,
&
t2
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"3"
,
0
,
&
t3
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
my_shutdown
,
"4"
,
0
,
&
t4
)
==
ISC_R_SUCCESS
);
timgr
=
NULL
;
INSIST
(
isc_timermgr_create
(
mctx
,
&
timgr
)
==
ISC_R_SUCCESS
);
...
...
@@ -78,11 +84,11 @@ main(int argc, char *argv[]) {
interval
.
seconds
=
1
;
interval
.
nanoseconds
=
0
;
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_ticker
,
absolute
,
interval
,
&
absolute
,
&
interval
,
t1
,
my_tick
,
"foo"
,
&
ti1
)
==
ISC_R_SUCCESS
);
ti2
=
NULL
;
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_ticker
,
absolute
,
interval
,
&
absolute
,
&
interval
,
t2
,
my_tick
,
"bar"
,
&
ti2
)
==
ISC_R_SUCCESS
);
printf
(
"task 1 = %p
\n
"
,
t1
);
...
...
bin/tests/timer_test.c
View file @
bf6d2e39
...
...
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <isc/assertions.h>
#include <isc/memcluster.h>
#include <isc/task.h>
#include <isc/thread.h>
...
...
@@ -38,17 +39,17 @@ tick(isc_task_t task, isc_event_t event)
isc_timer_touch
(
ti3
);
if
(
tick_count
==
7
)
{
o
s_time
_t
expires
,
interval
,
now
;
s
truct
isc
_time
expires
,
interval
,
now
;
(
void
)
os
_time_get
(
&
now
);
(
void
)
isc
_time_get
(
&
now
);
expires
.
seconds
=
5
;
expires
.
nanoseconds
=
0
;
os
_time_add
(
&
now
,
&
expires
,
&
expires
);
isc
_time_add
(
&
now
,
&
expires
,
&
expires
);
interval
.
seconds
=
4
;
interval
.
nanoseconds
=
0
;
printf
(
"*** resetting ti3 ***
\n
"
);
INSIST
(
isc_timer_reset
(
ti3
,
isc_timertype_once
,
expires
,
interval
,
ISC_TRUE
)
INSIST
(
isc_timer_reset
(
ti3
,
isc_timertype_once
,
&
expires
,
&
interval
,
ISC_TRUE
)
==
ISC_R_SUCCESS
);
}
...
...
@@ -82,7 +83,7 @@ main(int argc, char *argv[]) {
isc_taskmgr_t
manager
=
NULL
;
isc_timermgr_t
timgr
=
NULL
;
unsigned
int
workers
;
o
s_time
_t
expires
,
interval
,
now
;
s
truct
isc
_time
expires
,
interval
,
now
;
if
(
argc
>
1
)
workers
=
atoi
(
argv
[
1
]);
...
...
@@ -91,36 +92,41 @@ main(int argc, char *argv[]) {
printf
(
"%d workers
\n
"
,
workers
);
INSIST
(
isc_memctx_create
(
0
,
0
,
&
mctx
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_taskmgr_create
(
mctx
,
workers
,
0
,
&
manager
)
==
workers
);
INSIST
(
isc_task_create
(
manager
,
shutdown_task
,
"1"
,
0
,
&
t1
));
INSIST
(
isc_task_create
(
manager
,
shutdown_task
,
"2"
,
0
,
&
t2
));
INSIST
(
isc_task_create
(
manager
,
shutdown_task
,
"3"
,
0
,
&
t3
));
INSIST
(
isc_taskmgr_create
(
mctx
,
workers
,
0
,
&
manager
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
shutdown_task
,
"1"
,
0
,
&
t1
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
shutdown_task
,
"2"
,
0
,
&
t2
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_task_create
(
manager
,
shutdown_task
,
"3"
,
0
,
&
t3
)
==
ISC_R_SUCCESS
);
INSIST
(
isc_timermgr_create
(
mctx
,
&
timgr
)
==
ISC_R_SUCCESS
);
printf
(
"task 1: %p
\n
"
,
t1
);
printf
(
"task 2: %p
\n
"
,
t2
);
printf
(
"task 3: %p
\n
"
,
t3
);
(
void
)
os
_time_get
(
&
now
);
(
void
)
isc
_time_get
(
&
now
);
expires
.
seconds
=
0
;
expires
.
nanoseconds
=
0
;
interval
.
seconds
=
2
;
interval
.
nanoseconds
=
0
;
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_once
,
expires
,
interval
,
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_once
,
&
expires
,
&
interval
,
t2
,
timeout
,
"2"
,
&
ti2
)
==
ISC_R_SUCCESS
);
expires
.
seconds
=
0
;
expires
.
nanoseconds
=
0
;
interval
.
seconds
=
1
;
interval
.
nanoseconds
=
0
;
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_ticker
,
expires
,
interval
,
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_ticker
,
&
expires
,
&
interval
,
t1
,
tick
,
"1"
,
&
ti1
)
==
ISC_R_SUCCESS
);
expires
.
seconds
=
10
;
expires
.
nanoseconds
=
0
;
os
_time_add
(
&
now
,
&
expires
,
&
expires
);
isc
_time_add
(
&
now
,
&
expires
,
&
expires
);
interval
.
seconds
=
2
;
interval
.
nanoseconds
=
0
;
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_once
,
expires
,
interval
,
INSIST
(
isc_timer_create
(
timgr
,
isc_timertype_once
,
&
expires
,
&
interval
,
t3
,
timeout
,
"3"
,
&
ti3
)
==
ISC_R_SUCCESS
);
isc_task_detach
(
&
t1
);
...
...
lib/isc/include/isc/result.h
View file @
bf6d2e39
...
...
@@ -9,6 +9,8 @@ typedef unsigned int isc_result_t;
#define ISC_R_SUCCESS 0
#define ISC_R_NOMEMORY 1
#define ISC_R_TIMEDOUT 2
#define ISC_R_NOTHREADS 3
#define ISC_R_UNEXPECTED 0xFFFFFFFFL
#define isc_result_totext __isc_result_totext
...
...
lib/isc/include/isc/task.h
View file @
bf6d2e39
...
...
@@ -8,6 +8,7 @@
#include <isc/memcluster.h>
#include <isc/boolean.h>
#include <isc/result.h>
/***
...
...
@@ -64,16 +65,16 @@ void isc_event_free(isc_event_t *);
*** Tasks.
***/
isc_
boolean
_t
isc_task_create
(
isc_taskmgr_t
,
isc_taskaction_t
,
void
*
,
unsigned
int
,
isc_task_t
*
);
isc_
result
_t
isc_task_create
(
isc_taskmgr_t
,
isc_taskaction_t
,
void
*
,
unsigned
int
,
isc_task_t
*
);
void
isc_task_attach
(
isc_task_t
,
isc_task_t
*
);
void
isc_task_detach
(
isc_task_t
*
);
isc_boolean_t
isc_task_send
(
isc_task_t
,
isc_event_t
*
);
void
isc_task_send
(
isc_task_t
,
isc_event_t
*
);
void
isc_task_purge
(
isc_task_t
,
void
*
,
isc_eventtype_t
);
void
isc_task_shutdown
(
isc_task_t
);
...
...
@@ -83,7 +84,7 @@ void isc_task_destroy(isc_task_t *);
*** Task Manager.
***/
unsigned
in
t
isc_taskmgr_create
(
isc_memctx_t
,
isc_result_
t
isc_taskmgr_create
(
isc_memctx_t
,
unsigned
int
,
unsigned
int
,
isc_taskmgr_t
*
);
...
...
lib/isc/include/isc/timer.h
View file @
bf6d2e39
...
...
@@ -91,8 +91,8 @@ typedef struct isc_timerevent {
isc_result_t
isc_timer_create
(
isc_timermgr_t
manager
,
isc_timertype_t
type
,
os
_time_t
expires
,
os
_time_t
interval
,
isc
_time_t
expires
,
isc
_time_t
interval
,
isc_task_t
task
,
isc_taskaction_t
action
,
void
*
arg
,
...
...
@@ -146,8 +146,8 @@ isc_timer_create(isc_timermgr_t manager,
isc_result_t
isc_timer_reset
(
isc_timer_t
timer
,
isc_timertype_t
type
,
os
_time_t
expires
,
os
_time_t
interval
,
isc
_time_t
expires
,
isc
_time_t
interval
,
isc_boolean_t
purge
);
/*
* Change the timer's type, expires, and interval values to the given
...
...
lib/isc/mem.c
View file @
bf6d2e39
...
...
@@ -32,7 +32,7 @@
#endif
#if !defined(LINT) && !defined(CODECENTER)
static
char
rcsid
[]
__attribute__
((
unused
))
=
"$Id: mem.c,v 1.
6
1998/10/2
1 22:00:56
halley Exp $"
;
static
char
rcsid
[]
__attribute__
((
unused
))
=
"$Id: mem.c,v 1.
7
1998/10/2
2 01:33:03
halley Exp $"
;
#endif
/* not lint */
/*
...
...
@@ -68,7 +68,7 @@ struct isc_memctx {
unsigned
char
*
lowest
;
unsigned
char
*
highest
;
struct
stats
*
stats
;
os
_mutex_t
mutex
;
isc
_mutex_t
mutex
;
};
/* Forward. */
...
...
@@ -84,8 +84,10 @@ static size_t quantize(size_t);
#define TABLE_INCREMENT 1024
#ifdef MULTITHREADED
#define LOCK_CONTEXT(ctx) INSIST(os_mutex_lock(&(ctx)->mutex))
#define UNLOCK_CONTEXT(ctx) INSIST(os_mutex_unlock(&(ctx)->mutex))
#define LOCK_CONTEXT(ctx) \
INSIST(isc_mutex_lock(&(ctx)->mutex) == ISC_R_SUCCESS)
#define UNLOCK_CONTEXT(ctx) \
INSIST(isc_mutex_unlock(&(ctx)->mutex) == ISC_R_SUCCESS)
#else
#define LOCK_CONTEXT(ctx)
#define UNLOCK_CONTEXT(ctx)
...
...
@@ -152,12 +154,12 @@ isc_memctx_create(size_t init_max_size, size_t target_size,
ctx
->
basic_table_size
=
0
;
ctx
->
lowest
=
NULL
;
ctx
->
highest
=
NULL
;
if
(
!
os
_mutex_init
(
&
ctx
->
mutex
))
{
if
(
isc
_mutex_init
(
&
ctx
->
mutex
)
!=
ISC_R_SUCCESS
)
{
free
(
ctx
->
stats
);
free
(
ctx
->
freelists
);
free
(
ctx
);
UNEXPECTED_ERROR
(
__FILE__
,
__LINE__
,
"
os
_mutex_init() failed"
);
"
isc
_mutex_init() failed"
);
return
(
ISC_R_UNEXPECTED
);
}
*
ctxp
=
ctx
;
...
...
@@ -181,7 +183,7 @@ isc_memctx_destroy(isc_memctx_t *ctxp) {
free
(
ctx
->
freelists
);
free
(
ctx
->
stats
);
free
(
ctx
->
basic_table
);
(
void
)
os
_mutex_destroy
(
&
ctx
->
mutex
);
(
void
)
isc
_mutex_destroy
(
&
ctx
->
mutex
);
free
(
ctx
);
*
ctxp
=
NULL
;
...
...
@@ -453,8 +455,7 @@ meminit(size_t init_max_size, size_t target_size) {
/* need default_context lock here */
if
(
default_context
!=
NULL
)
return
(
-
1
);
return
(
isc_mem_create
(
init_max_size
,
target_size
,
&
default_context
));
return
(
isc_mem_create
(
init_max_size
,
target_size
,
&
default_context
));
}
isc_memctx_t
...
...
lib/isc/pthreads/condition.c
View file @
bf6d2e39
#include <isc/condition.h>
#include <errno.h>
#include <string.h>
#include <isc/condition.h>
#include <isc/unexpect.h>
isc_boolean_t
os_condition_waituntil
(
os_condition_t
*
c
,
os_mutex_t
*
m
,
os_time_t
*
t
,
isc_boolean_t
*
timeout
)
isc_result_t
isc_condition_waituntil
(
isc_condition_t
*
c
,
isc_mutex_t
*
m
,
isc_time_t
t
)
{
int
result
;
int
p
result
;
struct
timespec
ts
;
ts
.
tv_sec
=
t
->
seconds
;
ts
.
tv_nsec
=
t
->
nanoseconds
;
result
=
pthread_cond_timedwait
(
c
,
m
,
&
ts
);
if
(
result
==
0
)
{
*
timeout
=
ISC_FALSE
;
return
(
ISC_TRUE
);
}
else
if
(
result
==
ETIMEDOUT
)
{
*
timeout
=
ISC_TRUE
;
return
(
ISC_TRUE
);
}
return
(
ISC_FALSE
);
presult
=
pthread_cond_timedwait
(
c
,
m
,
&
ts
);
if
(
presult
==
0
)
return
(
ISC_R_SUCCESS
);
if
(
presult
==
ETIMEDOUT
)
return
(
ISC_R_TIMEDOUT
);
UNEXPECTED_ERROR
(
__FILE__
,
__LINE__
,
"pthread_cond_timedwait() returned %s"
,
strerror
(
presult
));
return
(
ISC_R_UNEXPECTED
);
}
lib/isc/pthreads/include/isc/condition.h
View file @
bf6d2e39
#ifndef CONDITION_H
#define CONDITION_H 1
#ifndef
ISC_
CONDITION_H
#define
ISC_
CONDITION_H 1
#include <pthread.h>
#include <isc/boolean.h>
#include <isc/result.h>
#include <isc/mutex.h>
#include <isc/time.h>
typedef
pthread_cond_t
os_condition_t
;
#define OS_CONDITION_INITIALIZER PTHREAD_COND_INITIALIZER
typedef
pthread_cond_t
isc_condition_t
;
#define os_condition_init(cp) (pthread_cond_init((cp), NULL) == 0)
#define os_condition_wait(cp, mp) (pthread_cond_wait((cp), (mp)) == 0)
#define os_condition_signal(cp) (pthread_cond_signal((cp)) == 0)
#define os_condition_broadcast(cp) (pthread_cond_broadcast((cp)) == 0)
#define os_condition_destroy(cp) (pthread_cond_destroy((cp)) == 0)
#define isc_condition_init(cp) \
((pthread_cond_init((cp), NULL) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
isc_boolean_t
os_condition_waituntil
(
os_condition_t
*
,
os_mutex_t
*
,
os_time_t
*
,
isc_boolean_t
*
);
#define isc_condition_wait(cp, mp) \
((pthread_cond_wait((cp), (mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#endif
/* CONDITION_H */
#define isc_condition_signal(cp) \
((pthread_cond_signal((cp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_condition_broadcast(cp) \
((pthread_cond_broadcast((cp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_condition_destroy(cp) \
((pthread_cond_destroy((cp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
isc_result_t
isc_condition_waituntil
(
isc_condition_t
*
,
isc_mutex_t
*
,
isc_time_t
);
#endif
/* ISC_CONDITION_H */
lib/isc/pthreads/include/isc/mutex.h
View file @
bf6d2e39
#ifndef MUTEX_H
#define MUTEX_H 1
#ifndef
ISC_
MUTEX_H
#define
ISC_
MUTEX_H 1
#include <pthread.h>
typedef
pthread_mutex_t
os_mutex_t
;
#define OS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#include <isc/result.h>
#define os_mutex_init(mp) (pthread_mutex_init((mp), NULL) == 0)
#define os_mutex_lock(mp) (pthread_mutex_lock((mp)) == 0)
#define os_mutex_unlock(mp) (pthread_mutex_unlock((mp)) == 0)
#define os_mutex_destroy(mp) (pthread_mutex_destroy((mp)) == 0)
typedef
pthread_mutex_t
isc_mutex_t
;
#endif
/* MUTEX_H */
/* XXX We could do fancier error handling... */
#define isc_mutex_init(mp) \
((pthread_mutex_init((mp), NULL) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_mutex_lock(mp) \
((pthread_mutex_lock((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_mutex_unlock(mp) \
((pthread_mutex_unlock((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_mutex_destroy(mp) \
((pthread_mutex_destroy((mp)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#endif
/* ISC_MUTEX_H */
lib/isc/pthreads/include/isc/thread.h
View file @
bf6d2e39
#ifndef THREAD_H
#define THREAD_H 1
#ifndef
ISC_
THREAD_H
#define
ISC_
THREAD_H 1
#include <pthread.h>
#include <isc/
assertions
.h>
#include <isc/
result
.h>
typedef
pthread_t
os
_thread_t
;
typedef
pthread_t
isc
_thread_t
;
#define os_thread_create(s, a, tp) (pthread_create((tp), NULL, (s), (a)) \
== 0)
#define os_thread_detach(t) (pthread_detach((t)) == 0)
#define os_thread_join(t) (pthread_join((t), NULL) == 0)
#define os_thread_self pthread_self
/* XXX We could do fancier error handling... */
#endif
/* THREAD_H */
#define isc_thread_create(s, a, tp) \
((pthread_create((tp), NULL, (s), (a)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_thread_detach(t) \
((pthread_detach((t)) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_thread_join(t) \
((pthread_join((t), NULL) == 0) ? \
ISC_R_SUCCESS : ISC_R_UNEXPECTED)
#define isc_thread_self \
pthread_self
#endif
/* ISC_THREAD_H */
lib/isc/task.c
View file @
bf6d2e39
...
...
@@ -6,7 +6,7 @@
#include <isc/thread.h>
#include <isc/mutex.h>
#include <isc/condition.h>
#include <isc/unexpect.h>
#include <isc/task.h>
...
...
@@ -15,20 +15,28 @@
***/
/*
* We use macros instead of calling the
os_
routines directly because
* We use macros instead of calling the routines directly because
* the capital letters make the locking stand out.
*
* We INSIST that they succeed since there's no way for us to continue
* if they fail.
*/
#define LOCK(lp) INSIST(os_mutex_lock((lp)))
#define UNLOCK(lp) INSIST(os_mutex_unlock((lp)))
#define WAIT(cvp, lp) INSIST(os_condition_wait((cvp), (lp)))
#define BROADCAST(cvp) INSIST(os_condition_broadcast((cvp)))
#define LOCK(lp) \
INSIST(isc_mutex_lock((lp)) == ISC_R_SUCCESS);
#define UNLOCK(lp) \
INSIST(isc_mutex_unlock((lp)) == ISC_R_SUCCESS);
#define BROADCAST(cvp) \
INSIST(isc_condition_broadcast((cvp)) == ISC_R_SUCCESS);
#define WAIT(cvp, lp) \
INSIST(isc_condition_wait((cvp), (lp)) == ISC_R_SUCCESS);
#define WAITUNTIL(cvp, lp, tp, bp) \
INSIST(isc_condition_waituntil((cvp), (lp), (tp), (bp)) == \
ISC_R_SUCCESS);
#ifdef ISC_TASK_TRACE
#define XTRACE(m) printf("%s task %p thread %p\n", (m), \
task,
os
_thread_self())
task,
isc
_thread_self())
#else
#define XTRACE(m)
#endif
...
...
@@ -51,7 +59,7 @@ struct isc_task {
/* Not locked. */
unsigned
int
magic
;
isc_taskmgr_t
manager
;
os
_mutex_t
lock
;
isc
_mutex_t
lock
;
/* Locked by task lock. */
task_state_t
state
;
unsigned
int
references
;
...
...
@@ -72,15 +80,15 @@ struct isc_taskmgr {
/* Not locked. */
unsigned
int
magic
;
isc_memctx_t
mctx
;
os
_mutex_t
lock
;
isc
_mutex_t
lock
;
/* Locked by task manager lock. */
unsigned
int
default_quantum
;
LIST
(
struct
isc_task
)
tasks
;
LIST
(
struct
isc_task
)
ready_tasks
;
os
_condition_t
work_available
;
isc
_condition_t
work_available
;
isc_boolean_t
exiting
;
unsigned
int
workers
;
os
_condition_t
no_workers
;
isc
_condition_t
no_workers
;
};
#define DEFAULT_DEFAULT_QUANTUM 5
...
...
@@ -160,14 +168,14 @@ task_free(isc_task_t task) {
BROADCAST
(
&
manager
->
work_available
);
}
UNLOCK
(
&
manager
->
lock
);
(
void
)
os
_mutex_destroy
(
&
task
->
lock
);
(
void
)
isc
_mutex_destroy
(
&
task
->
lock
);
if
(
task
->
shutdown_event
!=
NULL
)
isc_event_free
(
&
task
->
shutdown_event
);
task
->
magic
=
0
;
isc_mem_put
(
manager
->
mctx
,
task
,
sizeof
*
task
);
}
isc_
boolean
_t
isc_
result
_t
isc_task_create
(
isc_taskmgr_t
manager
,
isc_taskaction_t
shutdown_action
,
void
*
shutdown_arg
,
unsigned
int
quantum
,
isc_task_t
*
taskp
)
{
...
...
@@ -178,13 +186,15 @@ isc_task_create(isc_taskmgr_t manager, isc_taskaction_t shutdown_action,
task
=
isc_mem_get
(
manager
->
mctx
,
sizeof
*
task
);
if
(
task
==
NULL
)
return
(
ISC_
FALSE
);
return
(
ISC_
R_NOMEMORY
);
task
->
magic
=
TASK_MAGIC
;
task
->
manager
=
manager
;
if
(
!
os
_mutex_init
(
&
task
->
lock
))
{
if
(
isc
_mutex_init
(
&
task
->
lock
)
!=
ISC_R_SUCCESS
)
{
isc_mem_put
(
manager
->
mctx
,
task
,
sizeof
*
task
);
return
(
ISC_FALSE
);
UNEXPECTED_ERROR
(
__FILE__
,
__LINE__
,
"isc_mutex_init() failed"
);
return
(
ISC_R_UNEXPECTED
);
}
task
->
state
=
task_state_idle
;
task
->
references
=
1
;
...
...
@@ -198,9 +208,9 @@ isc_task_create(isc_taskmgr_t manager, isc_taskaction_t shutdown_action,
shutdown_arg
,
sizeof
*
task
->
shutdown_event
);
if
(
task
->
shutdown_event
==
NULL
)
{
(
void
)
os
_mutex_destroy
(
&
task
->
lock
);
(
void
)
isc
_mutex_destroy
(
&
task
->
lock
);
isc_mem_put
(
manager
->
mctx
,
task
,
sizeof
*
task
);
return
(
ISC_
FALSE
);
return
(
ISC_
R_NOMEMORY
);
}
INIT_LINK
(
task
,
link
);
INIT_LINK
(
task
,
ready_link
);
...
...
@@ -213,7 +223,7 @@ isc_task_create(isc_taskmgr_t manager, isc_taskaction_t shutdown_action,
*
taskp
=
task
;
return
(
ISC_
TRUE
);
return
(
ISC_
R_SUCCESS
);
}
void
...
...
@@ -253,7 +263,7 @@ isc_task_detach(isc_task_t *taskp) {
*
taskp
=
NULL
;
}
isc_boolean_t
void
isc_task_send
(
isc_task_t
task
,
isc_event_t
*
eventp
)
{
isc_boolean_t
was_idle
=
ISC_FALSE
;
isc_boolean_t
discard
=
ISC_FALSE
;
...
...
@@ -289,7 +299,7 @@ isc_task_send(isc_task_t task, isc_event_t *eventp) {
if
(
discard
)
{
isc_event_free
(
&
event
);
*
eventp
=
NULL
;
return
(
ISC_TRUE
)
;
return
;
}
if
(
was_idle
)
{
...
...
@@ -335,7 +345,6 @@ isc_task_send(isc_task_t task, isc_event_t *eventp) {
*
eventp
=
NULL
;
XTRACE
(
"sent"
);
return
(
ISC_TRUE
);
}
void
...
...
@@ -685,49 +694,55 @@ void *run(void *uap) {
static
void
manager_free
(
isc_taskmgr_t
manager
)
{
(
void
)
os
_condition_destroy
(
&
manager
->
work_available
);
(
void
)
os
_condition_destroy
(
&
manager
->
no_workers
);
(
void
)
os
_mutex_destroy
(
&
manager
->
lock
);
(
void
)
isc
_condition_destroy
(
&
manager
->
work_available
);
(
void
)
isc
_condition_destroy
(
&
manager
->
no_workers
);
(
void
)
isc
_mutex_destroy
(
&
manager
->
lock
);
manager
->
magic
=
0
;
isc_mem_put
(
manager
->
mctx
,
manager
,
sizeof
*
manager
);
}
unsigned
in
t
isc_result_
t
isc_taskmgr_create
(
isc_memctx_t
mctx
,
unsigned
int
workers
,
unsigned
int
default_quantum
,
isc_taskmgr_t
*
managerp
)
{
unsigned
int
i
,
started
=
0
;
isc_taskmgr_t
manager
;
os_thread_t
thread
;
isc_thread_t
thread
;
REQUIRE
(
workers
>
0
);
if
(
workers
==
0
)
return
(
0
);
manager
=
isc_mem_get
(
mctx
,
sizeof
*
manager
);
if
(
manager
==
NULL
)
return
(
0
);
return
(
ISC_R_NOMEMORY
);