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
This commit is contained in:
parent
65f8356f78
commit
f6fed308e3
@ -37,6 +37,11 @@
|
|||||||
static const char *kPartitioningSystemPrefix = "partitioning_systems";
|
static const char *kPartitioningSystemPrefix = "partitioning_systems";
|
||||||
static const char *kFileSystemPrefix = "file_systems";
|
static const char *kFileSystemPrefix = "file_systems";
|
||||||
|
|
||||||
|
|
||||||
|
// singleton instance
|
||||||
|
KDiskDeviceManager *KDiskDeviceManager::sDefaultManager = NULL;
|
||||||
|
|
||||||
|
|
||||||
// is_active_job_status
|
// is_active_job_status
|
||||||
static
|
static
|
||||||
bool
|
bool
|
||||||
@ -200,38 +205,43 @@ KDiskDeviceManager::InitCheck() const
|
|||||||
return (fLock.Sem() >= 0 ? B_OK : fLock.Sem());
|
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
|
status_t
|
||||||
KDiskDeviceManager::CreateDefault()
|
KDiskDeviceManager::CreateDefault()
|
||||||
{
|
{
|
||||||
status_t error = B_OK;
|
if (sDefaultManager != NULL)
|
||||||
if (!fDefaultManager) {
|
return B_OK;
|
||||||
fDefaultManager = new(nothrow) KDiskDeviceManager;
|
|
||||||
if (fDefaultManager) {
|
sDefaultManager = new(nothrow) KDiskDeviceManager;
|
||||||
error = fDefaultManager->InitCheck();
|
if (sDefaultManager == NULL)
|
||||||
if (error != B_OK)
|
return B_NO_MEMORY;
|
||||||
DeleteDefault();
|
|
||||||
} else
|
return sDefaultManager->InitCheck();
|
||||||
error = B_NO_MEMORY;
|
|
||||||
}
|
|
||||||
return (fDefaultManager ? B_OK : B_NO_MEMORY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteDefault
|
|
||||||
|
/** This deletes the default DiskDeviceManager. The
|
||||||
|
* deletion is not thread-safe either, you should
|
||||||
|
* make sure that it's called only once.
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
KDiskDeviceManager::DeleteDefault()
|
KDiskDeviceManager::DeleteDefault()
|
||||||
{
|
{
|
||||||
if (fDefaultManager) {
|
delete sDefaultManager;
|
||||||
delete fDefaultManager;
|
sDefaultManager = NULL;
|
||||||
fDefaultManager = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default
|
// Default
|
||||||
KDiskDeviceManager *
|
KDiskDeviceManager *
|
||||||
KDiskDeviceManager::Default()
|
KDiskDeviceManager::Default()
|
||||||
{
|
{
|
||||||
return fDefaultManager;
|
return sDefaultManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock
|
// Lock
|
||||||
@ -906,9 +916,11 @@ KDiskDeviceManager::_AddFileSystem(const char *name)
|
|||||||
{
|
{
|
||||||
if (!name)
|
if (!name)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
KDiskSystem *diskSystem = new(nothrow) KFileSystem(name);
|
KDiskSystem *diskSystem = new(nothrow) KFileSystem(name);
|
||||||
if (!diskSystem)
|
if (!diskSystem)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
return _AddDiskSystem(diskSystem);
|
return _AddDiskSystem(diskSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1132,7 +1144,3 @@ KDiskDeviceManager::_ScanPartition(KPartition *partition)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// singleton instance
|
|
||||||
KDiskDeviceManager *KDiskDeviceManager::fDefaultManager = NULL;
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user