Some cleanup (made static variables static).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13087 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-06-13 12:59:11 +00:00
parent 1f1ed1c62c
commit ff9fb62471
+25 -24
View File
@@ -1,23 +1,24 @@
/* /*
** Copyright 2003-2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2003-2005, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License. * Distributed under the terms of the MIT License.
*/ */
#include <KernelExport.h> #include <KernelExport.h>
#include <malloc.h>
#include <signal.h> #include <signal.h>
#include <kernel_daemon.h> #include <kernel_daemon.h>
#include <lock.h> #include <lock.h>
#include <util/list.h> #include <util/list.h>
#include <stdlib.h>
// ToDo: the use of snooze() in the kernel_daemon() function is very inaccurate, of
// course - the time the daemons need to execute add up in each iteration. // The use of snooze() in the kernel_daemon() function is very inaccurate, of
// But since the kernel daemon is documented to be very inaccurate, this actually // course - the time the daemons need to execute add up in each iteration.
// might be okay (and that's why it's implemented this way now :-). // But since the kernel daemon is documented to be very inaccurate, this
// BeOS R5 seems to do it in the same way, anyway. // actually might be okay (and that's why it's implemented this way now :-).
// BeOS R5 seems to do it in the same way, anyway.
struct daemon { struct daemon {
@@ -29,8 +30,8 @@ struct daemon {
}; };
mutex gDaemonMutex; static mutex sDaemonMutex;
struct list gDaemons; static struct list sDaemons;
static int32 static int32
@@ -41,14 +42,14 @@ kernel_daemon(void *data)
while (true) { while (true) {
struct daemon *daemon = NULL; struct daemon *daemon = NULL;
mutex_lock(&gDaemonMutex); mutex_lock(&sDaemonMutex);
// iterate through the list and execute each daemon if needed // iterate through the list and execute each daemon if needed
while ((daemon = list_get_next_item(&gDaemons, daemon)) != NULL) { while ((daemon = list_get_next_item(&sDaemons, daemon)) != NULL) {
if (((iteration + daemon->offset) % daemon->frequency) == 0) if (((iteration + daemon->offset) % daemon->frequency) == 0)
daemon->function(daemon->arg, iteration); daemon->function(daemon->arg, iteration);
} }
mutex_unlock(&gDaemonMutex); mutex_unlock(&sDaemonMutex);
iteration++; iteration++;
snooze(100000); // 0.1 seconds snooze(100000); // 0.1 seconds
@@ -61,18 +62,18 @@ unregister_kernel_daemon(daemon_hook function, void *arg)
{ {
struct daemon *daemon = NULL; struct daemon *daemon = NULL;
mutex_lock(&gDaemonMutex); mutex_lock(&sDaemonMutex);
// search for the daemon and remove it from the list // search for the daemon and remove it from the list
while ((daemon = list_get_next_item(&gDaemons, daemon)) != NULL) { while ((daemon = list_get_next_item(&sDaemons, daemon)) != NULL) {
if (daemon->function == function && daemon->arg == arg) { if (daemon->function == function && daemon->arg == arg) {
// found it! // found it!
list_remove_item(&gDaemons, daemon); list_remove_item(&sDaemons, daemon);
free(daemon); free(daemon);
break; break;
} }
} }
mutex_unlock(&gDaemonMutex); mutex_unlock(&sDaemonMutex);
// if we've iterated through the whole list, we didn't // if we've iterated through the whole list, we didn't
// find the daemon, and "daemon" is NULL // find the daemon, and "daemon" is NULL
@@ -96,7 +97,7 @@ register_kernel_daemon(daemon_hook function, void *arg, int frequency)
daemon->arg = arg; daemon->arg = arg;
daemon->frequency = frequency; daemon->frequency = frequency;
mutex_lock(&gDaemonMutex); mutex_lock(&sDaemonMutex);
if (frequency > 1) { if (frequency > 1) {
// we try to balance the work-load for each daemon run // we try to balance the work-load for each daemon run
@@ -105,7 +106,7 @@ register_kernel_daemon(daemon_hook function, void *arg, int frequency)
struct daemon *d = NULL; struct daemon *d = NULL;
int32 num = 0; int32 num = 0;
while ((d = list_get_next_item(&gDaemons, d)) != NULL) { while ((d = list_get_next_item(&sDaemons, d)) != NULL) {
if (d->frequency == frequency) if (d->frequency == frequency)
num++; num++;
} }
@@ -114,8 +115,8 @@ register_kernel_daemon(daemon_hook function, void *arg, int frequency)
} else } else
daemon->offset = 0; daemon->offset = 0;
list_add_item(&gDaemons, daemon); list_add_item(&sDaemons, daemon);
mutex_unlock(&gDaemonMutex); mutex_unlock(&sDaemonMutex);
return B_OK; return B_OK;
} }
@@ -126,10 +127,10 @@ kernel_daemon_init(void)
{ {
thread_id thread; thread_id thread;
if (mutex_init(&gDaemonMutex, "kernel daemon") < B_OK) if (mutex_init(&sDaemonMutex, "kernel daemon") < B_OK)
return B_ERROR; return B_ERROR;
list_init(&gDaemons); list_init(&sDaemons);
thread = spawn_kernel_thread(&kernel_daemon, "kernel daemon", B_LOW_PRIORITY, NULL); thread = spawn_kernel_thread(&kernel_daemon, "kernel daemon", B_LOW_PRIORITY, NULL);
send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE);