3 #if defined(__ANDROID__)
4 #include <android/log.h>
6 #define printf(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "ecere-app", __VA_ARGS__))
18 #define String _String
19 #if defined(__WIN32__)
20 #define WIN32_LEAN_AND_MEAN
31 // Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
32 public int64 GetCurrentThreadID()
34 #if defined(__WIN32__)
35 return (int64)GetCurrentThreadId();
37 return (int64)pthread_self();
41 public class Mutex : struct
43 #if !defined(__EMSCRIPTEN__)
46 #if defined(__WIN32__)
50 CRITICAL_SECTION mutex;
53 pthread_mutex_t mutex;
64 #if !defined(__EMSCRIPTEN__)
65 #if defined(__WIN32__)
67 mutex = CreateMutex(null, FALSE, null);
69 InitializeCriticalSection(&mutex);
72 pthread_mutexattr_t attr;
73 pthread_mutexattr_init(&attr);
75 // settype is available on Linux now, and hopefully _GNU_SOURCE should ensure it is
76 #if 0 // def __linux__
77 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
79 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
82 pthread_mutex_init(&mutex, &attr);
83 pthread_mutexattr_destroy(&attr);
96 #if !defined(__EMSCRIPTEN__)
97 #if defined(__WIN32__)
101 DeleteCriticalSection(&mutex);
104 pthread_mutex_destroy(&mutex);
114 #if !defined(__EMSCRIPTEN__)
116 if(this == globalSystem.fileMonitorMutex)
117 printf("[%d] Waiting on Mutex %x\n", (int)GetCurrentThreadID(), this);
119 #if defined(__WIN32__)
121 if(WaitForSingleObject(mutex, INFINITE /*2000*/) == WAIT_TIMEOUT)
122 PrintLn("Deadlock?");
124 EnterCriticalSection(&mutex);
130 e = pthread_mutex_lock(&mutex);
132 PrintLn("pthread_mutex_lock returned ", e);
135 pthread_mutex_lock(&mutex);
142 _owningThread = GetCurrentThreadID();
152 #if !defined(__EMSCRIPTEN__)
154 if(this == globalSystem.fileMonitorMutex)
155 printf("[%d] Releasing Mutex %x\n", (int)GetCurrentThreadID(), this);
158 if(_lockCount && _owningThread != GetCurrentThreadID())
159 PrintLn("WARNING: Not in owning thread!!");
168 #if defined(__WIN32__)
172 LeaveCriticalSection(&mutex);
178 e = pthread_mutex_unlock(&mutex);
180 PrintLn("pthread_mutex_unlock returned ", e);
183 pthread_mutex_unlock(&mutex);
190 PrintLn("WARNING: lockCount < 0");
195 property int lockCount { get { return _lockCount; } }
196 property int64 owningThread { get { return _owningThread; } }