Put network includes in sockets.h
[mono.git] / mono / io-layer / handles-private.h
1 /*
2  * handles-private.h:  Internal operations on handles
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #ifndef _WAPI_HANDLES_PRIVATE_H_
11 #define _WAPI_HANDLES_PRIVATE_H_
12
13 #include <config.h>
14 #include <glib.h>
15
16 #include <mono/io-layer/wapi-private.h>
17 #include <mono/io-layer/shared.h>
18
19 #undef DEBUG
20
21 extern struct _WapiHandleShared_list *_wapi_shared_data;
22 extern struct _WapiHandlePrivate_list *_wapi_private_data;
23
24 extern void _wapi_handle_init (void);
25
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);
47
48 extern gboolean _wapi_handle_count_signalled_handles (guint32 numhandles,
49                                                       gpointer *handles,
50                                                       gboolean waitall,
51                                                       guint32 *retcount,
52                                                       guint32 *lowest);
53 extern void _wapi_handle_unlock_handles (guint32 numhandles,
54                                          gpointer *handles);
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);
60
61 static inline WapiHandleType _wapi_handle_type (gpointer handle)
62 {
63         guint32 idx=GPOINTER_TO_UINT (handle);
64         
65         return(_wapi_shared_data->handles[idx].type);
66 }
67
68 static inline void _wapi_handle_set_signal_state (gpointer handle,
69                                                   gboolean state,
70                                                   gboolean broadcast)
71 {
72         guint32 idx=GPOINTER_TO_UINT (handle);
73
74         if(state==TRUE) {
75                 /* Tell everyone blocking on a single handle */
76
77                 /* This function _must_ be called with
78                  * handle->signal_mutex locked
79                  */
80                 _wapi_shared_data->handles[idx].signalled=state;
81                 
82                 if(broadcast==TRUE) {
83                         pthread_cond_broadcast (&_wapi_shared_data->handles[idx].signal_cond);
84                 } else {
85                         pthread_cond_signal (&_wapi_shared_data->handles[idx].signal_cond);
86                 }
87
88                 /* Tell everyone blocking on multiple handles that something
89                  * was signalled
90                  */
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);
95 #else
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 */
100         } else {
101                 _wapi_shared_data->handles[idx].signalled=state;
102         }
103 }
104
105 static inline gboolean _wapi_handle_issignalled (gpointer handle)
106 {
107         guint32 idx=GPOINTER_TO_UINT (handle);
108
109         return(_wapi_shared_data->handles[idx].signalled);
110 }
111
112 static inline int _wapi_handle_lock_signal_mutex (void)
113 {
114 #ifdef _POSIX_THREAD_PROCESS_SHARED
115         return(mono_mutex_lock (&_wapi_shared_data->signal_mutex));
116 #else
117         return(mono_mutex_lock (&_wapi_private_data->signal_mutex));
118 #endif /* _POSIX_THREAD_PROCESS_SHARED */
119 }
120
121 static inline int _wapi_handle_unlock_signal_mutex (void)
122 {
123 #ifdef _POSIX_THREAD_PROCESS_SHARED
124         return(mono_mutex_unlock (&_wapi_shared_data->signal_mutex));
125 #else
126         return(mono_mutex_unlock (&_wapi_private_data->signal_mutex));
127 #endif /* _POSIX_THREAD_PROCESS_SHARED */
128 }
129
130 static inline int _wapi_handle_lock_handle (gpointer handle)
131 {
132         guint32 idx=GPOINTER_TO_UINT (handle);
133         
134         return(mono_mutex_lock (&_wapi_shared_data->handles[idx].signal_mutex));
135 }
136
137 static inline int _wapi_handle_unlock_handle (gpointer handle)
138 {
139         guint32 idx=GPOINTER_TO_UINT (handle);
140         
141         return(mono_mutex_unlock (&_wapi_shared_data->handles[idx].signal_mutex));
142 }
143
144 #endif /* _WAPI_HANDLES_PRIVATE_H_ */