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 // Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
31 public int64 GetCurrentThreadID()
33 #if defined(__WIN32__)
34 return (int64)GetCurrentThreadId();
36 return (int64)pthread_self();
40 public class Mutex : struct
43 #if defined(__WIN32__)
47 CRITICAL_SECTION mutex;
50 pthread_mutex_t mutex;
60 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
62 mutex = CreateMutex(null, FALSE, null);
64 InitializeCriticalSection(&mutex);
67 pthread_mutexattr_t attr;
68 pthread_mutexattr_init(&attr);
70 // settype is available on Linux now, and hopefully _GNU_SOURCE should ensure it is
71 #if 0 // def __linux__
72 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
74 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
77 pthread_mutex_init(&mutex, &attr);
78 pthread_mutexattr_destroy(&attr);
89 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
93 DeleteCriticalSection(&mutex);
96 pthread_mutex_destroy(&mutex);
106 if(this == globalSystem.fileMonitorMutex)
107 printf("[%d] Waiting on Mutex %x\n", (int)GetCurrentThreadID(), this);
109 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
111 if(WaitForSingleObject(mutex, INFINITE /*2000*/) == WAIT_TIMEOUT)
112 PrintLn("Deadlock?");
114 EnterCriticalSection(&mutex);
120 e = pthread_mutex_lock(&mutex);
122 PrintLn("pthread_mutex_lock returned ", e);
125 pthread_mutex_lock(&mutex);
130 owningThread = GetCurrentThreadID();
141 if(this == globalSystem.fileMonitorMutex)
142 printf("[%d] Releasing Mutex %x\n", (int)GetCurrentThreadID(), this);
145 if(lockCount && owningThread != GetCurrentThreadID())
146 PrintLn("WARNING: Not in owning thread!!");
155 #if defined(__WIN32__) && !defined(__EMSCRIPTEN__)
159 LeaveCriticalSection(&mutex);
165 e = pthread_mutex_unlock(&mutex);
167 PrintLn("pthread_mutex_unlock returned ", e);
170 pthread_mutex_unlock(&mutex);
175 PrintLn("WARNING: lockCount < 0");
180 property int lockCount { get { return lockCount; } }