From 3c4a3ce31c1017c606e84659e65323b35aee04b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 11 Oct 2008 14:58:12 +0000 Subject: [PATCH] * correctly init ref_count on driver settings handles * unload settings when ref_count is zero and boot device is available git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27969 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/os/driver_settings.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/system/libroot/os/driver_settings.c b/src/system/libroot/os/driver_settings.c index 92445748f0..91e8eafd9a 100644 --- a/src/system/libroot/os/driver_settings.c +++ b/src/system/libroot/os/driver_settings.c @@ -39,6 +39,7 @@ # include # include # include +# include #endif #ifdef _BOOT_MODE # include @@ -405,6 +406,7 @@ new_settings(char *buffer, const char *driverName) handle->text = buffer; #ifdef _KERNEL_MODE + handle->ref_count = 1; strlcpy(handle->name, driverName, sizeof(handle->name)); #endif @@ -644,6 +646,8 @@ driver_settings_init(kernel_args *args) strlcpy(handle->name, settings->name, sizeof(handle->name)); handle->magic = 0; + handle->ref_count = 0; + // this triggers parsing the settings when they are actually used list_add_item(&sHandles, handle); @@ -659,19 +663,18 @@ driver_settings_init(kernel_args *args) status_t -unload_driver_settings(void *handle) +unload_driver_settings(void *_handle) { + settings_handle *handle = (settings_handle *)_handle; if (!check_handle(handle)) return B_BAD_VALUE; #ifdef _KERNEL_MODE mutex_lock(&sLock); - // ToDo: as soon as "/boot" is accessible, we should start throwing away settings -#if 0 - if (--handle->ref_count == 0) { + if (--handle->ref_count == 0 && gBootDevice > 0) { + // don't unload an handle when /boot is not available list_remove_link(&handle->link); } else -#endif handle = NULL; mutex_unlock(&sLock); #endif @@ -696,7 +699,10 @@ load_driver_settings(const char *driverName) // see if we already have these settings loaded mutex_lock(&sLock); handle = find_driver_settings(driverName); - if (handle != NULL) { + if (handle != NULL && handle->ref_count == 0 && gBootDevice > 0) { + // an handle with a zero ref_count should be unloaded if /boot is available + free_settings(handle); + } else if (handle != NULL) { handle->ref_count++; // we got it, now let's see if it already has been parsed