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 gconstpointer _wapi_handle_scratch_lookup (guint32 idx);
40 extern guchar *_wapi_handle_scratch_lookup_as_string (guint32 idx);
41 extern void _wapi_handle_scratch_delete_internal (guint32 idx);
42 extern void _wapi_handle_scratch_delete (guint32 idx);
43 extern void _wapi_handle_register_capabilities (WapiHandleType type,
44 WapiHandleCapability caps);
45 extern gboolean _wapi_handle_test_capabilities (gpointer handle,
46 WapiHandleCapability caps);
47 extern void _wapi_handle_ops_close_shared (gpointer handle);
48 extern void _wapi_handle_ops_close_private (gpointer handle);
49 extern void _wapi_handle_ops_signal (gpointer handle);
50 extern void _wapi_handle_ops_own (gpointer handle);
51 extern gboolean _wapi_handle_ops_isowned (gpointer handle);
53 extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles,
58 extern void _wapi_handle_unlock_handles (guint32 numhandles,
60 extern int _wapi_handle_wait_signal (void);
61 extern int _wapi_handle_timedwait_signal (struct timespec *timeout);
62 extern int _wapi_handle_wait_signal_handle (gpointer handle);
63 extern int _wapi_handle_timedwait_signal_handle (gpointer handle,
64 struct timespec *timeout);
65 extern gboolean _wapi_handle_process_fork (guint32 cmd, guint32 args,
66 guint32 env, guint32 dir,
67 gboolean inherit, guint32 flags,
68 gpointer stdin_handle,
69 gpointer stdout_handle,
70 gpointer stderr_handle,
71 gpointer *process_handle,
72 gpointer *thread_handle,
73 guint32 *pid, guint32 *tid);
75 static inline WapiHandleType _wapi_handle_type (gpointer handle)
77 guint32 idx=GPOINTER_TO_UINT (handle);
79 return(_wapi_shared_data->handles[idx].type);
82 static inline void _wapi_handle_set_signal_state (gpointer handle,
86 guint32 idx=GPOINTER_TO_UINT (handle);
89 g_message (G_GNUC_PRETTY_FUNCTION ": setting state of %p to %s (broadcast %s)", handle, state?"TRUE":"FALSE", broadcast?"TRUE":"FALSE");
93 /* Tell everyone blocking on a single handle */
95 /* This function _must_ be called with
96 * handle->signal_mutex locked
98 _wapi_shared_data->handles[idx].signalled=state;
100 if(broadcast==TRUE) {
101 pthread_cond_broadcast (&_wapi_shared_data->handles[idx].signal_cond);
103 pthread_cond_signal (&_wapi_shared_data->handles[idx].signal_cond);
106 /* Tell everyone blocking on multiple handles that something
109 #ifdef _POSIX_THREAD_PROCESS_SHARED
110 mono_mutex_lock (&_wapi_shared_data->signal_mutex);
111 pthread_cond_broadcast (&_wapi_shared_data->signal_cond);
112 mono_mutex_unlock (&_wapi_shared_data->signal_mutex);
115 g_message (G_GNUC_PRETTY_FUNCTION ": lock global signal mutex");
118 mono_mutex_lock (&_wapi_private_data->signal_mutex);
119 pthread_cond_broadcast (&_wapi_private_data->signal_cond);
122 g_message (G_GNUC_PRETTY_FUNCTION ": unlock global signal mutex");
125 mono_mutex_unlock (&_wapi_private_data->signal_mutex);
126 #endif /* _POSIX_THREAD_PROCESS_SHARED */
128 _wapi_shared_data->handles[idx].signalled=state;
132 static inline gboolean _wapi_handle_issignalled (gpointer handle)
134 guint32 idx=GPOINTER_TO_UINT (handle);
136 return(_wapi_shared_data->handles[idx].signalled);
139 static inline int _wapi_handle_lock_signal_mutex (void)
142 g_message (G_GNUC_PRETTY_FUNCTION ": lock global signal mutex");
144 #ifdef _POSIX_THREAD_PROCESS_SHARED
145 return(mono_mutex_lock (&_wapi_shared_data->signal_mutex));
147 return(mono_mutex_lock (&_wapi_private_data->signal_mutex));
148 #endif /* _POSIX_THREAD_PROCESS_SHARED */
151 static inline int _wapi_handle_unlock_signal_mutex (void)
154 g_message (G_GNUC_PRETTY_FUNCTION ": unlock global signal mutex");
156 #ifdef _POSIX_THREAD_PROCESS_SHARED
157 return(mono_mutex_unlock (&_wapi_shared_data->signal_mutex));
159 return(mono_mutex_unlock (&_wapi_private_data->signal_mutex));
160 #endif /* _POSIX_THREAD_PROCESS_SHARED */
163 static inline int _wapi_handle_lock_handle (gpointer handle)
165 guint32 idx=GPOINTER_TO_UINT (handle);
168 g_message (G_GNUC_PRETTY_FUNCTION ": locking handle %p", handle);
171 return(mono_mutex_lock (&_wapi_shared_data->handles[idx].signal_mutex));
174 static inline int _wapi_handle_unlock_handle (gpointer handle)
176 guint32 idx=GPOINTER_TO_UINT (handle);
179 g_message (G_GNUC_PRETTY_FUNCTION ": unlocking handle %p", handle);
182 return(mono_mutex_unlock (&_wapi_shared_data->handles[idx].signal_mutex));
185 #endif /* _WAPI_HANDLES_PRIVATE_H_ */