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
42 #if !defined(__EMSCRIPTEN__)
45 #if defined(__WIN32__)
49 CRITICAL_SECTION mutex;
52 pthread_mutex_t mutex;
63 #if !defined(__EMSCRIPTEN__)
64 #if defined(__WIN32__)
66 mutex = CreateMutex(null, FALSE, null);
68 InitializeCriticalSection(&mutex);
71 pthread_mutexattr_t attr;
72 pthread_mutexattr_init(&attr);
74 // settype is available on Linux now, and hopefully _GNU_SOURCE should ensure it is
75 #if 0 // def __linux__
76 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
78 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
81 pthread_mutex_init(&mutex, &attr);
82 pthread_mutexattr_destroy(&attr);
95 #if !defined(__EMSCRIPTEN__)
96 #if defined(__WIN32__)
100 DeleteCriticalSection(&mutex);
103 pthread_mutex_destroy(&mutex);
113 #if !defined(__EMSCRIPTEN__)
115 if(this == globalSystem.fileMonitorMutex)
116 printf("[%d] Waiting on Mutex %x\n", (int)GetCurrentThreadID(), this);
118 #if defined(__WIN32__)
120 if(WaitForSingleObject(mutex, INFINITE /*2000*/) == WAIT_TIMEOUT)
121 PrintLn("Deadlock?");
123 EnterCriticalSection(&mutex);
129 e = pthread_mutex_lock(&mutex);
131 PrintLn("pthread_mutex_lock returned ", e);
134 pthread_mutex_lock(&mutex);
141 owningThread = GetCurrentThreadID();
151 #if !defined(__EMSCRIPTEN__)
153 if(this == globalSystem.fileMonitorMutex)
154 printf("[%d] Releasing Mutex %x\n", (int)GetCurrentThreadID(), this);
157 if(lockCount && owningThread != GetCurrentThreadID())
158 PrintLn("WARNING: Not in owning thread!!");
167 #if defined(__WIN32__)
171 LeaveCriticalSection(&mutex);
177 e = pthread_mutex_unlock(&mutex);
179 PrintLn("pthread_mutex_unlock returned ", e);
182 pthread_mutex_unlock(&mutex);
189 PrintLn("WARNING: lockCount < 0");
194 property int lockCount { get { return lockCount; } }