mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 19:08:55 -04:00
thread-protect get_null_sound()
This commit is contained in:
parent
b3c42f22ac
commit
234724321e
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "config_audio.h"
|
#include "config_audio.h"
|
||||||
#include "audioManager.h"
|
#include "audioManager.h"
|
||||||
|
#include "atomicAdjust.h"
|
||||||
#include "nullAudioManager.h"
|
#include "nullAudioManager.h"
|
||||||
|
|
||||||
#include "load_dso.h"
|
#include "load_dso.h"
|
||||||
@ -88,7 +88,21 @@ PT(AudioManager) AudioManager::create_AudioManager() {
|
|||||||
// Access: Published, Virtual
|
// Access: Published, Virtual
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
AudioManager::~AudioManager() {
|
AudioManager::
|
||||||
|
~AudioManager() {
|
||||||
|
if (_null_sound != (AudioSound *)NULL) {
|
||||||
|
unref_delete(_null_sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: AudioManager::Constructor
|
||||||
|
// Access: Protected
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
AudioManager::
|
||||||
|
AudioManager() {
|
||||||
|
_null_sound = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -100,7 +114,8 @@ AudioManager::~AudioManager() {
|
|||||||
// change your mind and want to play sounds again, you
|
// change your mind and want to play sounds again, you
|
||||||
// will have to recreate all of these objects.
|
// will have to recreate all of these objects.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void AudioManager::shutdown() {
|
void AudioManager::
|
||||||
|
shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -111,10 +126,20 @@ void AudioManager::shutdown() {
|
|||||||
// sound. This same object may also be returned by
|
// sound. This same object may also be returned by
|
||||||
// get_sound() if it fails.
|
// get_sound() if it fails.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
PT(AudioSound) AudioManager::get_null_sound() {
|
PT(AudioSound) AudioManager::
|
||||||
|
get_null_sound() {
|
||||||
if (_null_sound == (AudioSound *)NULL) {
|
if (_null_sound == (AudioSound *)NULL) {
|
||||||
_null_sound = new NullAudioSound;
|
AudioSound *new_sound = new NullAudioSound;
|
||||||
|
new_sound->ref();
|
||||||
|
void *result = AtomicAdjust::compare_and_exchange_ptr((void * TVOLATILE &)_null_sound, (void *)NULL, (void *)new_sound);
|
||||||
|
if (result != NULL) {
|
||||||
|
// Someone else must have assigned the AudioSound first. OK.
|
||||||
|
nassertr(_null_sound != new_sound, NULL);
|
||||||
|
unref_delete(new_sound);
|
||||||
}
|
}
|
||||||
|
nassertr(_null_sound != NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return _null_sound;
|
return _null_sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,12 +216,9 @@ protected:
|
|||||||
// best flexibility.
|
// best flexibility.
|
||||||
|
|
||||||
static Create_AudioManager_proc* _create_AudioManager;
|
static Create_AudioManager_proc* _create_AudioManager;
|
||||||
PT(AudioSound) _null_sound;
|
AudioSound *_null_sound;
|
||||||
|
|
||||||
AudioManager() {
|
|
||||||
// intentionally blank.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AudioManager();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user