X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fio-layer%2Fhandles-private.h;h=9badbf3bd5da4fb864aef3a767dd1fc142b3e0c3;hb=92e073174174faf925c12d9af1e3c20af70499a1;hp=4f20de02d411248bec7f67f5b4dc256d084696f1;hpb=66321daeda387e7fe76ac7ebfa04a44fc85e905d;p=mono.git diff --git a/mono/io-layer/handles-private.h b/mono/io-layer/handles-private.h index 4f20de02d41..9badbf3bd5d 100644 --- a/mono/io-layer/handles-private.h +++ b/mono/io-layer/handles-private.h @@ -20,21 +20,9 @@ #include #include -#define _WAPI_PRIVATE_MAX_SLOTS (1024 * 16) -#define _WAPI_PRIVATE_HANDLES(x) (_wapi_private_handles [x / _WAPI_HANDLE_INITIAL_COUNT][x % _WAPI_HANDLE_INITIAL_COUNT]) -#define _WAPI_PRIVATE_HAVE_SLOT(x) ((GPOINTER_TO_UINT (x) / _WAPI_PRIVATE_MAX_SLOTS) < _WAPI_PRIVATE_MAX_SLOTS && \ - _wapi_private_handles [GPOINTER_TO_UINT (x) / _WAPI_HANDLE_INITIAL_COUNT] != NULL) -#define _WAPI_PRIVATE_VALID_SLOT(x) (((x) / _WAPI_HANDLE_INITIAL_COUNT) < _WAPI_PRIVATE_MAX_SLOTS) - #undef DEBUG -extern struct _WapiHandleUnshared *_wapi_private_handles []; -extern struct _WapiHandleSharedLayout *_wapi_shared_layout; - extern guint32 _wapi_fd_reserve; -extern mono_mutex_t *_wapi_global_signal_mutex; -extern pthread_cond_t *_wapi_global_signal_cond; -extern int _wapi_sem_id; extern gboolean _wapi_has_shut_down; extern pid_t _wapi_getpid (void); @@ -42,9 +30,6 @@ extern gpointer _wapi_handle_new (WapiHandleType type, gpointer handle_specific); extern gpointer _wapi_handle_new_fd (WapiHandleType type, int fd, gpointer handle_specific); -extern gpointer _wapi_handle_new_from_offset (WapiHandleType type, - guint32 offset, - gboolean timestamp); extern gboolean _wapi_lookup_handle (gpointer handle, WapiHandleType type, gpointer *handle_specific); extern gpointer _wapi_search_handle (WapiHandleType type, @@ -52,7 +37,7 @@ extern gpointer _wapi_search_handle (WapiHandleType type, gpointer user_data, gpointer *handle_specific, gboolean search_shared); -extern gint32 _wapi_search_handle_namespace (WapiHandleType type, +extern gpointer _wapi_search_handle_namespace (WapiHandleType type, gchar *utf8_name); extern void _wapi_handle_ref (gpointer handle); extern void _wapi_handle_unref (gpointer handle); @@ -76,238 +61,43 @@ extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles, guint32 *lowest); extern void _wapi_handle_unlock_handles (guint32 numhandles, gpointer *handles); +extern int _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean poll, gboolean *alerted); extern int _wapi_handle_timedwait_signal (guint32 timeout, gboolean poll, gboolean *alerted); -extern int _wapi_handle_timedwait_signal_handle (gpointer handle, guint32 timeout, gboolean alertable, gboolean poll, gboolean *alerted); extern gboolean _wapi_handle_get_or_set_share (guint64 device, guint64 inode, guint32 new_sharemode, guint32 new_access, guint32 *old_sharemode, guint32 *old_access, struct _WapiFileShare **info); -extern void _wapi_handle_check_share (struct _WapiFileShare *share_info, - int fd); extern void _wapi_handle_dump (void); extern void _wapi_handle_foreach (WapiHandleType type, gboolean (*on_each)(gpointer test, gpointer user), gpointer user_data); void _wapi_free_share_info (_WapiFileShare *share_info); -/* This is OK to use for atomic writes of individual struct members, as they - * are independent - */ -#define WAPI_SHARED_HANDLE_DATA(handle) _wapi_shared_layout->handles[_WAPI_PRIVATE_HANDLES(GPOINTER_TO_UINT((handle))).u.shared.offset] - -#define WAPI_SHARED_HANDLE_TYPED_DATA(handle, type) _wapi_shared_layout->handles[_WAPI_PRIVATE_HANDLES(GPOINTER_TO_UINT((handle))).u.shared.offset].u.type - -static inline WapiHandleType _wapi_handle_type (gpointer handle) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - - if (!_WAPI_PRIVATE_VALID_SLOT (idx) || !_WAPI_PRIVATE_HAVE_SLOT (idx)) { - return(WAPI_HANDLE_UNUSED); /* An impossible type */ - } - - return(_WAPI_PRIVATE_HANDLES(idx).type); -} - -static inline void _wapi_handle_set_signal_state (gpointer handle, - gboolean state, - gboolean broadcast) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - struct _WapiHandleUnshared *handle_data; - int thr_ret; - - if (!_WAPI_PRIVATE_VALID_SLOT (idx)) { - return; - } - - g_assert (!_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))); - - handle_data = &_WAPI_PRIVATE_HANDLES(idx); - -#ifdef DEBUG - g_message ("%s: setting state of %p to %s (broadcast %s)", __func__, - handle, state?"TRUE":"FALSE", broadcast?"TRUE":"FALSE"); -#endif - - if (state == TRUE) { - /* Tell everyone blocking on a single handle */ - - /* The condition the global signal cond is waiting on is the signalling of - * _any_ handle. So lock it before setting the signalled state. - */ - thr_ret = mono_os_mutex_lock (_wapi_global_signal_mutex); - if (thr_ret != 0) - g_warning ("Bad call to mono_os_mutex_lock result %d for global signal mutex", thr_ret); - g_assert (thr_ret == 0); - - /* This function _must_ be called with - * handle->signal_mutex locked - */ - handle_data->signalled=state; - - if (broadcast == TRUE) { - thr_ret = pthread_cond_broadcast (&handle_data->signal_cond); - if (thr_ret != 0) - g_warning ("Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle); - g_assert (thr_ret == 0); - } else { - thr_ret = pthread_cond_signal (&handle_data->signal_cond); - if (thr_ret != 0) - g_warning ("Bad call to pthread_cond_signal result %d for handle %p", thr_ret, handle); - g_assert (thr_ret == 0); - } +WapiHandleType +_wapi_handle_type (gpointer handle); - /* Tell everyone blocking on multiple handles that something - * was signalled - */ - thr_ret = pthread_cond_broadcast (_wapi_global_signal_cond); - if (thr_ret != 0) - g_warning ("Bad call to pthread_cond_broadcast result %d for handle %p", thr_ret, handle); - g_assert (thr_ret == 0); - - thr_ret = mono_os_mutex_unlock (_wapi_global_signal_mutex); - if (thr_ret != 0) - g_warning ("Bad call to mono_os_mutex_unlock result %d for global signal mutex", thr_ret); - g_assert (thr_ret == 0); - } else { - handle_data->signalled=state; - } -} +void +_wapi_handle_set_signal_state (gpointer handle, gboolean state, gboolean broadcast); -static inline void _wapi_shared_handle_set_signal_state (gpointer handle, - gboolean state) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - struct _WapiHandleUnshared *handle_data; - struct _WapiHandle_shared_ref *ref; - struct _WapiHandleShared *shared_data; - - if (!_WAPI_PRIVATE_VALID_SLOT (idx)) { - return; - } - - g_assert (_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))); - - handle_data = &_WAPI_PRIVATE_HANDLES(idx); - - ref = &handle_data->u.shared; - shared_data = &_wapi_shared_layout->handles[ref->offset]; - shared_data->signalled = state; +gboolean +_wapi_handle_issignalled (gpointer handle); -#ifdef DEBUG - g_message ("%s: signalled shared handle offset 0x%x", __func__, - ref->offset); -#endif -} +int +_wapi_handle_lock_signal_mutex (void); -static inline gboolean _wapi_handle_issignalled (gpointer handle) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - - if (!_WAPI_PRIVATE_VALID_SLOT (idx)) { - return(FALSE); - } - - if (_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))) { - return(WAPI_SHARED_HANDLE_DATA(handle).signalled); - } else { - return(_WAPI_PRIVATE_HANDLES(idx).signalled); - } -} - -static inline int _wapi_handle_lock_signal_mutex (void) -{ -#ifdef DEBUG - g_message ("%s: lock global signal mutex", __func__); -#endif +int +_wapi_handle_unlock_signal_mutex (void); - return(mono_os_mutex_lock (_wapi_global_signal_mutex)); -} +int +_wapi_handle_lock_handle (gpointer handle); -/* the parameter makes it easier to call from a pthread cleanup handler */ -static inline int _wapi_handle_unlock_signal_mutex (void *unused) -{ -#ifdef DEBUG - g_message ("%s: unlock global signal mutex", __func__); -#endif +int +_wapi_handle_trylock_handle (gpointer handle); - return(mono_os_mutex_unlock (_wapi_global_signal_mutex)); -} - -static inline int _wapi_handle_lock_handle (gpointer handle) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - -#ifdef DEBUG - g_message ("%s: locking handle %p", __func__, handle); -#endif - - if (!_WAPI_PRIVATE_VALID_SLOT (idx)) { - return(0); - } - - _wapi_handle_ref (handle); - - if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) { - return(0); - } - - return(mono_os_mutex_lock (&_WAPI_PRIVATE_HANDLES(idx).signal_mutex)); -} - -static inline int _wapi_handle_trylock_handle (gpointer handle) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - int ret; - -#ifdef DEBUG - g_message ("%s: locking handle %p", __func__, handle); -#endif - - if (!_WAPI_PRIVATE_VALID_SLOT (idx)) { - return(0); - } - - _wapi_handle_ref (handle); - - if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) { - return(0); - } - - ret = mono_os_mutex_trylock (&_WAPI_PRIVATE_HANDLES(idx).signal_mutex); - if (ret != 0) { - _wapi_handle_unref (handle); - } - - return(ret); -} - -static inline int _wapi_handle_unlock_handle (gpointer handle) -{ - guint32 idx = GPOINTER_TO_UINT(handle); - int ret; - -#ifdef DEBUG - g_message ("%s: unlocking handle %p", __func__, handle); -#endif - - if (!_WAPI_PRIVATE_VALID_SLOT (idx)) { - return(0); - } - - if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) { - _wapi_handle_unref (handle); - return(0); - } - - ret = mono_os_mutex_unlock (&_WAPI_PRIVATE_HANDLES(idx).signal_mutex); - - _wapi_handle_unref (handle); - - return(ret); -} +int +_wapi_handle_unlock_handle (gpointer handle); static inline void _wapi_handle_spin (guint32 ms) { @@ -321,21 +111,6 @@ static inline void _wapi_handle_spin (guint32 ms) nanosleep (&sleepytime, NULL); } -static inline int _wapi_handle_lock_shared_handles (void) -{ - return(_wapi_shm_sem_lock (_WAPI_SHARED_SEM_SHARED_HANDLES)); -} - -static inline int _wapi_handle_trylock_shared_handles (void) -{ - return(_wapi_shm_sem_trylock (_WAPI_SHARED_SEM_SHARED_HANDLES)); -} - -static inline int _wapi_handle_unlock_shared_handles (void) -{ - return(_wapi_shm_sem_unlock (_WAPI_SHARED_SEM_SHARED_HANDLES)); -} - static inline int _wapi_namespace_lock (void) { return(_wapi_shm_sem_lock (_WAPI_SHARED_SEM_NAMESPACE));