forked from sascha/godot
Merge pull request #45618 from RandomShaper/modernize_mt_3.2
Backport of all the multi-threading modernization (3.2)3.3
commit
220f24c191
@ -1,47 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* rw_lock.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 "rw_lock.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
RWLock *(*RWLock::create_func)() = 0;
|
||||
|
||||
RWLock *RWLock::create() {
|
||||
|
||||
ERR_FAIL_COND_V(!create_func, 0);
|
||||
|
||||
return create_func();
|
||||
}
|
||||
|
||||
RWLock::~RWLock() {
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* semaphore.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.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
|
||||
Semaphore *(*Semaphore::create_func)() = 0;
|
||||
|
||||
Semaphore *Semaphore::create() {
|
||||
|
||||
ERR_FAIL_COND_V(!create_func, 0);
|
||||
|
||||
return create_func();
|
||||
}
|
||||
|
||||
Semaphore::~Semaphore() {
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* thread_dummy.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_dummy.h"
|
||||
|
||||
#include "core/os/memory.h"
|
||||
|
||||
Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const Thread::Settings &p_settings) {
|
||||
return memnew(ThreadDummy);
|
||||
};
|
||||
|
||||
void ThreadDummy::make_default() {
|
||||
Thread::create_func = &ThreadDummy::create;
|
||||
};
|
||||
|
||||
Mutex *MutexDummy::create(bool p_recursive) {
|
||||
return memnew(MutexDummy);
|
||||
};
|
||||
|
||||
void MutexDummy::make_default() {
|
||||
Mutex::create_func = &MutexDummy::create;
|
||||
};
|
||||
|
||||
Semaphore *SemaphoreDummy::create() {
|
||||
return memnew(SemaphoreDummy);
|
||||
};
|
||||
|
||||
void SemaphoreDummy::make_default() {
|
||||
Semaphore::create_func = &SemaphoreDummy::create;
|
||||
};
|
||||
|
||||
RWLock *RWLockDummy::create() {
|
||||
return memnew(RWLockDummy);
|
||||
};
|
||||
|
||||
void RWLockDummy::make_default() {
|
||||
RWLock::create_func = &RWLockDummy::create;
|
||||
};
|
||||
@ -1,89 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* thread_dummy.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_DUMMY_H
|
||||
#define THREAD_DUMMY_H
|
||||
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/os/rw_lock.h"
|
||||
#include "core/os/semaphore.h"
|
||||
#include "core/os/thread.h"
|
||||
|
||||
class ThreadDummy : public Thread {
|
||||
|
||||
static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings());
|
||||
|
||||
public:
|
||||
virtual ID get_id() const { return 0; };
|
||||
|
||||
static void make_default();
|
||||
};
|
||||
|
||||
class MutexDummy : public Mutex {
|
||||
|
||||
static Mutex *create(bool p_recursive);
|
||||
|
||||
public:
|
||||
virtual void lock(){};
|
||||
virtual void unlock(){};
|
||||
virtual Error try_lock() { return OK; };
|
||||
|
||||
static void make_default();
|
||||
};
|
||||
|
||||
class SemaphoreDummy : public Semaphore {
|
||||
|
||||
static Semaphore *create();
|
||||
|
||||
public:
|
||||
virtual Error wait() { return OK; };
|
||||
virtual Error post() { return OK; };
|
||||
virtual int get() const { return 0; }; ///< get semaphore value
|
||||
|
||||
static void make_default();
|
||||
};
|
||||
|
||||
class RWLockDummy : public RWLock {
|
||||
|
||||
static RWLock *create();
|
||||
|
||||
public:
|
||||
virtual void read_lock() {}
|
||||
virtual void read_unlock() {}
|
||||
virtual Error read_try_lock() { return OK; }
|
||||
|
||||
virtual void write_lock() {}
|
||||
virtual void write_unlock() {}
|
||||
virtual Error write_try_lock() { return OK; }
|
||||
|
||||
static void make_default();
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,49 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* thread_safe.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_safe.h"
|
||||
|
||||
#include "core/error_macros.h"
|
||||
#include "core/os/memory.h"
|
||||
|
||||
ThreadSafe::ThreadSafe() {
|
||||
|
||||
mutex = Mutex::create();
|
||||
if (!mutex) {
|
||||
|
||||
WARN_PRINT("THREAD_SAFE defined, but no default mutex type");
|
||||
}
|
||||
}
|
||||
|
||||
ThreadSafe::~ThreadSafe() {
|
||||
|
||||
if (mutex)
|
||||
memdelete(mutex);
|
||||
}
|
||||
@ -1,169 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* safe_refcount.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 "safe_refcount.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
/* Implementation for MSVC-Windows */
|
||||
|
||||
// don't pollute my namespace!
|
||||
#include <windows.h>
|
||||
|
||||
#define ATOMIC_CONDITIONAL_INCREMENT_BODY(m_pw, m_win_type, m_win_cmpxchg, m_cpp_type) \
|
||||
/* try to increment until it actually works */ \
|
||||
/* taken from boost */ \
|
||||
while (true) { \
|
||||
m_cpp_type tmp = static_cast<m_cpp_type const volatile &>(*(m_pw)); \
|
||||
if (tmp == 0) \
|
||||
return 0; /* if zero, can't add to it anymore */ \
|
||||
if (m_win_cmpxchg((m_win_type volatile *)(m_pw), tmp + 1, tmp) == tmp) \
|
||||
return tmp + 1; \
|
||||
}
|
||||
|
||||
#define ATOMIC_EXCHANGE_IF_GREATER_BODY(m_pw, m_val, m_win_type, m_win_cmpxchg, m_cpp_type) \
|
||||
while (true) { \
|
||||
m_cpp_type tmp = static_cast<m_cpp_type const volatile &>(*(m_pw)); \
|
||||
if (tmp >= m_val) \
|
||||
return tmp; /* already greater, or equal */ \
|
||||
if (m_win_cmpxchg((m_win_type volatile *)(m_pw), m_val, tmp) == tmp) \
|
||||
return m_val; \
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(volatile uint32_t *pw){
|
||||
|
||||
ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONG, InterlockedCompareExchange, uint32_t)
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint32_t _atomic_decrement_impl(volatile uint32_t *pw) {
|
||||
|
||||
return InterlockedDecrement((LONG volatile *)pw);
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint32_t _atomic_increment_impl(volatile uint32_t *pw) {
|
||||
|
||||
return InterlockedIncrement((LONG volatile *)pw);
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint32_t _atomic_sub_impl(volatile uint32_t *pw, volatile uint32_t val) {
|
||||
|
||||
return InterlockedExchangeAdd((LONG volatile *)pw, -(int32_t)val) - val;
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint32_t _atomic_add_impl(volatile uint32_t *pw, volatile uint32_t val) {
|
||||
|
||||
return InterlockedAdd((LONG volatile *)pw, val);
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint32_t _atomic_exchange_if_greater_impl(volatile uint32_t *pw, volatile uint32_t val){
|
||||
|
||||
ATOMIC_EXCHANGE_IF_GREATER_BODY(pw, val, LONG, InterlockedCompareExchange, uint32_t)
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(volatile uint64_t *pw){
|
||||
|
||||
ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONGLONG, InterlockedCompareExchange64, uint64_t)
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint64_t _atomic_decrement_impl(volatile uint64_t *pw) {
|
||||
|
||||
return InterlockedDecrement64((LONGLONG volatile *)pw);
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint64_t _atomic_increment_impl(volatile uint64_t *pw) {
|
||||
|
||||
return InterlockedIncrement64((LONGLONG volatile *)pw);
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint64_t _atomic_sub_impl(volatile uint64_t *pw, volatile uint64_t val) {
|
||||
|
||||
return InterlockedExchangeAdd64((LONGLONG volatile *)pw, -(int64_t)val) - val;
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint64_t _atomic_add_impl(volatile uint64_t *pw, volatile uint64_t val) {
|
||||
|
||||
return InterlockedAdd64((LONGLONG volatile *)pw, val);
|
||||
}
|
||||
|
||||
_ALWAYS_INLINE_ uint64_t _atomic_exchange_if_greater_impl(volatile uint64_t *pw, volatile uint64_t val){
|
||||
|
||||
ATOMIC_EXCHANGE_IF_GREATER_BODY(pw, val, LONGLONG, InterlockedCompareExchange64, uint64_t)
|
||||
}
|
||||
|
||||
// The actual advertised functions; they'll call the right implementation
|
||||
|
||||
uint32_t atomic_conditional_increment(volatile uint32_t *pw) {
|
||||
return _atomic_conditional_increment_impl(pw);
|
||||
}
|
||||
|
||||
uint32_t atomic_decrement(volatile uint32_t *pw) {
|
||||
return _atomic_decrement_impl(pw);
|
||||
}
|
||||
|
||||
uint32_t atomic_increment(volatile uint32_t *pw) {
|
||||
return _atomic_increment_impl(pw);
|
||||
}
|
||||
|
||||
uint32_t atomic_sub(volatile uint32_t *pw, volatile uint32_t val) {
|
||||
return _atomic_sub_impl(pw, val);
|
||||
}
|
||||
|
||||
uint32_t atomic_add(volatile uint32_t *pw, volatile uint32_t val) {
|
||||
return _atomic_add_impl(pw, val);
|
||||
}
|
||||
|
||||
uint32_t atomic_exchange_if_greater(volatile uint32_t *pw, volatile uint32_t val) {
|
||||
return _atomic_exchange_if_greater_impl(pw, val);
|
||||
}
|
||||
|
||||
uint64_t atomic_conditional_increment(volatile uint64_t *pw) {
|
||||
return _atomic_conditional_increment_impl(pw);
|
||||
}
|
||||
|
||||
uint64_t atomic_decrement(volatile uint64_t *pw) {
|
||||
return _atomic_decrement_impl(pw);
|
||||
}
|
||||
|
||||
uint64_t atomic_increment(volatile uint64_t *pw) {
|
||||
return _atomic_increment_impl(pw);
|
||||
}
|
||||
|
||||
uint64_t atomic_sub(volatile uint64_t *pw, volatile uint64_t val) {
|
||||
return _atomic_sub_impl(pw, val);
|
||||
}
|
||||
|
||||
uint64_t atomic_add(volatile uint64_t *pw, volatile uint64_t val) {
|
||||
return _atomic_add_impl(pw, val);
|
||||
}
|
||||
|
||||
uint64_t atomic_exchange_if_greater(volatile uint64_t *pw, volatile uint64_t val) {
|
||||
return _atomic_exchange_if_greater_impl(pw, val);
|
||||
}
|
||||
#endif
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue