Skip to content

Commit

Permalink
BBufferGroup: rework init error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Numerio committed Jul 11, 2015
1 parent 1cc20d8 commit 280c64a
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/kits/media/BufferGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
uint32 lock)
{
CALLED();
if (_Init() != B_OK)
fInitError = _Init();
if (fInitError != B_OK)
return;

// This one is easy. We need to create "count" BBuffers,
Expand Down Expand Up @@ -94,7 +95,8 @@ BBufferGroup::BBufferGroup(size_t size, int32 count, uint32 placement,
BBufferGroup::BBufferGroup()
{
CALLED();
if (_Init() != B_OK)
fInitError = _Init();
if (fInitError != B_OK)
return;

// this one simply creates an empty BBufferGroup
Expand All @@ -104,13 +106,11 @@ BBufferGroup::BBufferGroup()
BBufferGroup::BBufferGroup(int32 count, const media_buffer_id* buffers)
{
CALLED();
if (_Init() != B_OK)
fInitError = _Init();
if (fInitError != B_OK)
return;

// TODO: we need to make sure that a media_buffer_id is only added
// once to each group

// this one creates "BBuffer"s from "media_buffer_id"s passed
// This one creates "BBuffer"s from "media_buffer_id"s passed
// by the application.

buffer_clone_info info;
Expand Down Expand Up @@ -170,15 +170,11 @@ BBufferGroup::RequestBuffer(size_t size, bigtime_t timeout)
if (size <= 0)
return NULL;

BBuffer *buffer;
status_t status;
BBuffer *buffer = NULL;
fRequestError = fBufferList->RequestBuffer(fReclaimSem, fBufferCount,
size, 0, &buffer, timeout);

buffer = NULL;
status = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, size, 0,
&buffer, timeout);
fRequestError = status;

return status == B_OK ? buffer : NULL;
return fRequestError == B_OK ? buffer : NULL;
}


Expand All @@ -192,12 +188,10 @@ BBufferGroup::RequestBuffer(BBuffer* buffer, bigtime_t timeout)
if (buffer == NULL)
return B_BAD_VALUE;

status_t status;
status = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, 0, 0,
fRequestError = fBufferList->RequestBuffer(fReclaimSem, fBufferCount, 0, 0,
&buffer, timeout);
fRequestError = status;

return status;
return fRequestError;
}


Expand Down Expand Up @@ -353,29 +347,25 @@ BBufferGroup::_Init()
CALLED();

// some defaults in case we drop out early
fBufferList = 0;
fInitError = B_ERROR;
fBufferList = NULL;
fRequestError = B_ERROR;
fBufferCount = 0;

// Create the reclaim semaphore
// This is also used as a system wide unique identifier for this group
fReclaimSem = create_sem(0, "buffer reclaim sem");
if (fReclaimSem < B_OK) {
if (fReclaimSem < 0) {
ERROR("BBufferGroup::InitBufferGroup: couldn't create fReclaimSem\n");
fInitError = (status_t)fReclaimSem;
return fInitError;
return (status_t)fReclaimSem;
}

fBufferList = BPrivate::SharedBufferList::Get();
if (fBufferList == NULL) {
ERROR("BBufferGroup::InitBufferGroup: SharedBufferList::Get() "
"failed\n");
fInitError = B_ERROR;
return fInitError;
return B_ERROR;
}

fInitError = B_OK;
return fInitError;
return B_OK;
}

0 comments on commit 280c64a

Please sign in to comment.