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/wapi-private.h>
17 #include <mono/io-layer/shared.h>
21 /* Shared threads dont seem to work yet */
22 #undef _POSIX_THREAD_PROCESS_SHARED
24 extern struct _WapiHandleShared_list *_wapi_shared_data;
25 extern struct _WapiHandlePrivate_list *_wapi_private_data;
27 extern guint32 _wapi_handle_new_internal (WapiHandleType type);
28 extern gpointer _wapi_handle_new (WapiHandleType type);
29 extern gboolean _wapi_lookup_handle (gpointer handle, WapiHandleType type,
30 gpointer *shared, gpointer *private);
31 extern gpointer _wapi_search_handle (WapiHandleType type,
32 gboolean (*check)(gpointer, gpointer),
34 gpointer *shared, gpointer *private);
35 extern void _wapi_handle_ref (gpointer handle);
36 extern void _wapi_handle_unref (gpointer handle);
37 extern guint32 _wapi_handle_scratch_store_internal (guint32 bytes);
38 extern guint32 _wapi_handle_scratch_store (gconstpointer data, guint32 bytes);
39 extern guint32 _wapi_handle_scratch_store_string_array (gchar **data);
40 extern gconstpointer _wapi_handle_scratch_lookup (guint32 idx);
41 extern guchar *_wapi_handle_scratch_lookup_as_string (guint32 idx);
42 extern gchar **_wapi_handle_scratch_lookup_string_array (guint32 idx);
43 extern void _wapi_handle_scratch_delete_internal (guint32 idx);
44 extern void _wapi_handle_scratch_delete (guint32 idx);
45 extern void _wapi_handle_scratch_delete_string_array (guint32 idx);
46 extern void _wapi_handle_register_capabilities (WapiHandleType type,
47 WapiHandleCapability caps);
48 extern gboolean _wapi_handle_test_capabilities (gpointer handle,
49 WapiHandleCapability caps);
50 extern void _wapi_handle_ops_close_shared (gpointer handle);
51 extern void _wapi_handle_ops_close_private (gpointer handle);
52 extern void _wapi_handle_ops_signal (gpointer handle);
53 extern void _wapi_handle_ops_own (gpointer handle);
54 extern gboolean _wapi_handle_ops_isowned (gpointer handle);
56 extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles,
61 extern void _wapi_handle_unlock_handles (guint32 numhandles,
63 extern int _wapi_handle_wait_signal (void);
64 extern int _wapi_handle_timedwait_signal (struct timespec *timeout);
65 extern int _wapi_handle_wait_signal_handle (gpointer handle);
66 extern int _wapi_handle_timedwait_signal_handle (gpointer handle,
67 struct timespec *timeout);
68 extern gboolean _wapi_handle_process_fork (guint32 cmd, guint32 env,
69 guint32 dir, gboolean inherit,
71 gpointer stdin_handle,
72 gpointer stdout_handle,
73 gpointer stderr_handle,
74 gpointer *process_handle,
75 gpointer *thread_handle,
76 guint32 *pid, guint32 *tid);
78 static inline WapiHandleType _wapi_handle_type (gpointer handle)
80 guint32 idx=GPOINTER_TO_UINT (handle);
82 return(_wapi_shared_data->handles[idx].type);
85 static inline void _wapi_handle_set_signal_state (gpointer handle,
89 guint32 idx=GPOINTER_TO_UINT (handle);
92 g_message (G_GNUC_PRETTY_FUNCTION ": setting state of %p to %s (broadcast %s)", handle, state?"TRUE":"FALSE", broadcast?"TRUE":"FALSE");
96 /* Tell everyone blocking on a single handle */
98 /* This function _must_ be called with
99 * handle->signal_mutex locked
101 _wapi_shared_data->handles[idx].signalled=state;
103 if(broadcast==TRUE) {
104 pthread_cond_broadcast (&_wapi_shared_data->handles[idx].signal_cond);
106 pthread_cond_signal (&_wapi_shared_data->handles[idx].signal_cond);
109 /* Tell everyone blocking on multiple handles that something
112 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
113 mono_mutex_lock (&_wapi_shared_data->signal_mutex);
114 pthread_cond_broadcast (&_wapi_shared_data->signal_cond);
115 mono_mutex_unlock (&_wapi_shared_data->signal_mutex);
118 g_message (G_GNUC_PRETTY_FUNCTION ": lock global signal mutex");
121 mono_mutex_lock (&_wapi_private_data->signal_mutex);
122 pthread_cond_broadcast (&_wapi_private_data->signal_cond);
125 g_message (G_GNUC_PRETTY_FUNCTION ": unlock global signal mutex");
128 mono_mutex_unlock (&_wapi_private_data->signal_mutex);
129 #endif /* _POSIX_THREAD_PROCESS_SHARED */
131 _wapi_shared_data->handles[idx].signalled=state;
135 static inline gboolean _wapi_handle_issignalled (gpointer handle)
137 guint32 idx=GPOINTER_TO_UINT (handle);
139 return(_wapi_shared_data->handles[idx].signalled);
142 static inline int _wapi_handle_lock_signal_mutex (void)
145 g_message (G_GNUC_PRETTY_FUNCTION ": lock global signal mutex");
147 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
148 return(mono_mutex_lock (&_wapi_shared_data->signal_mutex));
150 return(mono_mutex_lock (&_wapi_private_data->signal_mutex));
151 #endif /* _POSIX_THREAD_PROCESS_SHARED */
154 static inline int _wapi_handle_unlock_signal_mutex (void)
157 g_message (G_GNUC_PRETTY_FUNCTION ": unlock global signal mutex");
159 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
160 return(mono_mutex_unlock (&_wapi_shared_data->signal_mutex));
162 return(mono_mutex_unlock (&_wapi_private_data->signal_mutex));
163 #endif /* _POSIX_THREAD_PROCESS_SHARED */
166 static inline int _wapi_handle_lock_handle (gpointer handle)
168 guint32 idx=GPOINTER_TO_UINT (handle);
171 g_message (G_GNUC_PRETTY_FUNCTION ": locking handle %p", handle);
174 return(mono_mutex_lock (&_wapi_shared_data->handles[idx].signal_mutex));
177 static inline int _wapi_handle_unlock_handle (gpointer handle)
179 guint32 idx=GPOINTER_TO_UINT (handle);
182 g_message (G_GNUC_PRETTY_FUNCTION ": unlocking handle %p", handle);
185 return(mono_mutex_unlock (&_wapi_shared_data->handles[idx].signal_mutex));
188 #endif /* _WAPI_HANDLES_PRIVATE_H_ */