5901544cdc8d3da361f30299c5761c9030cbfc72
[mono.git] / mono / io-layer / handles.c
1 #include <config.h>
2 #include <glib.h>
3
4 #include "mono/io-layer/wapi.h"
5 #include "wapi-private.h"
6 #include "handles-private.h"
7
8 guint32 _wapi_handle_count_signalled(GPtrArray *handles)
9 {
10         guint32 i, ret=0;
11         
12         /* Count how many of the interesting thread handles are signalled */
13         for(i=0; i<handles->len; i++) {
14                 WapiHandle *handle;
15
16                 handle=(WapiHandle *)g_ptr_array_index(handles, i);
17 #ifdef DEBUG
18                 g_message(G_GNUC_PRETTY_FUNCTION ": Checking handle %p",
19                           handle);
20 #endif
21                 
22                 if(handle->signalled==TRUE) {
23 #ifdef DEBUG
24                         g_message(G_GNUC_PRETTY_FUNCTION
25                                   ": Thread %p signalled", handle);
26 #endif
27                         ret++;
28                 }
29         }
30
31 #ifdef DEBUG
32         g_message(G_GNUC_PRETTY_FUNCTION ": %d signalled handles", ret);
33 #endif
34
35         return(ret);
36 }
37
38 /**
39  * CloseHandle:
40  * @handle: The handle to release
41  *
42  * Closes and invalidates @handle, releasing any resources it
43  * consumes.  When the last handle to a temporary or non-persistent
44  * object is closed, that object can be deleted.  Closing the same
45  * handle twice is an error.
46  *
47  * Return value: %TRUE on success, %FALSE otherwise.
48  */
49 gboolean CloseHandle(WapiHandle *handle)
50 {
51         g_return_val_if_fail(handle->ref>0, FALSE);
52         
53         handle->ref--;
54         if(handle->ref==0) {
55                 if(handle->ops->close!=NULL) {
56                         handle->ops->close(handle);
57                 }
58                 
59                 g_free(handle);         /* maybe this should be in
60                                          * ops, cuurently ops->close()
61                                          * is being used to free
62                                          * handle data
63                                          */
64         }
65         
66         return(TRUE);
67 }