#include <mono/io-layer/wapi.h>
#include <mono/io-layer/wapi-private.h>
-#include <mono/io-layer/misc-private.h>
#include <mono/io-layer/handles-private.h>
-#include <mono/io-layer/mono-mutex.h>
#include <mono/io-layer/semaphore-private.h>
+#include <mono/utils/mono-once.h>
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
static void sema_signal(gpointer handle);
static gboolean sema_own (gpointer handle);
static void sem_ops_init (void)
{
_wapi_handle_register_capabilities (WAPI_HANDLE_SEM,
- WAPI_HANDLE_CAP_WAIT |
- WAPI_HANDLE_CAP_SIGNAL);
+ (WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL));
_wapi_handle_register_capabilities (WAPI_HANDLE_NAMEDSEM,
- WAPI_HANDLE_CAP_WAIT |
- WAPI_HANDLE_CAP_SIGNAL);
+ (WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL));
}
static void sema_signal(gpointer handle)
return(FALSE);
}
-#ifdef DEBUG
- g_message("%s: owning sem handle %p", __func__, handle);
-#endif
+ DEBUG("%s: owning sem handle %p", __func__, handle);
sem_handle->val--;
-#ifdef DEBUG
- g_message ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
-#endif
+ DEBUG ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
if(sem_handle->val==0) {
_wapi_handle_set_signal_state (handle, FALSE, FALSE);
struct _WapiHandle_namedsem *namedsem_handle;
gboolean ok;
-#ifdef DEBUG
- g_message ("%s: owning named sem handle %p", __func__, handle);
-#endif
+ DEBUG ("%s: owning named sem handle %p", __func__, handle);
ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDSEM,
(gpointer *)&namedsem_handle);
namedsem_handle->val--;
-#ifdef DEBUG
- g_message ("%s: named sem %p val now %d", __func__, handle,
+ DEBUG ("%s: named sem %p val now %d", __func__, handle,
namedsem_handle->val);
-#endif
if (namedsem_handle->val == 0) {
_wapi_shared_handle_set_signal_state (handle, FALSE);
return(NULL);
}
- pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
- handle);
thr_ret = _wapi_handle_lock_handle (handle);
g_assert (thr_ret == 0);
_wapi_handle_set_signal_state (handle, TRUE, FALSE);
}
-#ifdef DEBUG
- g_message ("%s: Created semaphore handle %p initial %d max %d",
+ DEBUG ("%s: Created semaphore handle %p initial %d max %d",
__func__, handle, initial, max);
-#endif
thr_ret = _wapi_handle_unlock_handle (handle);
g_assert (thr_ret == 0);
- pthread_cleanup_pop (0);
return(handle);
}
utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
-#ifdef DEBUG
- g_message ("%s: Creating named sem [%s]", __func__, utf8_name);
-#endif
+ DEBUG ("%s: Creating named sem [%s]", __func__, utf8_name);
offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDSEM,
utf8_name);
_wapi_handle_unlock_shared_handles ();
}
-#ifdef DEBUG
- g_message ("%s: returning named sem handle %p", __func__, handle);
-#endif
+ DEBUG ("%s: returning named sem handle %p", __func__, handle);
cleanup:
g_free (utf8_name);
mono_once (&sem_ops_once, sem_ops_init);
if (max <= 0) {
-#ifdef DEBUG
- g_message ("%s: max <= 0", __func__);
-#endif
+ DEBUG ("%s: max <= 0", __func__);
SetLastError (ERROR_INVALID_PARAMETER);
return(NULL);
}
if (initial > max || initial < 0) {
-#ifdef DEBUG
- g_message ("%s: initial>max or < 0", __func__);
-#endif
+ DEBUG ("%s: initial>max or < 0", __func__);
SetLastError (ERROR_INVALID_PARAMETER);
return(NULL);
return(FALSE);
}
- pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
- handle);
thr_ret = _wapi_handle_lock_handle (handle);
g_assert (thr_ret == 0);
-#ifdef DEBUG
- g_message ("%s: sem %p val %d count %d", __func__, handle,
+ DEBUG ("%s: sem %p val %d count %d", __func__, handle,
sem_handle->val, count);
-#endif
/* Do this before checking for count overflow, because overflowing max
* is a listed technique for finding the current value
/* No idea why max is signed, but thats the spec :-( */
if (sem_handle->val + count > (guint32)sem_handle->max) {
-#ifdef DEBUG
- g_message ("%s: sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
-#endif
+ DEBUG ("%s: sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
goto end;
}
ret = TRUE;
-#ifdef DEBUG
- g_message ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
-#endif
+ DEBUG ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
end:
thr_ret = _wapi_handle_unlock_handle (handle);
g_assert (thr_ret == 0);
- pthread_cleanup_pop (0);
return(ret);
}
thr_ret = _wapi_handle_lock_shared_handles ();
g_assert (thr_ret == 0);
-#ifdef DEBUG
- g_message("%s: named sem %p val %d count %d", __func__, handle,
+ DEBUG("%s: named sem %p val %d count %d", __func__, handle,
sem_handle->val, count);
-#endif
/* Do this before checking for count overflow, because overflowing max
* is a listed technique for finding the current value
/* No idea why max is signed, but thats the spec :-( */
if (sem_handle->val + count > (guint32)sem_handle->max) {
-#ifdef DEBUG
- g_message ("%s: named sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
-#endif
+ DEBUG ("%s: named sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
goto end;
}
ret = TRUE;
-#ifdef DEBUG
- g_message("%s: named sem %p val now %d", __func__, handle,
+ DEBUG("%s: named sem %p val now %d", __func__, handle,
sem_handle->val);
-#endif
end:
_wapi_handle_unlock_shared_handles ();
utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
-#ifdef DEBUG
- g_message ("%s: Opening named sem [%s]", __func__, utf8_name);
-#endif
+ DEBUG ("%s: Opening named sem [%s]", __func__, utf8_name);
offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDSEM,
utf8_name);
}
ret = handle;
-#ifdef DEBUG
- g_message ("%s: returning named sem handle %p", __func__, handle);
-#endif
+ DEBUG ("%s: returning named sem handle %p", __func__, handle);
cleanup:
g_free (utf8_name);