2 #if defined(__ANDROID__)
3 #include <android/log.h>
5 #define printf(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "ecere-app", __VA_ARGS__))
17 #define String _String
18 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
19 #define WIN32_LEAN_AND_MEAN
30 #if !defined(__EMSCRIPTEN__)
32 // Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
33 public int64 GetCurrentThreadID()
35 #if defined(__WIN32__)
36 return (int64)GetCurrentThreadId();
38 return (int64)pthread_self();
42 public class Mutex : struct
45 #if defined(__WIN32__)
49 CRITICAL_SECTION mutex;
52 pthread_mutex_t mutex;
62 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
64 mutex = CreateMutex(null, FALSE, null);
66 InitializeCriticalSection(&mutex);
69 pthread_mutexattr_t attr;
70 pthread_mutexattr_init(&attr);
72 // settype is available on Linux now, and hopefully _GNU_SOURCE should ensure it is
73 #if 0 // def __linux__
74 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
76 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
79 pthread_mutex_init(&mutex, &attr);
80 pthread_mutexattr_destroy(&attr);
91 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
95 DeleteCriticalSection(&mutex);
98 pthread_mutex_destroy(&mutex);
108 if(this == globalSystem.fileMonitorMutex)
109 printf("[%d] Waiting on Mutex %x\n", (int)GetCurrentThreadID(), this);
111 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
113 if(WaitForSingleObject(mutex, INFINITE /*2000*/) == WAIT_TIMEOUT)
114 PrintLn("Deadlock?");
116 EnterCriticalSection(&mutex);
122 e = pthread_mutex_lock(&mutex);
124 PrintLn("pthread_mutex_lock returned ", e);
127 pthread_mutex_lock(&mutex);
132 owningThread = GetCurrentThreadID();
143 if(this == globalSystem.fileMonitorMutex)
144 printf("[%d] Releasing Mutex %x\n", (int)GetCurrentThreadID(), this);
147 if(lockCount && owningThread != GetCurrentThreadID())
148 PrintLn("WARNING: Not in owning thread!!");
157 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
161 LeaveCriticalSection(&mutex);
167 e = pthread_mutex_unlock(&mutex);
169 PrintLn("pthread_mutex_unlock returned ", e);
172 pthread_mutex_unlock(&mutex);
177 PrintLn("WARNING: lockCount < 0");
182 property int lockCount { get { return lockCount; } }
185 #endif // !defined(__EMSCRIPTEN__)