From f6fed308e34cbaf99ebf34ab997fa35c11575f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 12 Jun 2004 20:57:11 +0000 Subject: [PATCH] Rewrote KDiskDeviceManager::CreateDefault() to be easier to read and actually return the correct error code in case there is one. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7932 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../KDiskDeviceManager.cpp | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp index 85a03e7b61..8a11fa9f64 100644 --- a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp @@ -37,6 +37,11 @@ static const char *kPartitioningSystemPrefix = "partitioning_systems"; static const char *kFileSystemPrefix = "file_systems"; + +// singleton instance +KDiskDeviceManager *KDiskDeviceManager::sDefaultManager = NULL; + + // is_active_job_status static bool @@ -200,38 +205,43 @@ KDiskDeviceManager::InitCheck() const return (fLock.Sem() >= 0 ? B_OK : fLock.Sem()); } -// CreateDefault + +/** This creates the system's default DiskDeviceManager. + * The creation is not thread-safe, and shouldn't be done + * more than once. + */ + status_t KDiskDeviceManager::CreateDefault() { - status_t error = B_OK; - if (!fDefaultManager) { - fDefaultManager = new(nothrow) KDiskDeviceManager; - if (fDefaultManager) { - error = fDefaultManager->InitCheck(); - if (error != B_OK) - DeleteDefault(); - } else - error = B_NO_MEMORY; - } - return (fDefaultManager ? B_OK : B_NO_MEMORY); + if (sDefaultManager != NULL) + return B_OK; + + sDefaultManager = new(nothrow) KDiskDeviceManager; + if (sDefaultManager == NULL) + return B_NO_MEMORY; + + return sDefaultManager->InitCheck(); } -// DeleteDefault + +/** This deletes the default DiskDeviceManager. The + * deletion is not thread-safe either, you should + * make sure that it's called only once. + */ + void KDiskDeviceManager::DeleteDefault() { - if (fDefaultManager) { - delete fDefaultManager; - fDefaultManager = NULL; - } + delete sDefaultManager; + sDefaultManager = NULL; } // Default KDiskDeviceManager * KDiskDeviceManager::Default() { - return fDefaultManager; + return sDefaultManager; } // Lock @@ -906,9 +916,11 @@ KDiskDeviceManager::_AddFileSystem(const char *name) { if (!name) return B_BAD_VALUE; + KDiskSystem *diskSystem = new(nothrow) KFileSystem(name); if (!diskSystem) return B_NO_MEMORY; + return _AddDiskSystem(diskSystem); } @@ -1132,7 +1144,3 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition) return error; } - -// singleton instance -KDiskDeviceManager *KDiskDeviceManager::fDefaultManager = NULL; -