mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-17 17:05:24 +00:00
OS X thread-local fixes
This commit is contained in:
@@ -15,7 +15,7 @@ class GLDataFactory : public IGraphicsDataFactory
|
||||
{
|
||||
friend struct GLCommandQueue;
|
||||
IGraphicsContext* m_parent;
|
||||
static thread_local struct GLData* m_deferredData;
|
||||
static ThreadLocalPtr<struct GLData> m_deferredData;
|
||||
std::unordered_set<struct GLData*> m_committedData;
|
||||
std::mutex m_committedMutex;
|
||||
std::vector<int> m_texUnis;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#include "boo/System.hpp"
|
||||
|
||||
namespace boo
|
||||
@@ -226,6 +227,28 @@ private:
|
||||
virtual void destroyAllData()=0;
|
||||
};
|
||||
|
||||
/** Multiplatform TLS-pointer wrapper (for compilers without proper thread_local support) */
|
||||
template <class T>
|
||||
class ThreadLocalPtr
|
||||
{
|
||||
#if _WIN32
|
||||
DWORD m_key;
|
||||
public:
|
||||
ThreadLocalPtr() {m_key = TlsAlloc();}
|
||||
~ThreadLocalPtr() {TlsFree(m_key);}
|
||||
T* get() {return static_cast<T*>(TlsGetValue(m_key));}
|
||||
void reset(T* v=nullptr) {TlsSetValue(m_key, v);}
|
||||
#else
|
||||
pthread_key_t m_key;
|
||||
public:
|
||||
ThreadLocalPtr() {pthread_key_create(&m_key, nullptr);}
|
||||
~ThreadLocalPtr() {pthread_key_delete(m_key);}
|
||||
T* get() {return static_cast<T*>(pthread_getspecific(m_key));}
|
||||
void reset(T* v=nullptr) {pthread_setspecific(m_key, v);}
|
||||
#endif
|
||||
T* operator->() {return get();}
|
||||
};
|
||||
|
||||
/** Ownership token for maintaining lifetime of factory-created resources
|
||||
* deletion of this token triggers mass-deallocation of the factory's
|
||||
* IGraphicsData (please don't delete and draw contained resources in the same frame). */
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "IGraphicsCommandQueue.hpp"
|
||||
#include "boo/IGraphicsContext.hpp"
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -22,8 +23,9 @@ class MetalDataFactory : public IGraphicsDataFactory
|
||||
{
|
||||
friend struct MetalCommandQueue;
|
||||
IGraphicsContext* m_parent;
|
||||
struct MetalData* m_deferredData = nullptr;
|
||||
static ThreadLocalPtr<struct MetalData> m_deferredData;
|
||||
std::unordered_set<struct MetalData*> m_committedData;
|
||||
std::mutex m_committedMutex;
|
||||
struct MetalContext* m_ctx;
|
||||
|
||||
void destroyData(IGraphicsData*);
|
||||
@@ -64,7 +66,7 @@ public:
|
||||
size_t texCount, ITexture** texs);
|
||||
|
||||
void reset();
|
||||
IGraphicsDataToken commit();
|
||||
GraphicsDataToken commit();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user