Port server core to Android
* Android libutils locks and threads
* Add Android.mk for building with AOSP
* Add logger sink for Android
* Regenerate Android.mk when CMake is run
diff --git a/common/os/Mutex.cxx b/common/os/Mutex.cxx
index 13013cf..4794568 100644
--- a/common/os/Mutex.cxx
+++ b/common/os/Mutex.cxx
@@ -18,6 +18,10 @@
#ifdef WIN32
#include <windows.h>
+#elif defined(__ANDROID__)
+#include <utils/Errors.h>
+#include <utils/Mutex.h>
+#include <utils/Condition.h>
#else
#include <pthread.h>
#endif
@@ -33,6 +37,8 @@
#ifdef WIN32
systemMutex = new CRITICAL_SECTION;
InitializeCriticalSection((CRITICAL_SECTION*)systemMutex);
+#elif defined(__ANDROID__)
+ systemMutex = new ::android::Mutex;
#else
int ret;
@@ -48,6 +54,8 @@
#ifdef WIN32
DeleteCriticalSection((CRITICAL_SECTION*)systemMutex);
delete (CRITICAL_SECTION*)systemMutex;
+#elif defined(__ANDROID__)
+ delete (::android::Mutex*)systemMutex;
#else
pthread_mutex_destroy((pthread_mutex_t*)systemMutex);
delete (pthread_mutex_t*)systemMutex;
@@ -58,6 +66,12 @@
{
#ifdef WIN32
EnterCriticalSection((CRITICAL_SECTION*)systemMutex);
+#elif defined(__ANDROID__)
+ android::status_t ret;
+
+ ret = ((::android::Mutex*)systemMutex)->lock();
+ if (ret != android::NO_ERROR)
+ throw rdr::SystemException("Failed to lock mutex", ret);
#else
int ret;
@@ -71,6 +85,8 @@
{
#ifdef WIN32
LeaveCriticalSection((CRITICAL_SECTION*)systemMutex);
+#elif defined(__ANDROID__)
+ ((::android::Mutex*)systemMutex)->unlock();
#else
int ret;
@@ -87,6 +103,8 @@
#ifdef WIN32
systemCondition = new CONDITION_VARIABLE;
InitializeConditionVariable((CONDITION_VARIABLE*)systemCondition);
+#elif defined(__ANDROID__)
+ systemCondition = new ::android::Condition;
#else
int ret;
@@ -101,6 +119,8 @@
{
#ifdef WIN32
delete (CONDITION_VARIABLE*)systemCondition;
+#elif defined(__ANDROID__)
+ delete (::android::Condition*)systemCondition;
#else
pthread_cond_destroy((pthread_cond_t*)systemCondition);
delete (pthread_cond_t*)systemCondition;
@@ -117,6 +137,12 @@
INFINITE);
if (!ret)
throw rdr::SystemException("Failed to wait on condition variable", GetLastError());
+#elif defined(__ANDROID__)
+ android::status_t ret;
+
+ ret = ((::android::Condition*)systemCondition)->wait(*(::android::Mutex*)mutex->systemMutex);
+ if (ret != android::NO_ERROR)
+ throw rdr::SystemException("Failed to wait on condition variable", ret);
#else
int ret;
@@ -131,6 +157,8 @@
{
#ifdef WIN32
WakeConditionVariable((CONDITION_VARIABLE*)systemCondition);
+#elif defined(__ANDROID__)
+ ((::android::Condition*)systemCondition)->signal();
#else
int ret;
@@ -144,6 +172,8 @@
{
#ifdef WIN32
WakeAllConditionVariable((CONDITION_VARIABLE*)systemCondition);
+#elif defined(__ANDROID__)
+ ((::android::Condition*)systemCondition)->broadcast();
#else
int ret;