2 * handles-private.h: Internal operations on handles
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, Inc.
10 #ifndef _WAPI_HANDLES_PRIVATE_H_
11 #define _WAPI_HANDLES_PRIVATE_H_
16 #include <mono/io-layer/wait-private.h>
17 #include <mono/io-layer/shared.h>
21 extern struct _WapiHandleShared_list *_wapi_shared_data;
22 extern struct _WapiHandlePrivate_list *_wapi_private_data;
24 extern void _wapi_handle_init (void);
26 extern guint32 _wapi_handle_new_internal (WapiHandleType type);
27 extern gpointer _wapi_handle_new (WapiHandleType type);
28 extern gboolean _wapi_lookup_handle (gpointer handle, WapiHandleType type,
29 gpointer *shared, gpointer *private);
30 extern void _wapi_handle_ref (gpointer handle);
31 extern void _wapi_handle_unref (gpointer handle);
32 extern guint32 _wapi_handle_scratch_store_internal (guint32 bytes);
33 extern guint32 _wapi_handle_scratch_store (gconstpointer data, guint32 bytes);
34 extern gconstpointer _wapi_handle_scratch_lookup (guint32 idx);
35 extern guchar *_wapi_handle_scratch_lookup_as_string (guint32 idx);
36 extern void _wapi_handle_scratch_delete_internal (guint32 idx);
37 extern void _wapi_handle_scratch_delete (guint32 idx);
38 extern void _wapi_handle_register_capabilities (WapiHandleType type,
39 WapiHandleCapability caps);
40 extern gboolean _wapi_handle_test_capabilities (gpointer handle,
41 WapiHandleCapability caps);
42 extern void _wapi_handle_ops_close_shared (gpointer handle);
43 extern void _wapi_handle_ops_close_private (gpointer handle);
44 extern void _wapi_handle_ops_signal (gpointer handle);
45 extern void _wapi_handle_ops_own (gpointer handle);
46 extern gboolean _wapi_handle_ops_isowned (gpointer handle);
48 extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles,
53 extern void _wapi_handle_unlock_handles (guint32 numhandles,
55 extern int _wapi_handle_wait_signal (void);
56 extern int _wapi_handle_timedwait_signal (struct timespec *timeout);
57 extern int _wapi_handle_wait_signal_handle (gpointer handle);
58 extern int _wapi_handle_timedwait_signal_handle (gpointer handle,
59 struct timespec *timeout);
61 static inline WapiHandleType _wapi_handle_type (gpointer handle)
63 guint32 idx=GPOINTER_TO_UINT (handle);
65 return(_wapi_shared_data->handles[idx].type);
68 static inline void _wapi_handle_set_signal_state (gpointer handle,
72 guint32 idx=GPOINTER_TO_UINT (handle);
75 /* Tell everyone blocking on a single handle */
77 /* This function _must_ be called with
78 * handle->signal_mutex locked
80 _wapi_shared_data->handles[idx].signalled=state;
83 pthread_cond_broadcast (&_wapi_shared_data->handles[idx].signal_cond);
85 pthread_cond_signal (&_wapi_shared_data->handles[idx].signal_cond);
88 /* Tell everyone blocking on multiple handles that something
91 #ifdef _POSIX_THREAD_PROCESS_SHARED
92 mono_mutex_lock (&_wapi_shared_data->signal_mutex);
93 pthread_cond_broadcast (&_wapi_shared_data->signal_cond);
94 mono_mutex_unlock (&_wapi_shared_data->signal_mutex);
96 mono_mutex_lock (&_wapi_private_data->signal_mutex);
97 pthread_cond_broadcast (&_wapi_private_data->signal_cond);
98 mono_mutex_unlock (&_wapi_private_data->signal_mutex);
99 #endif /* _POSIX_THREAD_PROCESS_SHARED */
101 _wapi_shared_data->handles[idx].signalled=state;
105 static inline gboolean _wapi_handle_issignalled (gpointer handle)
107 guint32 idx=GPOINTER_TO_UINT (handle);
109 return(_wapi_shared_data->handles[idx].signalled);
112 static inline int _wapi_handle_lock_signal_mutex (void)
114 #ifdef _POSIX_THREAD_PROCESS_SHARED
115 return(mono_mutex_lock (&_wapi_shared_data->signal_mutex));
117 return(mono_mutex_lock (&_wapi_private_data->signal_mutex));
118 #endif /* _POSIX_THREAD_PROCESS_SHARED */
121 static inline int _wapi_handle_unlock_signal_mutex (void)
123 #ifdef _POSIX_THREAD_PROCESS_SHARED
124 return(mono_mutex_unlock (&_wapi_shared_data->signal_mutex));
126 return(mono_mutex_unlock (&_wapi_private_data->signal_mutex));
127 #endif /* _POSIX_THREAD_PROCESS_SHARED */
130 static inline int _wapi_handle_lock_handle (gpointer handle)
132 guint32 idx=GPOINTER_TO_UINT (handle);
134 return(mono_mutex_lock (&_wapi_shared_data->handles[idx].signal_mutex));
137 static inline int _wapi_handle_unlock_handle (gpointer handle)
139 guint32 idx=GPOINTER_TO_UINT (handle);
141 return(mono_mutex_unlock (&_wapi_shared_data->handles[idx].signal_mutex));
144 #endif /* _WAPI_HANDLES_PRIVATE_H_ */