* 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()
|
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);
|
kill_thread(fReadThread);
|
||||||
|
}
|
||||||
|
|
||||||
if (fAudioStream) {
|
if (fAudioStream) {
|
||||||
if (fAudioStream->stream)
|
if (fAudioStream->stream)
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ using std::nothrow;
|
|||||||
BGameSound::BGameSound(BGameSoundDevice *device)
|
BGameSound::BGameSound(BGameSoundDevice *device)
|
||||||
: fSound(-1)
|
: fSound(-1)
|
||||||
{
|
{
|
||||||
|
// TODO: device is ignored!
|
||||||
|
// NOTE: BeBook documents that BGameSoundDevice must currently always
|
||||||
|
// be NULL...
|
||||||
fDevice = GetDefaultDevice();
|
fDevice = GetDefaultDevice();
|
||||||
fInitError = fDevice->InitCheck();
|
fInitError = fDevice->InitCheck();
|
||||||
}
|
}
|
||||||
@@ -32,6 +35,7 @@ BGameSound::BGameSound(const BGameSound &other)
|
|||||||
: fSound(-1)
|
: fSound(-1)
|
||||||
{
|
{
|
||||||
memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
|
memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
|
||||||
|
// TODO: device from other is ignored!
|
||||||
fDevice = GetDefaultDevice();
|
fDevice = GetDefaultDevice();
|
||||||
|
|
||||||
fInitError = fDevice->InitCheck();
|
fInitError = fDevice->InitCheck();
|
||||||
@@ -57,6 +61,7 @@ BGameSound::InitCheck() const
|
|||||||
BGameSoundDevice *
|
BGameSoundDevice *
|
||||||
BGameSound::Device() const
|
BGameSound::Device() const
|
||||||
{
|
{
|
||||||
|
// TODO: Must return NULL if default device is being used!
|
||||||
return fDevice;
|
return fDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +69,8 @@ BGameSound::Device() const
|
|||||||
gs_id
|
gs_id
|
||||||
BGameSound::ID() const
|
BGameSound::ID() const
|
||||||
{
|
{
|
||||||
|
// TODO: Should be 0 if no sound has been selected! But fSound
|
||||||
|
// is initialized with -1 in the constructors.
|
||||||
return fSound;
|
return fSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +268,8 @@ BGameSound::operator=(const BGameSound &other)
|
|||||||
fSound = other.fSound;
|
fSound = other.fSound;
|
||||||
fInitError = other.fInitError;
|
fInitError = other.fInitError;
|
||||||
|
|
||||||
|
// TODO: This would need to acquire the sound another time!
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -30,7 +30,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Autolock.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
#include <Locker.h>
|
||||||
#include <MediaRoster.h>
|
#include <MediaRoster.h>
|
||||||
#include <MediaAddOn.h>
|
#include <MediaAddOn.h>
|
||||||
#include <TimeSource.h>
|
#include <TimeSource.h>
|
||||||
@@ -47,11 +49,14 @@ const int32 kGrowth = 16;
|
|||||||
|
|
||||||
static int32 sDeviceCount = 0;
|
static int32 sDeviceCount = 0;
|
||||||
static BGameSoundDevice* sDevice = NULL;
|
static BGameSoundDevice* sDevice = NULL;
|
||||||
|
static BLocker sDeviceRefCountLock = BLocker("GameSound device lock");
|
||||||
|
|
||||||
|
|
||||||
BGameSoundDevice *
|
BGameSoundDevice *
|
||||||
GetDefaultDevice()
|
GetDefaultDevice()
|
||||||
{
|
{
|
||||||
|
BAutolock _(sDeviceRefCountLock);
|
||||||
|
|
||||||
if (!sDevice)
|
if (!sDevice)
|
||||||
sDevice = new BGameSoundDevice();
|
sDevice = new BGameSoundDevice();
|
||||||
|
|
||||||
@@ -63,6 +68,8 @@ GetDefaultDevice()
|
|||||||
void
|
void
|
||||||
ReleaseDevice()
|
ReleaseDevice()
|
||||||
{
|
{
|
||||||
|
BAutolock _(sDeviceRefCountLock);
|
||||||
|
|
||||||
sDeviceCount--;
|
sDeviceCount--;
|
||||||
|
|
||||||
if (sDeviceCount <= 0) {
|
if (sDeviceCount <= 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user