mirror of
https://github.com/tiennm99/godot.git
synced 2026-08-19 10:23:41 +00:00
Merge pull request #45618 from RandomShaper/modernize_mt_3.2
Backport of all the multi-threading modernization (3.2)
This commit is contained in:
@@ -169,8 +169,7 @@ Error AudioDriverALSA::init() {
|
||||
|
||||
Error err = init_device();
|
||||
if (err == OK) {
|
||||
mutex = Mutex::create();
|
||||
thread = Thread::create(AudioDriverALSA::thread_func, this);
|
||||
thread.start(AudioDriverALSA::thread_func, this);
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -314,16 +313,12 @@ void AudioDriverALSA::set_device(String device) {
|
||||
|
||||
void AudioDriverALSA::lock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
return;
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
void AudioDriverALSA::unlock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
return;
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AudioDriverALSA::finish_device() {
|
||||
@@ -336,25 +331,13 @@ void AudioDriverALSA::finish_device() {
|
||||
|
||||
void AudioDriverALSA::finish() {
|
||||
|
||||
if (thread) {
|
||||
exit_thread = true;
|
||||
Thread::wait_to_finish(thread);
|
||||
|
||||
memdelete(thread);
|
||||
thread = NULL;
|
||||
|
||||
if (mutex) {
|
||||
memdelete(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
}
|
||||
exit_thread = true;
|
||||
thread.wait_to_finish();
|
||||
|
||||
finish_device();
|
||||
}
|
||||
|
||||
AudioDriverALSA::AudioDriverALSA() :
|
||||
thread(NULL),
|
||||
mutex(NULL),
|
||||
pcm_handle(NULL),
|
||||
device_name("Default"),
|
||||
new_device("Default") {
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
|
||||
class AudioDriverALSA : public AudioDriver {
|
||||
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
Thread thread;
|
||||
Mutex mutex;
|
||||
|
||||
snd_pcm_t *pcm_handle;
|
||||
|
||||
|
||||
@@ -148,27 +148,16 @@ Error MIDIDriverALSAMidi::open() {
|
||||
}
|
||||
snd_device_name_free_hint(hints);
|
||||
|
||||
mutex = Mutex::create();
|
||||
exit_thread = false;
|
||||
thread = Thread::create(MIDIDriverALSAMidi::thread_func, this);
|
||||
thread.start(MIDIDriverALSAMidi::thread_func, this);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void MIDIDriverALSAMidi::close() {
|
||||
|
||||
if (thread) {
|
||||
exit_thread = true;
|
||||
Thread::wait_to_finish(thread);
|
||||
|
||||
memdelete(thread);
|
||||
thread = NULL;
|
||||
}
|
||||
|
||||
if (mutex) {
|
||||
memdelete(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
exit_thread = true;
|
||||
thread.wait_to_finish();
|
||||
|
||||
for (int i = 0; i < connected_inputs.size(); i++) {
|
||||
snd_rawmidi_t *midi_in = connected_inputs[i];
|
||||
@@ -179,14 +168,12 @@ void MIDIDriverALSAMidi::close() {
|
||||
|
||||
void MIDIDriverALSAMidi::lock() const {
|
||||
|
||||
if (mutex)
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
void MIDIDriverALSAMidi::unlock() const {
|
||||
|
||||
if (mutex)
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
PoolStringArray MIDIDriverALSAMidi::get_connected_inputs() {
|
||||
@@ -210,9 +197,6 @@ PoolStringArray MIDIDriverALSAMidi::get_connected_inputs() {
|
||||
|
||||
MIDIDriverALSAMidi::MIDIDriverALSAMidi() {
|
||||
|
||||
mutex = NULL;
|
||||
thread = NULL;
|
||||
|
||||
exit_thread = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@
|
||||
|
||||
class MIDIDriverALSAMidi : public MIDIDriver {
|
||||
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
Thread thread;
|
||||
Mutex mutex;
|
||||
|
||||
Vector<snd_rawmidi_t *> connected_inputs;
|
||||
|
||||
|
||||
@@ -69,8 +69,6 @@ OSStatus AudioDriverCoreAudio::output_device_address_cb(AudioObjectID inObjectID
|
||||
#endif
|
||||
|
||||
Error AudioDriverCoreAudio::init() {
|
||||
mutex = Mutex::create();
|
||||
|
||||
AudioComponentDescription desc;
|
||||
zeromem(&desc, sizeof(desc));
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
@@ -280,19 +278,15 @@ AudioDriver::SpeakerMode AudioDriverCoreAudio::get_speaker_mode() const {
|
||||
};
|
||||
|
||||
void AudioDriverCoreAudio::lock() {
|
||||
if (mutex)
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
};
|
||||
|
||||
void AudioDriverCoreAudio::unlock() {
|
||||
if (mutex)
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
};
|
||||
|
||||
bool AudioDriverCoreAudio::try_lock() {
|
||||
if (mutex)
|
||||
return mutex->try_lock() == OK;
|
||||
return true;
|
||||
return mutex.try_lock() == OK;
|
||||
}
|
||||
|
||||
void AudioDriverCoreAudio::finish() {
|
||||
@@ -344,11 +338,6 @@ void AudioDriverCoreAudio::finish() {
|
||||
audio_unit = NULL;
|
||||
unlock();
|
||||
}
|
||||
|
||||
if (mutex) {
|
||||
memdelete(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Error AudioDriverCoreAudio::capture_init() {
|
||||
@@ -691,7 +680,6 @@ AudioDriverCoreAudio::AudioDriverCoreAudio() :
|
||||
audio_unit(NULL),
|
||||
input_unit(NULL),
|
||||
active(false),
|
||||
mutex(NULL),
|
||||
device_name("Default"),
|
||||
capture_device_name("Default"),
|
||||
mix_rate(0),
|
||||
|
||||
@@ -46,7 +46,7 @@ class AudioDriverCoreAudio : public AudioDriver {
|
||||
AudioComponentInstance input_unit;
|
||||
|
||||
bool active;
|
||||
Mutex *mutex;
|
||||
Mutex mutex;
|
||||
|
||||
String device_name;
|
||||
String capture_device_name;
|
||||
|
||||
@@ -294,8 +294,7 @@ Error AudioDriverPulseAudio::init() {
|
||||
|
||||
Error err = init_device();
|
||||
if (err == OK) {
|
||||
mutex = Mutex::create();
|
||||
thread = Thread::create(AudioDriverPulseAudio::thread_func, this);
|
||||
thread.start(AudioDriverPulseAudio::thread_func, this);
|
||||
}
|
||||
|
||||
return OK;
|
||||
@@ -600,16 +599,12 @@ void AudioDriverPulseAudio::set_device(String device) {
|
||||
|
||||
void AudioDriverPulseAudio::lock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
return;
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
void AudioDriverPulseAudio::unlock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
return;
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AudioDriverPulseAudio::finish_device() {
|
||||
@@ -623,11 +618,11 @@ void AudioDriverPulseAudio::finish_device() {
|
||||
|
||||
void AudioDriverPulseAudio::finish() {
|
||||
|
||||
if (!thread)
|
||||
if (!thread.is_started())
|
||||
return;
|
||||
|
||||
exit_thread = true;
|
||||
Thread::wait_to_finish(thread);
|
||||
thread.wait_to_finish();
|
||||
|
||||
finish_device();
|
||||
|
||||
@@ -641,14 +636,6 @@ void AudioDriverPulseAudio::finish() {
|
||||
pa_mainloop_free(pa_ml);
|
||||
pa_ml = NULL;
|
||||
}
|
||||
|
||||
memdelete(thread);
|
||||
if (mutex) {
|
||||
memdelete(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
|
||||
thread = NULL;
|
||||
}
|
||||
|
||||
Error AudioDriverPulseAudio::capture_init_device() {
|
||||
@@ -802,8 +789,6 @@ String AudioDriverPulseAudio::capture_get_device() {
|
||||
}
|
||||
|
||||
AudioDriverPulseAudio::AudioDriverPulseAudio() :
|
||||
thread(NULL),
|
||||
mutex(NULL),
|
||||
pa_ml(NULL),
|
||||
pa_ctx(NULL),
|
||||
pa_str(NULL),
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
|
||||
class AudioDriverPulseAudio : public AudioDriver {
|
||||
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
Thread thread;
|
||||
Mutex mutex;
|
||||
|
||||
pa_mainloop *pa_ml;
|
||||
pa_context *pa_ctx;
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* mutex_posix.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "mutex_posix.h"
|
||||
|
||||
#include "core/os/memory.h"
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
|
||||
|
||||
void MutexPosix::lock() {
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
}
|
||||
void MutexPosix::unlock() {
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
Error MutexPosix::try_lock() {
|
||||
|
||||
return (pthread_mutex_trylock(&mutex) == 0) ? OK : ERR_BUSY;
|
||||
}
|
||||
|
||||
Mutex *MutexPosix::create_func_posix(bool p_recursive) {
|
||||
|
||||
return memnew(MutexPosix(p_recursive));
|
||||
}
|
||||
|
||||
void MutexPosix::make_default() {
|
||||
|
||||
create_func = create_func_posix;
|
||||
}
|
||||
|
||||
MutexPosix::MutexPosix(bool p_recursive) {
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
if (p_recursive)
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mutex, &attr);
|
||||
}
|
||||
|
||||
MutexPosix::~MutexPosix() {
|
||||
|
||||
pthread_mutex_destroy(&mutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,61 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* mutex_posix.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef MUTEX_POSIX_H
|
||||
#define MUTEX_POSIX_H
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
|
||||
|
||||
#include "core/os/mutex.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
class MutexPosix : public Mutex {
|
||||
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
static Mutex *create_func_posix(bool p_recursive);
|
||||
|
||||
public:
|
||||
virtual void lock();
|
||||
virtual void unlock();
|
||||
virtual Error try_lock();
|
||||
|
||||
static void make_default();
|
||||
|
||||
MutexPosix(bool p_recursive);
|
||||
|
||||
~MutexPosix();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -32,14 +32,10 @@
|
||||
|
||||
#ifdef UNIX_ENABLED
|
||||
|
||||
#include "core/os/thread_dummy.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "drivers/unix/mutex_posix.h"
|
||||
#include "drivers/unix/net_socket_posix.h"
|
||||
#include "drivers/unix/rw_lock_posix.h"
|
||||
#include "drivers/unix/semaphore_posix.h"
|
||||
#include "drivers/unix/thread_posix.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
@@ -64,6 +60,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/// Clock Setup function (used by get_ticks_usec)
|
||||
@@ -120,19 +117,10 @@ int OS_Unix::unix_initialize_audio(int p_audio_driver) {
|
||||
|
||||
void OS_Unix::initialize_core() {
|
||||
|
||||
#ifdef NO_THREADS
|
||||
ThreadDummy::make_default();
|
||||
SemaphoreDummy::make_default();
|
||||
MutexDummy::make_default();
|
||||
RWLockDummy::make_default();
|
||||
#else
|
||||
ThreadPosix::make_default();
|
||||
#if !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
|
||||
SemaphorePosix::make_default();
|
||||
#endif
|
||||
MutexPosix::make_default();
|
||||
RWLockPosix::make_default();
|
||||
#if !defined(NO_THREADS)
|
||||
init_thread_posix();
|
||||
#endif
|
||||
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
|
||||
@@ -310,13 +298,9 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
|
||||
|
||||
while (fgets(buf, 65535, f)) {
|
||||
|
||||
if (p_pipe_mutex) {
|
||||
p_pipe_mutex->lock();
|
||||
}
|
||||
p_pipe_mutex->lock();
|
||||
(*r_pipe) += String::utf8(buf);
|
||||
if (p_pipe_mutex) {
|
||||
p_pipe_mutex->unlock();
|
||||
}
|
||||
p_pipe_mutex->unlock();
|
||||
}
|
||||
int rv = pclose(f);
|
||||
if (r_exitcode)
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_posix.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
|
||||
|
||||
#include "rw_lock_posix.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
#include "core/os/memory.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void RWLockPosix::read_lock() {
|
||||
|
||||
int err = pthread_rwlock_rdlock(&rwlock);
|
||||
if (err != 0) {
|
||||
perror("Acquiring lock failed");
|
||||
}
|
||||
ERR_FAIL_COND(err != 0);
|
||||
}
|
||||
|
||||
void RWLockPosix::read_unlock() {
|
||||
|
||||
pthread_rwlock_unlock(&rwlock);
|
||||
}
|
||||
|
||||
Error RWLockPosix::read_try_lock() {
|
||||
|
||||
if (pthread_rwlock_tryrdlock(&rwlock) != 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
void RWLockPosix::write_lock() {
|
||||
|
||||
int err = pthread_rwlock_wrlock(&rwlock);
|
||||
ERR_FAIL_COND(err != 0);
|
||||
}
|
||||
|
||||
void RWLockPosix::write_unlock() {
|
||||
|
||||
pthread_rwlock_unlock(&rwlock);
|
||||
}
|
||||
|
||||
Error RWLockPosix::write_try_lock() {
|
||||
if (pthread_rwlock_trywrlock(&rwlock) != 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
RWLock *RWLockPosix::create_func_posix() {
|
||||
|
||||
return memnew(RWLockPosix);
|
||||
}
|
||||
|
||||
void RWLockPosix::make_default() {
|
||||
|
||||
create_func = create_func_posix;
|
||||
}
|
||||
|
||||
RWLockPosix::RWLockPosix() {
|
||||
|
||||
//rwlock=PTHREAD_RWLOCK_INITIALIZER; fails on OSX
|
||||
pthread_rwlock_init(&rwlock, NULL);
|
||||
}
|
||||
|
||||
RWLockPosix::~RWLockPosix() {
|
||||
|
||||
pthread_rwlock_destroy(&rwlock);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,63 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_posix.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RWLOCKPOSIX_H
|
||||
#define RWLOCKPOSIX_H
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)
|
||||
|
||||
#include "core/os/rw_lock.h"
|
||||
#include <pthread.h>
|
||||
|
||||
class RWLockPosix : public RWLock {
|
||||
|
||||
pthread_rwlock_t rwlock;
|
||||
|
||||
static RWLock *create_func_posix();
|
||||
|
||||
public:
|
||||
virtual void read_lock();
|
||||
virtual void read_unlock();
|
||||
virtual Error read_try_lock();
|
||||
|
||||
virtual void write_lock();
|
||||
virtual void write_unlock();
|
||||
virtual Error write_try_lock();
|
||||
|
||||
static void make_default();
|
||||
|
||||
RWLockPosix();
|
||||
|
||||
~RWLockPosix();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // RWLOCKPOSIX_H
|
||||
@@ -1,87 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* semaphore_posix.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "semaphore_posix.h"
|
||||
|
||||
#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
|
||||
|
||||
#include "core/os/memory.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Error SemaphorePosix::wait() {
|
||||
|
||||
while (sem_wait(&sem)) {
|
||||
if (errno == EINTR) {
|
||||
errno = 0;
|
||||
continue;
|
||||
} else {
|
||||
perror("sem waiting");
|
||||
return ERR_BUSY;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error SemaphorePosix::post() {
|
||||
|
||||
return (sem_post(&sem) == 0) ? OK : ERR_BUSY;
|
||||
}
|
||||
int SemaphorePosix::get() const {
|
||||
|
||||
int val;
|
||||
sem_getvalue(&sem, &val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
Semaphore *SemaphorePosix::create_semaphore_posix() {
|
||||
|
||||
return memnew(SemaphorePosix);
|
||||
}
|
||||
|
||||
void SemaphorePosix::make_default() {
|
||||
|
||||
create_func = create_semaphore_posix;
|
||||
}
|
||||
|
||||
SemaphorePosix::SemaphorePosix() {
|
||||
|
||||
int r = sem_init(&sem, 0, 0);
|
||||
if (r != 0)
|
||||
perror("sem creating");
|
||||
}
|
||||
|
||||
SemaphorePosix::~SemaphorePosix() {
|
||||
|
||||
sem_destroy(&sem);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,58 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* semaphore_posix.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef SEMAPHORE_POSIX_H
|
||||
#define SEMAPHORE_POSIX_H
|
||||
|
||||
#include "core/os/semaphore.h"
|
||||
|
||||
#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED)
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
class SemaphorePosix : public Semaphore {
|
||||
|
||||
mutable sem_t sem;
|
||||
|
||||
static Semaphore *create_semaphore_posix();
|
||||
|
||||
public:
|
||||
virtual Error wait();
|
||||
virtual Error post();
|
||||
virtual int get() const;
|
||||
|
||||
static void make_default();
|
||||
SemaphorePosix();
|
||||
|
||||
~SemaphorePosix();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -28,92 +28,14 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "thread_posix.h"
|
||||
|
||||
#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS)
|
||||
|
||||
#include "core/os/memory.h"
|
||||
#include "core/safe_refcount.h"
|
||||
#include "core/script_language.h"
|
||||
#include "thread_posix.h"
|
||||
|
||||
#ifdef PTHREAD_BSD_SET_NAME
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
|
||||
static void _thread_id_key_destr_callback(void *p_value) {
|
||||
memdelete(static_cast<Thread::ID *>(p_value));
|
||||
}
|
||||
|
||||
static pthread_key_t _create_thread_id_key() {
|
||||
pthread_key_t key;
|
||||
pthread_key_create(&key, &_thread_id_key_destr_callback);
|
||||
return key;
|
||||
}
|
||||
|
||||
pthread_key_t ThreadPosix::thread_id_key = _create_thread_id_key();
|
||||
Thread::ID ThreadPosix::next_thread_id = 0;
|
||||
|
||||
Thread::ID ThreadPosix::get_id() const {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Thread *ThreadPosix::create_thread_posix() {
|
||||
|
||||
return memnew(ThreadPosix);
|
||||
}
|
||||
|
||||
void *ThreadPosix::thread_callback(void *userdata) {
|
||||
|
||||
ThreadPosix *t = reinterpret_cast<ThreadPosix *>(userdata);
|
||||
t->id = atomic_increment(&next_thread_id);
|
||||
pthread_setspecific(thread_id_key, (void *)memnew(ID(t->id)));
|
||||
|
||||
ScriptServer::thread_enter(); //scripts may need to attach a stack
|
||||
|
||||
t->callback(t->user);
|
||||
|
||||
ScriptServer::thread_exit();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Thread *ThreadPosix::create_func_posix(ThreadCreateCallback p_callback, void *p_user, const Settings &) {
|
||||
|
||||
ThreadPosix *tr = memnew(ThreadPosix);
|
||||
tr->callback = p_callback;
|
||||
tr->user = p_user;
|
||||
pthread_attr_init(&tr->pthread_attr);
|
||||
pthread_attr_setdetachstate(&tr->pthread_attr, PTHREAD_CREATE_JOINABLE);
|
||||
pthread_attr_setstacksize(&tr->pthread_attr, 256 * 1024);
|
||||
|
||||
pthread_create(&tr->pthread, &tr->pthread_attr, thread_callback, tr);
|
||||
|
||||
return tr;
|
||||
}
|
||||
Thread::ID ThreadPosix::get_thread_id_func_posix() {
|
||||
|
||||
void *value = pthread_getspecific(thread_id_key);
|
||||
|
||||
if (value)
|
||||
return *static_cast<ID *>(value);
|
||||
|
||||
ID new_id = atomic_increment(&next_thread_id);
|
||||
pthread_setspecific(thread_id_key, (void *)memnew(ID(new_id)));
|
||||
return new_id;
|
||||
}
|
||||
void ThreadPosix::wait_to_finish_func_posix(Thread *p_thread) {
|
||||
|
||||
ThreadPosix *tp = static_cast<ThreadPosix *>(p_thread);
|
||||
ERR_FAIL_COND(!tp);
|
||||
ERR_FAIL_COND(tp->pthread == 0);
|
||||
|
||||
pthread_join(tp->pthread, NULL);
|
||||
tp->pthread = 0;
|
||||
}
|
||||
|
||||
Error ThreadPosix::set_name_func_posix(const String &p_name) {
|
||||
#include "core/os/thread.h"
|
||||
#include "core/ustring.h"
|
||||
|
||||
static Error set_name(const String &p_name) {
|
||||
#ifdef PTHREAD_NO_RENAME
|
||||
return ERR_UNAVAILABLE;
|
||||
|
||||
@@ -141,22 +63,10 @@ Error ThreadPosix::set_name_func_posix(const String &p_name) {
|
||||
return err == 0 ? OK : ERR_INVALID_PARAMETER;
|
||||
|
||||
#endif // PTHREAD_NO_RENAME
|
||||
};
|
||||
|
||||
void ThreadPosix::make_default() {
|
||||
|
||||
create_func = create_func_posix;
|
||||
get_thread_id_func = get_thread_id_func_posix;
|
||||
wait_to_finish_func = wait_to_finish_func_posix;
|
||||
set_name_func = set_name_func_posix;
|
||||
}
|
||||
|
||||
ThreadPosix::ThreadPosix() {
|
||||
|
||||
pthread = 0;
|
||||
}
|
||||
|
||||
ThreadPosix::~ThreadPosix() {
|
||||
void init_thread_posix() {
|
||||
Thread::_set_platform_funcs(&set_name, nullptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,43 +31,8 @@
|
||||
#ifndef THREAD_POSIX_H
|
||||
#define THREAD_POSIX_H
|
||||
|
||||
#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(NO_THREADS)
|
||||
|
||||
#include "core/os/thread.h"
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
class ThreadPosix : public Thread {
|
||||
|
||||
static pthread_key_t thread_id_key;
|
||||
static ID next_thread_id;
|
||||
|
||||
pthread_t pthread;
|
||||
pthread_attr_t pthread_attr;
|
||||
ThreadCreateCallback callback;
|
||||
void *user;
|
||||
ID id;
|
||||
|
||||
static Thread *create_thread_posix();
|
||||
|
||||
static void *thread_callback(void *userdata);
|
||||
|
||||
static Thread *create_func_posix(ThreadCreateCallback p_callback, void *, const Settings &);
|
||||
static ID get_thread_id_func_posix();
|
||||
static void wait_to_finish_func_posix(Thread *p_thread);
|
||||
|
||||
static Error set_name_func_posix(const String &p_name);
|
||||
|
||||
ThreadPosix();
|
||||
|
||||
public:
|
||||
virtual ID get_id() const;
|
||||
|
||||
static void make_default();
|
||||
|
||||
~ThreadPosix();
|
||||
};
|
||||
|
||||
#if !defined(NO_THREADS)
|
||||
void init_thread_posix();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -406,8 +406,7 @@ Error AudioDriverWASAPI::init() {
|
||||
exit_thread = false;
|
||||
thread_exited = false;
|
||||
|
||||
mutex = Mutex::create(true);
|
||||
thread = Thread::create(thread_func, this);
|
||||
thread.start(thread_func, this);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -782,33 +781,21 @@ void AudioDriverWASAPI::start() {
|
||||
|
||||
void AudioDriverWASAPI::lock() {
|
||||
|
||||
if (mutex)
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
void AudioDriverWASAPI::unlock() {
|
||||
|
||||
if (mutex)
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AudioDriverWASAPI::finish() {
|
||||
|
||||
if (thread) {
|
||||
exit_thread = true;
|
||||
Thread::wait_to_finish(thread);
|
||||
|
||||
memdelete(thread);
|
||||
thread = NULL;
|
||||
}
|
||||
exit_thread = true;
|
||||
thread.wait_to_finish();
|
||||
|
||||
finish_capture_device();
|
||||
finish_render_device();
|
||||
|
||||
if (mutex) {
|
||||
memdelete(mutex);
|
||||
mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Error AudioDriverWASAPI::capture_start() {
|
||||
@@ -863,9 +850,6 @@ String AudioDriverWASAPI::capture_get_device() {
|
||||
|
||||
AudioDriverWASAPI::AudioDriverWASAPI() {
|
||||
|
||||
mutex = NULL;
|
||||
thread = NULL;
|
||||
|
||||
samples_in.clear();
|
||||
|
||||
channels = 0;
|
||||
|
||||
@@ -75,8 +75,8 @@ class AudioDriverWASAPI : public AudioDriver {
|
||||
AudioDeviceWASAPI audio_input;
|
||||
AudioDeviceWASAPI audio_output;
|
||||
|
||||
Mutex *mutex;
|
||||
Thread *thread;
|
||||
Mutex mutex;
|
||||
Thread thread;
|
||||
|
||||
Vector<int32_t> samples_in;
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* mutex_windows.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "mutex_windows.h"
|
||||
|
||||
#include "core/os/memory.h"
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
|
||||
void MutexWindows::lock() {
|
||||
|
||||
#ifdef WINDOWS_USE_MUTEX
|
||||
WaitForSingleObject(mutex, INFINITE);
|
||||
#else
|
||||
EnterCriticalSection(&mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MutexWindows::unlock() {
|
||||
|
||||
#ifdef WINDOWS_USE_MUTEX
|
||||
ReleaseMutex(mutex);
|
||||
#else
|
||||
LeaveCriticalSection(&mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
Error MutexWindows::try_lock() {
|
||||
|
||||
#ifdef WINDOWS_USE_MUTEX
|
||||
return (WaitForSingleObject(mutex, 0) == WAIT_TIMEOUT) ? ERR_BUSY : OK;
|
||||
#else
|
||||
|
||||
if (TryEnterCriticalSection(&mutex))
|
||||
return OK;
|
||||
else
|
||||
return ERR_BUSY;
|
||||
#endif
|
||||
}
|
||||
|
||||
Mutex *MutexWindows::create_func_windows(bool p_recursive) {
|
||||
|
||||
return memnew(MutexWindows);
|
||||
}
|
||||
|
||||
void MutexWindows::make_default() {
|
||||
|
||||
create_func = create_func_windows;
|
||||
}
|
||||
|
||||
MutexWindows::MutexWindows() {
|
||||
|
||||
#ifdef WINDOWS_USE_MUTEX
|
||||
mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
#else
|
||||
#ifdef UWP_ENABLED
|
||||
InitializeCriticalSectionEx(&mutex, 0, 0);
|
||||
#else
|
||||
InitializeCriticalSection(&mutex);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
MutexWindows::~MutexWindows() {
|
||||
|
||||
#ifdef WINDOWS_USE_MUTEX
|
||||
CloseHandle(mutex);
|
||||
#else
|
||||
|
||||
DeleteCriticalSection(&mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,63 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* mutex_windows.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef MUTEX_WINDOWS_H
|
||||
#define MUTEX_WINDOWS_H
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
|
||||
#include "core/os/mutex.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class MutexWindows : public Mutex {
|
||||
|
||||
#ifdef WINDOWS_USE_MUTEX
|
||||
HANDLE mutex;
|
||||
#else
|
||||
CRITICAL_SECTION mutex;
|
||||
#endif
|
||||
|
||||
static Mutex *create_func_windows(bool p_recursive);
|
||||
|
||||
public:
|
||||
virtual void lock();
|
||||
virtual void unlock();
|
||||
virtual Error try_lock();
|
||||
|
||||
static void make_default();
|
||||
|
||||
MutexWindows();
|
||||
~MutexWindows();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,95 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_windows.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#if defined(WINDOWS_ENABLED)
|
||||
|
||||
#include "rw_lock_windows.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
#include "core/os/memory.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void RWLockWindows::read_lock() {
|
||||
|
||||
AcquireSRWLockShared(&lock);
|
||||
}
|
||||
|
||||
void RWLockWindows::read_unlock() {
|
||||
|
||||
ReleaseSRWLockShared(&lock);
|
||||
}
|
||||
|
||||
Error RWLockWindows::read_try_lock() {
|
||||
|
||||
if (TryAcquireSRWLockShared(&lock) == 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
void RWLockWindows::write_lock() {
|
||||
|
||||
AcquireSRWLockExclusive(&lock);
|
||||
}
|
||||
|
||||
void RWLockWindows::write_unlock() {
|
||||
|
||||
ReleaseSRWLockExclusive(&lock);
|
||||
}
|
||||
|
||||
Error RWLockWindows::write_try_lock() {
|
||||
if (TryAcquireSRWLockExclusive(&lock) == 0) {
|
||||
return ERR_BUSY;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
RWLock *RWLockWindows::create_func_windows() {
|
||||
|
||||
return memnew(RWLockWindows);
|
||||
}
|
||||
|
||||
void RWLockWindows::make_default() {
|
||||
|
||||
create_func = create_func_windows;
|
||||
}
|
||||
|
||||
RWLockWindows::RWLockWindows() {
|
||||
|
||||
InitializeSRWLock(&lock);
|
||||
}
|
||||
|
||||
RWLockWindows::~RWLockWindows() {
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,64 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock_windows.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef RWLOCKWINDOWS_H
|
||||
#define RWLOCKWINDOWS_H
|
||||
|
||||
#if defined(WINDOWS_ENABLED)
|
||||
|
||||
#include "core/os/rw_lock.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class RWLockWindows : public RWLock {
|
||||
|
||||
SRWLOCK lock;
|
||||
|
||||
static RWLock *create_func_windows();
|
||||
|
||||
public:
|
||||
virtual void read_lock();
|
||||
virtual void read_unlock();
|
||||
virtual Error read_try_lock();
|
||||
|
||||
virtual void write_lock();
|
||||
virtual void write_unlock();
|
||||
virtual Error write_try_lock();
|
||||
|
||||
static void make_default();
|
||||
|
||||
RWLockWindows();
|
||||
|
||||
~RWLockWindows();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // RWLOCKWINDOWS_H
|
||||
@@ -1,98 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* semaphore_windows.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "semaphore_windows.h"
|
||||
|
||||
#if defined(WINDOWS_ENABLED)
|
||||
|
||||
#include "core/os/memory.h"
|
||||
|
||||
Error SemaphoreWindows::wait() {
|
||||
|
||||
WaitForSingleObjectEx(semaphore, INFINITE, false);
|
||||
return OK;
|
||||
}
|
||||
Error SemaphoreWindows::post() {
|
||||
|
||||
ReleaseSemaphore(semaphore, 1, NULL);
|
||||
return OK;
|
||||
}
|
||||
int SemaphoreWindows::get() const {
|
||||
long previous;
|
||||
switch (WaitForSingleObjectEx(semaphore, 0, false)) {
|
||||
case WAIT_OBJECT_0: {
|
||||
ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous), -1);
|
||||
return previous + 1;
|
||||
} break;
|
||||
case WAIT_TIMEOUT: {
|
||||
return 0;
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
|
||||
ERR_FAIL_V(-1);
|
||||
}
|
||||
|
||||
Semaphore *SemaphoreWindows::create_semaphore_windows() {
|
||||
|
||||
return memnew(SemaphoreWindows);
|
||||
}
|
||||
|
||||
void SemaphoreWindows::make_default() {
|
||||
|
||||
create_func = create_semaphore_windows;
|
||||
}
|
||||
|
||||
SemaphoreWindows::SemaphoreWindows() {
|
||||
|
||||
#ifdef UWP_ENABLED
|
||||
semaphore = CreateSemaphoreEx(
|
||||
NULL,
|
||||
0,
|
||||
0xFFFFFFF, //wathever
|
||||
NULL,
|
||||
0,
|
||||
SEMAPHORE_ALL_ACCESS);
|
||||
#else
|
||||
semaphore = CreateSemaphore(
|
||||
NULL,
|
||||
0,
|
||||
0xFFFFFFF, //wathever
|
||||
NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
SemaphoreWindows::~SemaphoreWindows() {
|
||||
|
||||
CloseHandle(semaphore);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,58 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* semaphore_windows.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef SEMAPHORE_WINDOWS_H
|
||||
#define SEMAPHORE_WINDOWS_H
|
||||
|
||||
#include "core/os/semaphore.h"
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class SemaphoreWindows : public Semaphore {
|
||||
|
||||
mutable HANDLE semaphore;
|
||||
|
||||
static Semaphore *create_semaphore_windows();
|
||||
|
||||
public:
|
||||
virtual Error wait();
|
||||
virtual Error post();
|
||||
virtual int get() const;
|
||||
|
||||
static void make_default();
|
||||
SemaphoreWindows();
|
||||
|
||||
~SemaphoreWindows();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,100 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* thread_windows.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "thread_windows.h"
|
||||
|
||||
#if defined(WINDOWS_ENABLED) && !defined(UWP_ENABLED)
|
||||
|
||||
#include "core/os/memory.h"
|
||||
|
||||
Thread::ID ThreadWindows::get_id() const {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Thread *ThreadWindows::create_thread_windows() {
|
||||
|
||||
return memnew(ThreadWindows);
|
||||
}
|
||||
|
||||
DWORD ThreadWindows::thread_callback(LPVOID userdata) {
|
||||
|
||||
ThreadWindows *t = reinterpret_cast<ThreadWindows *>(userdata);
|
||||
|
||||
ScriptServer::thread_enter(); //scripts may need to attach a stack
|
||||
|
||||
t->id = (ID)GetCurrentThreadId(); // must implement
|
||||
t->callback(t->user);
|
||||
SetEvent(t->handle);
|
||||
|
||||
ScriptServer::thread_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Thread *ThreadWindows::create_func_windows(ThreadCreateCallback p_callback, void *p_user, const Settings &) {
|
||||
|
||||
ThreadWindows *tr = memnew(ThreadWindows);
|
||||
tr->callback = p_callback;
|
||||
tr->user = p_user;
|
||||
tr->handle = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
QueueUserWorkItem(thread_callback, tr, WT_EXECUTELONGFUNCTION);
|
||||
|
||||
return tr;
|
||||
}
|
||||
Thread::ID ThreadWindows::get_thread_id_func_windows() {
|
||||
|
||||
return (ID)GetCurrentThreadId(); //must implement
|
||||
}
|
||||
void ThreadWindows::wait_to_finish_func_windows(Thread *p_thread) {
|
||||
|
||||
ThreadWindows *tp = static_cast<ThreadWindows *>(p_thread);
|
||||
ERR_FAIL_COND(!tp);
|
||||
WaitForSingleObject(tp->handle, INFINITE);
|
||||
CloseHandle(tp->handle);
|
||||
//`memdelete(tp);
|
||||
}
|
||||
|
||||
void ThreadWindows::make_default() {
|
||||
|
||||
create_func = create_func_windows;
|
||||
get_thread_id_func = get_thread_id_func_windows;
|
||||
wait_to_finish_func = wait_to_finish_func_windows;
|
||||
}
|
||||
|
||||
ThreadWindows::ThreadWindows() :
|
||||
handle(NULL) {
|
||||
}
|
||||
|
||||
ThreadWindows::~ThreadWindows() {
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,68 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* thread_windows.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef THREAD_WINDOWS_H
|
||||
#define THREAD_WINDOWS_H
|
||||
|
||||
#ifdef WINDOWS_ENABLED
|
||||
|
||||
#include "core/os/thread.h"
|
||||
#include "core/script_language.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class ThreadWindows : public Thread {
|
||||
|
||||
ThreadCreateCallback callback;
|
||||
void *user;
|
||||
ID id;
|
||||
HANDLE handle;
|
||||
|
||||
static Thread *create_thread_windows();
|
||||
|
||||
static DWORD WINAPI thread_callback(LPVOID userdata);
|
||||
|
||||
static Thread *create_func_windows(ThreadCreateCallback p_callback, void *, const Settings &);
|
||||
static ID get_thread_id_func_windows();
|
||||
static void wait_to_finish_func_windows(Thread *p_thread);
|
||||
|
||||
ThreadWindows();
|
||||
|
||||
public:
|
||||
virtual ID get_id() const;
|
||||
|
||||
static void make_default();
|
||||
|
||||
~ThreadWindows();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -79,8 +79,7 @@ Error AudioDriverXAudio2::init() {
|
||||
hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, &voice_callback);
|
||||
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_UNAVAILABLE, "Error creating XAudio2 source voice. Error code: " + itos(hr) + ".");
|
||||
|
||||
mutex = Mutex::create();
|
||||
thread = Thread::create(AudioDriverXAudio2::thread_func, this);
|
||||
thread.start(AudioDriverXAudio2::thread_func, this);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -158,24 +157,20 @@ float AudioDriverXAudio2::get_latency() {
|
||||
|
||||
void AudioDriverXAudio2::lock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
return;
|
||||
mutex->lock();
|
||||
mutex.lock();
|
||||
}
|
||||
void AudioDriverXAudio2::unlock() {
|
||||
|
||||
if (!thread || !mutex)
|
||||
return;
|
||||
mutex->unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AudioDriverXAudio2::finish() {
|
||||
|
||||
if (!thread)
|
||||
if (!thread.is_started())
|
||||
return;
|
||||
|
||||
exit_thread = true;
|
||||
Thread::wait_to_finish(thread);
|
||||
thread.wait_to_finish();
|
||||
|
||||
if (source_voice) {
|
||||
source_voice->Stop(0);
|
||||
@@ -192,16 +187,9 @@ void AudioDriverXAudio2::finish() {
|
||||
}
|
||||
|
||||
mastering_voice->DestroyVoice();
|
||||
|
||||
memdelete(thread);
|
||||
if (mutex)
|
||||
memdelete(mutex);
|
||||
thread = NULL;
|
||||
}
|
||||
|
||||
AudioDriverXAudio2::AudioDriverXAudio2() :
|
||||
thread(NULL),
|
||||
mutex(NULL),
|
||||
current_buffer(0) {
|
||||
wave_format = { 0 };
|
||||
for (int i = 0; i < AUDIO_BUFFERS; i++) {
|
||||
|
||||
@@ -64,8 +64,8 @@ class AudioDriverXAudio2 : public AudioDriver {
|
||||
void STDMETHODCALLTYPE OnVoiceError(void *pBufferContext, HRESULT Error) {}
|
||||
};
|
||||
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
Thread thread;
|
||||
Mutex mutex;
|
||||
|
||||
int32_t *samples_in;
|
||||
int16_t *samples_out[AUDIO_BUFFERS];
|
||||
|
||||
Reference in New Issue
Block a user