mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Move some C++11 types from Android to AerofoilSDL.
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
#include "GpSystemServices_Android.h"
|
#include "GpSystemServices_Android.h"
|
||||||
#include "IGpMutex.h"
|
|
||||||
#include "IGpThreadEvent.h"
|
#include "GpMutex_Cpp11.h"
|
||||||
|
#include "GpThreadEvent_Cpp11.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <mutex>
|
|
||||||
#include <condition_variable>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct GpSystemServices_Android_ThreadStartParams
|
struct GpSystemServices_Android_ThreadStartParams
|
||||||
@@ -28,143 +27,6 @@ static int SDLCALL StaticStartThread(void *lpThreadParameter)
|
|||||||
return threadFunc(threadContext);
|
return threadFunc(threadContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class TMutex>
|
|
||||||
class GpMutex_Cpp11 final : public IGpMutex
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GpMutex_Cpp11();
|
|
||||||
~GpMutex_Cpp11();
|
|
||||||
|
|
||||||
void Destroy() override;
|
|
||||||
|
|
||||||
void Lock() override;
|
|
||||||
void Unlock() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
TMutex m_mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class TMutex>
|
|
||||||
GpMutex_Cpp11<TMutex>::GpMutex_Cpp11()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class TMutex>
|
|
||||||
GpMutex_Cpp11<TMutex>::~GpMutex_Cpp11()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class TMutex>
|
|
||||||
void GpMutex_Cpp11<TMutex>::Destroy()
|
|
||||||
{
|
|
||||||
this->~GpMutex_Cpp11();
|
|
||||||
free(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class TMutex>
|
|
||||||
void GpMutex_Cpp11<TMutex>::Lock()
|
|
||||||
{
|
|
||||||
m_mutex.lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class TMutex>
|
|
||||||
void GpMutex_Cpp11<TMutex>::Unlock()
|
|
||||||
{
|
|
||||||
m_mutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef GpMutex_Cpp11<std::mutex> GpMutex_Cpp11_Vanilla;
|
|
||||||
typedef GpMutex_Cpp11<std::recursive_mutex> GpMutex_Cpp11_Recursive;
|
|
||||||
|
|
||||||
|
|
||||||
class GpThreadEvent_Cpp11 final : public IGpThreadEvent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GpThreadEvent_Cpp11(bool autoReset, bool startSignaled);
|
|
||||||
~GpThreadEvent_Cpp11();
|
|
||||||
|
|
||||||
void Wait() override;
|
|
||||||
bool WaitTimed(uint32_t msec) override;
|
|
||||||
void Signal() override;
|
|
||||||
void Destroy() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::mutex m_mutex;
|
|
||||||
std::condition_variable m_cvar;
|
|
||||||
bool m_flag;
|
|
||||||
bool m_autoReset;
|
|
||||||
};
|
|
||||||
|
|
||||||
GpThreadEvent_Cpp11::GpThreadEvent_Cpp11(bool autoReset, bool startSignaled)
|
|
||||||
: m_flag(startSignaled)
|
|
||||||
, m_autoReset(autoReset)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GpThreadEvent_Cpp11::~GpThreadEvent_Cpp11()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpThreadEvent_Cpp11::Wait()
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
|
||||||
if (m_autoReset)
|
|
||||||
{
|
|
||||||
m_cvar.wait(lock,[&]()->bool{
|
|
||||||
if (m_flag)
|
|
||||||
{
|
|
||||||
m_flag = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_cvar.wait(lock,[&]()->bool{ return m_flag; });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GpThreadEvent_Cpp11::WaitTimed(uint32_t msec)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
|
||||||
if (m_autoReset)
|
|
||||||
{
|
|
||||||
if (!m_cvar.wait_for(lock, std::chrono::milliseconds(msec), [&]()->bool{
|
|
||||||
if (m_flag)
|
|
||||||
{
|
|
||||||
m_flag = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!m_cvar.wait_for(lock, std::chrono::milliseconds(msec), [&]()->bool{ return m_flag; }))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpThreadEvent_Cpp11::Signal()
|
|
||||||
{
|
|
||||||
m_mutex.lock();
|
|
||||||
m_flag = true;
|
|
||||||
m_mutex.unlock();
|
|
||||||
if (m_autoReset)
|
|
||||||
m_cvar.notify_one();
|
|
||||||
else
|
|
||||||
m_cvar.notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GpThreadEvent_Cpp11::Destroy()
|
|
||||||
{
|
|
||||||
this->~GpThreadEvent_Cpp11();
|
|
||||||
free(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
GpSystemServices_Android::GpSystemServices_Android()
|
GpSystemServices_Android::GpSystemServices_Android()
|
||||||
: m_textInputEnabled(false)
|
: m_textInputEnabled(false)
|
||||||
{
|
{
|
||||||
@@ -189,11 +51,7 @@ void GpSystemServices_Android::GetLocalDateTime(unsigned int &year, unsigned int
|
|||||||
|
|
||||||
IGpMutex *GpSystemServices_Android::CreateMutex()
|
IGpMutex *GpSystemServices_Android::CreateMutex()
|
||||||
{
|
{
|
||||||
GpMutex_Cpp11_Vanilla *mutex = static_cast<GpMutex_Cpp11_Vanilla*>(malloc(sizeof(GpMutex_Cpp11_Vanilla)));
|
return GpMutex_Cpp11_NonRecursive::Create();
|
||||||
if (!mutex)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return new (mutex) GpMutex_Cpp11_Vanilla();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -223,20 +81,12 @@ void *GpSystemServices_Android::CreateThread(ThreadFunc_t threadFunc, void *cont
|
|||||||
|
|
||||||
IGpMutex *GpSystemServices_Android::CreateRecursiveMutex()
|
IGpMutex *GpSystemServices_Android::CreateRecursiveMutex()
|
||||||
{
|
{
|
||||||
GpMutex_Cpp11_Recursive *mutex = static_cast<GpMutex_Cpp11_Recursive*>(malloc(sizeof(GpMutex_Cpp11_Recursive)));
|
return GpMutex_Cpp11_Recursive::Create();
|
||||||
if (!mutex)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return new (mutex) GpMutex_Cpp11_Recursive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IGpThreadEvent *GpSystemServices_Android::CreateThreadEvent(bool autoReset, bool startSignaled)
|
IGpThreadEvent *GpSystemServices_Android::CreateThreadEvent(bool autoReset, bool startSignaled)
|
||||||
{
|
{
|
||||||
GpThreadEvent_Cpp11 *evt = static_cast<GpThreadEvent_Cpp11*>(malloc(sizeof(GpThreadEvent_Cpp11)));
|
return GpThreadEvent_Cpp11::Create(autoReset, startSignaled);
|
||||||
if (!evt)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return new (evt) GpThreadEvent_Cpp11(autoReset, startSignaled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GpSystemServices_Android::GetFreeMemoryCosmetic() const
|
uint64_t GpSystemServices_Android::GetFreeMemoryCosmetic() const
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ LOCAL_SRC_FILES := \
|
|||||||
GpDisplayDriver_SDL_GL2.cpp \
|
GpDisplayDriver_SDL_GL2.cpp \
|
||||||
GpFiber_SDL.cpp \
|
GpFiber_SDL.cpp \
|
||||||
GpFiberStarter_SDL.cpp \
|
GpFiberStarter_SDL.cpp \
|
||||||
|
GpThreadEvent_Cpp11.cpp \
|
||||||
ShaderCode/CopyQuadP.cpp \
|
ShaderCode/CopyQuadP.cpp \
|
||||||
ShaderCode/DrawQuadPaletteP.cpp \
|
ShaderCode/DrawQuadPaletteP.cpp \
|
||||||
ShaderCode/DrawQuad32P.cpp \
|
ShaderCode/DrawQuad32P.cpp \
|
||||||
|
|||||||
66
AerofoilSDL/GpMutex_Cpp11.h
Normal file
66
AerofoilSDL/GpMutex_Cpp11.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IGpMutex.h"
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
class GpMutex_Cpp11 final : public IGpMutex
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~GpMutex_Cpp11();
|
||||||
|
|
||||||
|
void Destroy() override;
|
||||||
|
static GpMutex_Cpp11<TMutex> *Create();
|
||||||
|
|
||||||
|
void Lock() override;
|
||||||
|
void Unlock() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GpMutex_Cpp11();
|
||||||
|
|
||||||
|
TMutex m_mutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
GpMutex_Cpp11<TMutex>::GpMutex_Cpp11()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
GpMutex_Cpp11<TMutex>::~GpMutex_Cpp11()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
void GpMutex_Cpp11<TMutex>::Destroy()
|
||||||
|
{
|
||||||
|
this->~GpMutex_Cpp11();
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
GpMutex_Cpp11<TMutex> *GpMutex_Cpp11<TMutex>::Create()
|
||||||
|
{
|
||||||
|
GpMutex_Cpp11<TMutex> *mutex = static_cast<GpMutex_Cpp11<TMutex>*>(malloc(sizeof(GpMutex_Cpp11<TMutex>)));
|
||||||
|
if (!mutex)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return new (mutex) GpMutex_Cpp11<TMutex>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
void GpMutex_Cpp11<TMutex>::Lock()
|
||||||
|
{
|
||||||
|
m_mutex.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class TMutex>
|
||||||
|
void GpMutex_Cpp11<TMutex>::Unlock()
|
||||||
|
{
|
||||||
|
m_mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef GpMutex_Cpp11<std::mutex> GpMutex_Cpp11_NonRecursive;
|
||||||
|
typedef GpMutex_Cpp11<std::recursive_mutex> GpMutex_Cpp11_Recursive;
|
||||||
82
AerofoilSDL/GpThreadEvent_Cpp11.cpp
Normal file
82
AerofoilSDL/GpThreadEvent_Cpp11.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include "GpThreadEvent_Cpp11.h"
|
||||||
|
|
||||||
|
GpThreadEvent_Cpp11::GpThreadEvent_Cpp11(bool autoReset, bool startSignaled)
|
||||||
|
: m_flag(startSignaled)
|
||||||
|
, m_autoReset(autoReset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GpThreadEvent_Cpp11::~GpThreadEvent_Cpp11()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GpThreadEvent_Cpp11::Wait()
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
if (m_autoReset)
|
||||||
|
{
|
||||||
|
m_cvar.wait(lock,[&]()->bool{
|
||||||
|
if (m_flag)
|
||||||
|
{
|
||||||
|
m_flag = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_cvar.wait(lock,[&]()->bool{ return m_flag; });
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GpThreadEvent_Cpp11::WaitTimed(uint32_t msec)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
if (m_autoReset)
|
||||||
|
{
|
||||||
|
if (!m_cvar.wait_for(lock, std::chrono::milliseconds(msec), [&]()->bool{
|
||||||
|
if (m_flag)
|
||||||
|
{
|
||||||
|
m_flag = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!m_cvar.wait_for(lock, std::chrono::milliseconds(msec), [&]()->bool{ return m_flag; }))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GpThreadEvent_Cpp11::Signal()
|
||||||
|
{
|
||||||
|
m_mutex.lock();
|
||||||
|
m_flag = true;
|
||||||
|
m_mutex.unlock();
|
||||||
|
if (m_autoReset)
|
||||||
|
m_cvar.notify_one();
|
||||||
|
else
|
||||||
|
m_cvar.notify_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GpThreadEvent_Cpp11::Destroy()
|
||||||
|
{
|
||||||
|
this->~GpThreadEvent_Cpp11();
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GpThreadEvent_Cpp11 *GpThreadEvent_Cpp11::Create(bool autoReset, bool startSignaled)
|
||||||
|
{
|
||||||
|
GpThreadEvent_Cpp11 *evt = static_cast<GpThreadEvent_Cpp11*>(malloc(sizeof(GpThreadEvent_Cpp11)));
|
||||||
|
if (!evt)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return new (evt) GpThreadEvent_Cpp11(autoReset, startSignaled);
|
||||||
|
}
|
||||||
|
|
||||||
28
AerofoilSDL/GpThreadEvent_Cpp11.h
Normal file
28
AerofoilSDL/GpThreadEvent_Cpp11.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IGpThreadEvent.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
class GpThreadEvent_Cpp11 final : public IGpThreadEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~GpThreadEvent_Cpp11();
|
||||||
|
|
||||||
|
void Wait() override;
|
||||||
|
bool WaitTimed(uint32_t msec) override;
|
||||||
|
void Signal() override;
|
||||||
|
void Destroy() override;
|
||||||
|
|
||||||
|
static GpThreadEvent_Cpp11 *Create(bool autoReset, bool startSignaled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
GpThreadEvent_Cpp11(bool autoReset, bool startSignaled);
|
||||||
|
GpThreadEvent_Cpp11() = delete;
|
||||||
|
|
||||||
|
std::mutex m_mutex;
|
||||||
|
std::condition_variable m_cvar;
|
||||||
|
bool m_flag;
|
||||||
|
bool m_autoReset;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user