Commit 5a842a6f authored by Brian Wellington's avatar Brian Wellington

The non-threaded version does a better job avoiding starvation.

parent 2310b796
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: task.c,v 1.73 2000/08/29 22:55:57 bwelling Exp $ */
/* $Id: task.c,v 1.74 2000/08/30 23:47:14 bwelling Exp $ */
/*
* Principal Author: Bob Halley
......@@ -121,6 +121,7 @@ struct isc_taskmgr {
#endif
};
#define DEFAULT_TASKMGR_QUANTUM 10
#define DEFAULT_DEFAULT_QUANTUM 5
#define FINISHED(m) ((m)->exiting && EMPTY((m)->tasks))
......@@ -717,6 +718,9 @@ isc_task_gettag(isc_task_t *task) {
static void
dispatch(isc_taskmgr_t *manager) {
isc_task_t *task;
#ifndef ISC_PLATFORM_USETHREADS
unsigned int total_dispatch_count = 0;
#endif
REQUIRE(VALID_MANAGER(manager));
......@@ -771,10 +775,8 @@ dispatch(isc_taskmgr_t *manager) {
*/
LOCK(&manager->lock);
#ifndef ISC_PLATFORM_USETHREADS
while (!EMPTY(manager->ready_tasks) && !FINISHED(manager)) {
#else
while (!FINISHED(manager)) {
#ifdef ISC_PLATFORM_USETHREADS
/*
* For reasons similar to those given in the comment in
* isc_task_send() above, it is safe for us to dequeue
......@@ -787,6 +789,10 @@ dispatch(isc_taskmgr_t *manager) {
WAIT(&manager->work_available, &manager->lock);
XTHREADTRACE("awake");
}
#else
if (total_dispatch_count >= DEFAULT_TASKMGR_QUANTUM ||
EMPTY(manager->ready_tasks))
break;
#endif
XTHREADTRACE("working");
......@@ -827,6 +833,9 @@ dispatch(isc_taskmgr_t *manager) {
LOCK(&task->lock);
}
dispatch_count++;
#ifndef ISC_PLATFORM_USETHREADS
total_dispatch_count++;
#endif
}
if (task->references == 0 &&
......@@ -1136,7 +1145,8 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
* Dispatch the shutdown events.
*/
UNLOCK(&manager->lock);
isc__taskmgr_dispatch();
while (isc__taskmgr_ready())
(void)isc__taskmgr_dispatch();
#endif
manager_free(manager);
......@@ -1145,6 +1155,13 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
}
#ifndef ISC_PLATFORM_USETHREADS
isc_boolean_t
isc__taskmgr_ready(void) {
if (taskmgr == NULL)
return (ISC_FALSE);
return (ISC_TF(!ISC_LIST_EMPTY(taskmgr->ready_tasks)));
}
isc_result_t
isc__taskmgr_dispatch(void) {
isc_taskmgr_t *manager = taskmgr;
......
......@@ -15,11 +15,14 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: task_p.h,v 1.2 2000/08/29 22:53:59 bwelling Exp $ */
/* $Id: task_p.h,v 1.3 2000/08/30 23:47:15 bwelling Exp $ */
#ifndef ISC_TASK_P_H
#define ISC_TASK_P_H
isc_boolean_t
isc__taskmgr_ready(void);
isc_result_t
isc__taskmgr_dispatch(void);
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: app.c,v 1.27 2000/08/30 01:43:59 bwelling Exp $ */
/* $Id: app.c,v 1.28 2000/08/30 23:47:16 bwelling Exp $ */
#include <config.h>
......@@ -380,29 +380,37 @@ isc_app_run(void) {
int n;
isc_time_t when, now;
struct timeval tv, *tvp;
isc_uint64_t us;
fd_set readfds, writefds;
int maxfd;
isc_boolean_t readytasks;
result = isc__timermgr_nextevent(&when);
if (result != ISC_R_SUCCESS)
tvp = NULL;
else {
(void)isc_time_now(&now);
us = isc_time_microdiff(&when, &now);
tv.tv_sec = us / 1000000;
tv.tv_usec = us % 1000000;
readytasks = isc__taskmgr_ready();
if (readytasks) {
tv.tv_sec = 0;
tv.tv_usec = 0;
tvp = &tv;
} else {
result = isc__timermgr_nextevent(&when);
if (result != ISC_R_SUCCESS)
tvp = NULL;
else {
isc_uint64_t us;
(void)isc_time_now(&now);
us = isc_time_microdiff(&when, &now);
tv.tv_sec = us / 1000000;
tv.tv_usec = us % 1000000;
tvp = &tv;
}
}
isc__socketmgr_getfdsets(&readfds, &writefds, &maxfd);
n = select(maxfd, &readfds, &writefds, NULL, tvp);
if (n == 0)
isc__timermgr_dispatch();
else if (maxfd > 0)
isc__socketmgr_dispatch(&readfds, &writefds, maxfd);
(void)isc__timermgr_dispatch();
if (n > 0)
(void)isc__socketmgr_dispatch(&readfds, &writefds,
maxfd);
(void)isc__taskmgr_dispatch();
if (want_reload) {
......@@ -410,6 +418,8 @@ isc_app_run(void) {
return (ISC_R_RELOAD);
}
}
while (isc__taskmgr_ready())
(void)isc__taskmgr_dispatch();
#endif /* ISC_PLATFORM_USETHREADS */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment