2005-09-27 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / io-layer / wapi-private.h
index 05b48411160c38e56f28b869ab33e92e89ba1e47..5dc0e6360732ab36004c9347d9e0538c85203d74 100644 (file)
@@ -24,7 +24,7 @@
 /* Increment this whenever an incompatible change is made to the
  * shared handle structure.
  */
-#define _WAPI_HANDLE_VERSION 4
+#define _WAPI_HANDLE_VERSION 7
 
 typedef enum {
        WAPI_HANDLE_UNUSED=0,
@@ -44,8 +44,7 @@ typedef enum {
 
 extern const char *_wapi_handle_typename[];
 
-#define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_THREAD || \
-                                  type == WAPI_HANDLE_PROCESS || \
+#define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_PROCESS || \
                                   type == WAPI_HANDLE_NAMEDMUTEX)
 
 #define _WAPI_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
@@ -69,7 +68,7 @@ typedef enum {
 
 struct _WapiHandleOps 
 {
-       void (*close)(gpointer handle);
+       void (*close)(gpointer handle, gpointer data);
 
        /* SignalObjectAndWait */
        void (*signal)(gpointer signal);
@@ -86,10 +85,10 @@ struct _WapiHandleOps
         */
        gboolean (*is_owned)(gpointer handle);
 
-       /* Called by WaitForSingleObject, if the handle in question
-        * needs a special wait function instead of using the normal
-        * handle signal mechanism.  Returns the WaitForSingleObject
-        * return code.
+       /* Called by WaitForSingleObject and WaitForMultipleObjects,
+        * if the handle in question needs a special wait function
+        * instead of using the normal handle signal mechanism.
+        * Returns the WaitForSingleObject return code.
         */
        guint32 (*special_wait)(gpointer handle, guint32 timeout);
 };
@@ -130,6 +129,11 @@ struct _WapiHandleUnshared
                struct _WapiHandle_sem sem;
                struct _WapiHandle_socket sock;
                struct _WapiHandle_shared_ref shared;
+
+               /* Move thread data into the private set, while
+                * problems with cleaning up shared handles are fixed
+                */
+               struct _WapiHandle_thread thread;
        } u;
 };
 
@@ -138,7 +142,6 @@ struct _WapiHandleSharedMetadata
        volatile guint32 offset;
        guint32 timestamp;
        volatile gboolean signalled;
-       volatile guint32 checking;
 };
 
 struct _WapiHandleShared
@@ -148,19 +151,26 @@ struct _WapiHandleShared
        
        union
        {
+               /* Leave this one while the thread is in the private
+                * set, so the shared space doesn't change size
+                */
                struct _WapiHandle_thread thread;
                struct _WapiHandle_process process;
                struct _WapiHandle_namedmutex namedmutex;
        } u;
 };
 
+#define _WAPI_SHARED_SEM_NAMESPACE 0
+#define _WAPI_SHARED_SEM_COLLECTION 1
+#define _WAPI_SHARED_SEM_SHARE 2
+#define _WAPI_SHARED_SEM_HANDLE 3
+#define _WAPI_SHARED_SEM_COUNT 8       /* Leave some future expansion space */
+
 struct _WapiHandleSharedLayout
 {
-       guint32 namespace_check;
        volatile guint32 signal_count;
-
-       guint32 master_timestamp;
        volatile guint32 collection_count;
+       volatile key_t sem_key;
        
        struct _WapiHandleSharedMetadata metadata[_WAPI_HANDLE_INITIAL_COUNT];
        struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
@@ -172,6 +182,7 @@ struct _WapiFileShare
 {
        dev_t device;
        ino_t inode;
+       pid_t opened_by_pid;
        guint32 sharemode;
        guint32 access;
        guint32 handle_refs;
@@ -180,7 +191,6 @@ struct _WapiFileShare
 
 struct _WapiFileShareLayout
 {
-       guint32 share_check;
        guint32 hwm;
        
        struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];