* 4MB array.
*/
static GHashTable *file_share_hash;
-static mono_mutex_t file_share_hash_mutex;
-
-#define file_share_hash_lock() mono_os_mutex_lock (&file_share_hash_mutex)
-#define file_share_hash_unlock() mono_os_mutex_unlock (&file_share_hash_mutex)
+static mono_mutex_t file_share_mutex;
static void
_wapi_handle_share_release (_WapiFileShare *share_info)
{
- int thr_ret;
+ /* Prevent new entries racing with us */
+ mono_os_mutex_lock (&file_share_mutex);
g_assert (share_info->handle_refs > 0);
-
- /* Prevent new entries racing with us */
- thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_FILESHARE);
- g_assert(thr_ret == 0);
+ share_info->handle_refs -= 1;
- if (InterlockedDecrement ((gint32 *)&share_info->handle_refs) == 0) {
- file_share_hash_lock ();
+ if (share_info->handle_refs == 0)
g_hash_table_remove (file_share_hash, share_info);
- file_share_hash_unlock ();
- }
- thr_ret = _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_FILESHARE);
- g_assert (thr_ret == 0);
+ mono_os_mutex_unlock (&file_share_mutex);
}
static gint
guint32 *old_sharemode, guint32 *old_access, struct _WapiFileShare **share_info)
{
struct _WapiFileShare *file_share;
- int thr_ret;
gboolean exists = FALSE;
/* Prevent new entries racing with us */
- thr_ret = _wapi_shm_sem_lock (_WAPI_SHARED_SEM_FILESHARE);
- g_assert (thr_ret == 0);
+ mono_os_mutex_lock (&file_share_mutex);
_WapiFileShare tmp;
* info. This is needed even if SHM is disabled, to track sharing inside
* the current process.
*/
- if (!file_share_hash) {
+ if (!file_share_hash)
file_share_hash = g_hash_table_new_full (wapi_share_info_hash, wapi_share_info_equal, NULL, g_free);
- mono_os_mutex_init_recursive (&file_share_hash_mutex);
- }
tmp.device = device;
tmp.inode = inode;
- file_share_hash_lock ();
-
file_share = (_WapiFileShare *)g_hash_table_lookup (file_share_hash, &tmp);
if (file_share) {
*old_sharemode = file_share->sharemode;
*old_access = file_share->access;
*share_info = file_share;
- InterlockedIncrement ((gint32 *)&file_share->handle_refs);
+ g_assert (file_share->handle_refs > 0);
+ file_share->handle_refs += 1;
+
exists = TRUE;
} else {
file_share = g_new0 (_WapiFileShare, 1);
g_hash_table_insert (file_share_hash, file_share, file_share);
}
- file_share_hash_unlock ();
-
- thr_ret = _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_FILESHARE);
- g_assert (thr_ret == 0);
+ mono_os_mutex_unlock (&file_share_mutex);
return(exists);
}
_wapi_io_init (void)
{
mono_os_mutex_init (&stdhandle_mutex);
+ mono_os_mutex_init (&file_share_mutex);
mono_w32handle_register_ops (MONO_W32HANDLE_FILE, &_wapi_file_ops);
mono_w32handle_register_ops (MONO_W32HANDLE_CONSOLE, &_wapi_console_ops);
void
_wapi_io_cleanup (void)
{
- if (file_share_hash) {
+ mono_os_mutex_destroy (&file_share_mutex);
+
+ if (file_share_hash)
g_hash_table_destroy (file_share_hash);
- mono_os_mutex_destroy (&file_share_hash_mutex);
- }
}