#include "Thread.hpp"
+#ifdef __ANDROID__
+// Use an actual mutex on Android. Since many processes may use SwiftShader
+// at the same time it's best to just have the scheduler overhead.
+#include <pthread.h>
+
+namespace sw
+{
+ class MutexLock
+ {
+ public:
+ MutexLock()
+ {
+ pthread_mutex_init(&mutex, NULL);
+ }
+
+ ~MutexLock()
+ {
+ pthread_mutex_destroy(&mutex);
+ }
+
+ bool attemptLock()
+ {
+ return pthread_mutex_trylock(&mutex) == 0;
+ }
+
+ void lock()
+ {
+ pthread_mutex_lock(&mutex);
+ }
+
+ void unlock()
+ {
+ pthread_mutex_unlock(&mutex);
+ }
+
+ private:
+ pthread_mutex_t mutex;
+ };
+}
+
+#else // !__ANDROID__
+
namespace sw
{
class BackoffLock
volatile int padding2[15];
};
};
+
+ using MutexLock = BackoffLock;
}
+#endif // !__ANDROID__
+
+class LockGuard
+{
+public:
+ explicit LockGuard(sw::MutexLock &mutex) : mutex(mutex)
+ {
+ mutex.lock();
+ }
+
+ ~LockGuard()
+ {
+ mutex.unlock();
+ }
+
+protected:
+ sw::MutexLock &mutex;
+};
+
#endif // sw_MutexLock_hpp
private:
~Resource(); // Always call destruct() instead
- BackoffLock criticalSection;
+ MutexLock criticalSection;
Event unblock;
volatile int blocked;
Thread *serverThread;
volatile bool terminate;
- BackoffLock criticalSection; // Protects reading and writing the configuration settings
+ MutexLock criticalSection; // Protects reading and writing the configuration settings
bool newConfig;
#include <vector>
#include <map>
-class Guard
-{
-public:
- explicit Guard(sw::BackoffLock* in) : mMutex(in)
- {
- mMutex->lock();
- }
-
- ~Guard()
- {
- mMutex->unlock();
- }
-protected:
- sw::BackoffLock* mMutex;
-};
-
namespace egl
{
EGLSyncKHR Display::createSync(Context *context)
{
FenceSync *fenceSync = new egl::FenceSync(context);
- Guard lk(&mSyncSetMutex);
+ LockGuard lock(mSyncSetMutex);
mSyncSet.insert(fenceSync);
return fenceSync;
}
void Display::destroySync(FenceSync *sync)
{
{
- Guard lk(&mSyncSetMutex);
+ LockGuard lock(mSyncSetMutex);
mSyncSet.erase(sync);
}
delete sync;
bool Display::isValidSync(FenceSync *sync)
{
- Guard lk(&mSyncSetMutex);
+ LockGuard lock(mSyncSetMutex);
return mSyncSet.find(sync) != mSyncSet.end();
}
ContextSet mContextSet;
typedef std::set<FenceSync*> SyncSet;
- sw::BackoffLock mSyncSetMutex;
+ sw::MutexLock mSyncSetMutex;
SyncSet mSyncSet;
gl::NameSpace<Image> mSharedImageNameSpace;
llvm::Module *module = nullptr;
llvm::Function *function = nullptr;
- sw::BackoffLock codegenMutex;
+ sw::MutexLock codegenMutex;
}
namespace sw
Routine *generate(BlitState &state);
RoutineCache<BlitState> *blitCache;
- BackoffLock criticalSection;
+ MutexLock criticalSection;
};
extern Blitter blitter;
unsigned int qHead;
unsigned int qSize;
- BackoffLock schedulerMutex;
+ MutexLock schedulerMutex;
#if PERF_HUD
int64_t vertexTime[16];