Do not include silcdefs.h in installed headers anymore. Include
[silc.git] / lib / silcutil / win32 / silcwin32mutex.c
index 690c2a2074e602c3b9e5a2dae8d58ff6a391f4d4..95a6e2651262ee7d203cd98dd0fa27b032f71649 100644 (file)
 
 #include "silcincludes.h"
 
-#ifdef SILC_THREADS
-
 /* SILC Mutex structure */
 struct SilcMutexStruct {
+#ifdef SILC_THREADS
   HANDLE mutex;
+#else
+  void *tmp;
+#endif /* SILC_THREADS */
 };
 
-SilcMutex silc_mutex_alloc(void)
+bool silc_mutex_alloc(SilcMutex *mutex)
 {
-  SilcMutex mutex = silc_calloc(1, sizeof(*mutex));
-  mutex->mutex = CreateMutex(NULL, FALSE, NULL);
-  if (!mutex->mutex) {
-    silc_free(mutex);
-    return NULL;
+#ifdef SILC_THREADS
+  *mutex = silc_calloc(1, sizeof(**mutex));
+  (*mutex)->mutex = CreateMutex(NULL, FALSE, NULL);
+  if (!(*mutex)->mutex) {
+    silc_free(*mutex);
+    return FALSE;
   }
-  return mutex;
+#endif /* SILC_THREADS */
+  return TRUE;
 }
 
 void silc_mutex_free(SilcMutex mutex)
 {
+#ifdef SILC_THREADS
   CloseHandle(mutex->mutex);
   silc_free(mutex);
+#endif /* SILC_THREADS */
 }
 
 void silc_mutex_lock(SilcMutex mutex)
 {
+#ifdef SILC_THREADS
   WaitForSingleObject(mutex->mutex, INFINITE);
+#endif /* SILC_THREADS */
 }
 
 void silc_mutex_unlock(SilcMutex mutex)
 {
+#ifdef SILC_THREADS
   ReleaseMutex(mutex->mutex);
-}
-
 #endif /* SILC_THREADS */
+}