1 #if defined(__ANDROID__)
2 #include <android/log.h>
4 #define printf(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, "ecere-app", __VA_ARGS__))
14 #define String _String
15 #if defined(__WIN32__)
16 #define WIN32_LEAN_AND_MEAN
27 // Moved this here from Thread.ec to make compiling ecereCOM in Debug easier
28 public int GetCurrentThreadID()
30 #if defined(__WIN32__)
31 return (int)GetCurrentThreadId();
33 return (int)pthread_self();
37 public class Mutex : struct
40 #if defined(__WIN32__)
44 CRITICAL_SECTION mutex;
47 pthread_mutex_t mutex;
57 #if defined(__WIN32__)
59 mutex = CreateMutex(null, FALSE, null);
61 InitializeCriticalSection(&mutex);
64 pthread_mutexattr_t attr;
65 pthread_mutexattr_init(&attr);
67 // settype is available on Linux now, and hopefully _GNU_SOURCE should ensure it is
68 #if 0 // def __linux__
69 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
71 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
74 pthread_mutex_init(&mutex, &attr);
75 pthread_mutexattr_destroy(&attr);
86 #if defined(__WIN32__)
90 DeleteCriticalSection(&mutex);
93 pthread_mutex_destroy(&mutex);
103 if(this == globalSystem.fileMonitorMutex)
104 printf("[%d] Waiting on Mutex %x\n", GetCurrentThreadID(), this);
106 #if defined(__WIN32__)
108 if(WaitForSingleObject(mutex, INFINITE /*2000*/) == WAIT_TIMEOUT)
109 PrintLn("Deadlock?");
111 EnterCriticalSection(&mutex);
117 e = pthread_mutex_lock(&mutex);
119 PrintLn("pthread_mutex_lock returned ", e);
122 pthread_mutex_lock(&mutex);
127 owningThread = GetCurrentThreadID();
138 if(this == globalSystem.fileMonitorMutex)
139 printf("[%d] Releasing Mutex %x\n", GetCurrentThreadID(), this);
142 if(lockCount && owningThread != GetCurrentThreadID())
143 PrintLn("WARNING: Not in owning thread!!");
152 #if defined(__WIN32__)
156 LeaveCriticalSection(&mutex);
162 e = pthread_mutex_unlock(&mutex);
164 PrintLn("pthread_mutex_unlock returned ", e);
167 pthread_mutex_unlock(&mutex);
172 PrintLn("WARNING: lockCount < 0");