BBufferGroup: rework init error handling
This commit is contained in:
@@ -41,7 +41,8 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
|
|||||||
uint32 lock)
|
uint32 lock)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (_Init() != B_OK)
|
fInitError = _Init();
|
||||||
|
if (fInitError != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// This one is easy. We need to create "count" BBuffers,
|
// This one is easy. We need to create "count" BBuffers,
|
||||||
@@ -94,7 +95,8 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
|
|||||||
BBufferGroup::BBufferGroup()
|
BBufferGroup::BBufferGroup()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (_Init() != B_OK)
|
fInitError = _Init();
|
||||||
|
if (fInitError != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// this one simply creates an empty BBufferGroup
|
// this one simply creates an empty BBufferGroup
|
||||||
@@ -104,13 +106,11 @@ BBufferGroup::BBufferGroup()
|
|||||||
BBufferGroup::BBufferGroup(int32 count, const media_buffer_id* buffers)
|
BBufferGroup::BBufferGroup(int32 count, const media_buffer_id* buffers)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (_Init() != B_OK)
|
fInitError = _Init();
|
||||||
|
if (fInitError != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: we need to make sure that a media_buffer_id is only added
|
// This one creates "BBuffer"s from "media_buffer_id"s passed
|
||||||
// once to each group
|
|
||||||
|
|
||||||
// this one creates "BBuffer"s from "media_buffer_id"s passed
|
|
||||||
// by the application.
|
// by the application.
|
||||||
|
|
||||||
buffer_clone_info info;
|
buffer_clone_info info;
|
||||||
@@ -170,15 +170,11 @@ BBufferGroup::RequestBuffer(size_t size, bigtime_t timeout)
|
|||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BBuffer *buffer;
|
BBuffer *buffer = NULL;
|
||||||
status_t status;
|
fRequestError = fBufferList->RequestBuffer(fReclaimSem, fBufferCount,
|
||||||
|
size, 0, &buffer, timeout);
|
||||||
|
|
||||||
buffer = NULL;
|
return fRequestError == B_OK ? buffer : NULL;
|
||||||
status = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, size, 0,
|
|
||||||
&buffer, timeout);
|
|
||||||
fRequestError = status;
|
|
||||||
|
|
||||||
return status == B_OK ? buffer : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -192,12 +188,10 @@ BBufferGroup::RequestBuffer(BBuffer* buffer, bigtime_t timeout)
|
|||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
status_t status;
|
fRequestError = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, 0, 0,
|
||||||
status = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, 0, 0,
|
|
||||||
&buffer, timeout);
|
&buffer, timeout);
|
||||||
fRequestError = status;
|
|
||||||
|
|
||||||
return status;
|
return fRequestError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -353,29 +347,25 @@ BBufferGroup::_Init()
|
|||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
// some defaults in case we drop out early
|
// some defaults in case we drop out early
|
||||||
fBufferList = 0;
|
fBufferList = NULL;
|
||||||
fInitError = B_ERROR;
|
|
||||||
fRequestError = B_ERROR;
|
fRequestError = B_ERROR;
|
||||||
fBufferCount = 0;
|
fBufferCount = 0;
|
||||||
|
|
||||||
// Create the reclaim semaphore
|
// Create the reclaim semaphore
|
||||||
// This is also used as a system wide unique identifier for this group
|
// This is also used as a system wide unique identifier for this group
|
||||||
fReclaimSem = create_sem(0, "buffer reclaim sem");
|
fReclaimSem = create_sem(0, "buffer reclaim sem");
|
||||||
if (fReclaimSem < B_OK) {
|
if (fReclaimSem < 0) {
|
||||||
ERROR("BBufferGroup::InitBufferGroup: couldn't create fReclaimSem\n");
|
ERROR("BBufferGroup::InitBufferGroup: couldn't create fReclaimSem\n");
|
||||||
fInitError = (status_t)fReclaimSem;
|
return (status_t)fReclaimSem;
|
||||||
return fInitError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fBufferList = BPrivate::SharedBufferList::Get();
|
fBufferList = BPrivate::SharedBufferList::Get();
|
||||||
if (fBufferList == NULL) {
|
if (fBufferList == NULL) {
|
||||||
ERROR("BBufferGroup::InitBufferGroup: SharedBufferList::Get() "
|
ERROR("BBufferGroup::InitBufferGroup: SharedBufferList::Get() "
|
||||||
"failed\n");
|
"failed\n");
|
||||||
fInitError = B_ERROR;
|
return B_ERROR;
|
||||||
return fInitError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fInitError = B_OK;
|
return B_OK;
|
||||||
return fInitError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user