* Added a couple TODOs after reading a bit in the source.
* Introduced a lock in GetDefaultDevice() and ReleaseDevice() as a quick solution to the race condition in those functions. It could also use proper atomic ref counting. Untested. * Automatic white space cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31060 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -151,8 +151,13 @@ BFileGameSound::BFileGameSound(const char *file,
|
||||
|
||||
BFileGameSound::~BFileGameSound()
|
||||
{
|
||||
if (fReadThread >= 0)
|
||||
if (fReadThread >= 0) {
|
||||
// TODO: kill_thread() is very bad, since it will leak any resources
|
||||
// that the thread had allocated. It will also keep locks locked that
|
||||
// the thread holds! Set a flag to make the thread quit and use
|
||||
// wait_for_thread() here!
|
||||
kill_thread(fReadThread);
|
||||
}
|
||||
|
||||
if (fAudioStream) {
|
||||
if (fAudioStream->stream)
|
||||
|
||||
@@ -23,6 +23,9 @@ using std::nothrow;
|
||||
BGameSound::BGameSound(BGameSoundDevice *device)
|
||||
: fSound(-1)
|
||||
{
|
||||
// TODO: device is ignored!
|
||||
// NOTE: BeBook documents that BGameSoundDevice must currently always
|
||||
// be NULL...
|
||||
fDevice = GetDefaultDevice();
|
||||
fInitError = fDevice->InitCheck();
|
||||
}
|
||||
@@ -32,6 +35,7 @@ BGameSound::BGameSound(const BGameSound &other)
|
||||
: fSound(-1)
|
||||
{
|
||||
memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
|
||||
// TODO: device from other is ignored!
|
||||
fDevice = GetDefaultDevice();
|
||||
|
||||
fInitError = fDevice->InitCheck();
|
||||
@@ -57,6 +61,7 @@ BGameSound::InitCheck() const
|
||||
BGameSoundDevice *
|
||||
BGameSound::Device() const
|
||||
{
|
||||
// TODO: Must return NULL if default device is being used!
|
||||
return fDevice;
|
||||
}
|
||||
|
||||
@@ -64,6 +69,8 @@ BGameSound::Device() const
|
||||
gs_id
|
||||
BGameSound::ID() const
|
||||
{
|
||||
// TODO: Should be 0 if no sound has been selected! But fSound
|
||||
// is initialized with -1 in the constructors.
|
||||
return fSound;
|
||||
}
|
||||
|
||||
@@ -261,6 +268,8 @@ BGameSound::operator=(const BGameSound &other)
|
||||
fSound = other.fSound;
|
||||
fInitError = other.fInitError;
|
||||
|
||||
// TODO: This would need to acquire the sound another time!
|
||||
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Autolock.h>
|
||||
#include <List.h>
|
||||
#include <Locker.h>
|
||||
#include <MediaRoster.h>
|
||||
#include <MediaAddOn.h>
|
||||
#include <TimeSource.h>
|
||||
@@ -47,11 +49,14 @@ const int32 kGrowth = 16;
|
||||
|
||||
static int32 sDeviceCount = 0;
|
||||
static BGameSoundDevice* sDevice = NULL;
|
||||
static BLocker sDeviceRefCountLock = BLocker("GameSound device lock");
|
||||
|
||||
|
||||
BGameSoundDevice *
|
||||
GetDefaultDevice()
|
||||
{
|
||||
BAutolock _(sDeviceRefCountLock);
|
||||
|
||||
if (!sDevice)
|
||||
sDevice = new BGameSoundDevice();
|
||||
|
||||
@@ -63,6 +68,8 @@ GetDefaultDevice()
|
||||
void
|
||||
ReleaseDevice()
|
||||
{
|
||||
BAutolock _(sDeviceRefCountLock);
|
||||
|
||||
sDeviceCount--;
|
||||
|
||||
if (sDeviceCount <= 0) {
|
||||
|
||||
Reference in New Issue
Block a user