[TCPIP, IP]
[reactos.git] / drivers / network / tcpip / include / titypes.h
index 78584fb..5a921e4 100644 (file)
@@ -7,79 +7,63 @@
 #ifndef __TITYPES_H
 #define __TITYPES_H
 
-
-#if DBG
-
-#define DEBUG_REFCHECK(Object) {        \
-   if ((Object)->RefCount <= 0) {       \
-      TI_DbgPrint(MIN_TRACE, ("Object at (0x%X) has invalid reference count (%d).\n", \
-        (Object), (Object)->RefCount)); \
-    }                                   \
-}
-
 /*
  * VOID ReferenceObject(
  *     PVOID Object)
  */
-#define ReferenceObject(Object)      \
-{                                    \
-  CHAR c1, c2, c3, c4;               \
-                                     \
-  c1 = ((Object)->Tag >> 24) & 0xFF; \
-  c2 = ((Object)->Tag >> 16) & 0xFF; \
-  c3 = ((Object)->Tag >> 8) & 0xFF;  \
-  c4 = ((Object)->Tag & 0xFF);       \
-                                     \
-  DEBUG_REFCHECK(Object);            \
-  TI_DbgPrint(DEBUG_REFCOUNT, ("Referencing object of type (%c%c%c%c) at (0x%X). RefCount (%d).\n", \
-    c4, c3, c2, c1, (Object), (Object)->RefCount)); \
-                                                    \
-  InterlockedIncrement(&((Object)->RefCount));      \
+#define ReferenceObject(Object)                            \
+{                                                          \
+    InterlockedIncrement(&((Object)->RefCount));           \
 }
 
-  /*
+/*
  * VOID DereferenceObject(
  *     PVOID Object)
  */
-#define DereferenceObject(Object)    \
-{                                    \
-  CHAR c1, c2, c3, c4;               \
-                                     \
-  c1 = ((Object)->Tag >> 24) & 0xFF; \
-  c2 = ((Object)->Tag >> 16) & 0xFF; \
-  c3 = ((Object)->Tag >> 8) & 0xFF;  \
-  c4 = ((Object)->Tag & 0xFF);       \
-                                     \
-  DEBUG_REFCHECK(Object);            \
-  TI_DbgPrint(DEBUG_REFCOUNT, ("Dereferencing object of type (%c%c%c%c) at (0x%X). RefCount (%d).\n", \
-    c4, c3, c2, c1, (Object), (Object)->RefCount));     \
-                                                        \
-  if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
-    (((Object)->Free)(Object));                         \
+#define DereferenceObject(Object)                           \
+{                                                           \
+    if (InterlockedDecrement(&((Object)->RefCount)) == 0)   \
+        (((Object)->Free)(Object));                         \
 }
 
-#else /* DBG */
+/*
+ * VOID LockObject(PVOID Object, PKIRQL OldIrql)
+ */
+#define LockObject(Object, Irql)                         \
+{                                                        \
+    ReferenceObject(Object);                             \
+    KeAcquireSpinLock(&((Object)->Lock), Irql);          \
+    memcpy(&(Object)->OldIrql, Irql, sizeof(KIRQL));     \
+}
 
 /*
- * VOID ReferenceObject(
- *     PVOID Object)
+ * VOID LockObjectAtDpcLevel(PVOID Object)
  */
-#define ReferenceObject(Object)                  \
-{                                                \
-    InterlockedIncrement(&((Object)->RefCount)); \
+#define LockObjectAtDpcLevel(Object)                     \
+{                                                        \
+    ReferenceObject(Object);                             \
+    KeAcquireSpinLockAtDpcLevel(&((Object)->Lock));      \
+    (Object)->OldIrql = DISPATCH_LEVEL;                  \
 }
 
 /*
- * VOID DereferenceObject(
- *     PVOID Object)
+ * VOID UnlockObject(PVOID Object, KIRQL OldIrql)
  */
-#define DereferenceObject(Object)                         \
-{                                                         \
-    if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
-        (((Object)->Free)(Object));                       \
+#define UnlockObject(Object, OldIrql)                       \
+{                                                           \
+    KeReleaseSpinLock(&((Object)->Lock), OldIrql);          \
+    DereferenceObject(Object);                              \
+}
+
+/*
+ * VOID UnlockObjectFromDpcLevel(PVOID Object)
+ */
+#define UnlockObjectFromDpcLevel(Object)                    \
+{                                                           \
+    KeReleaseSpinLockFromDpcLevel(&((Object)->Lock));       \
+    DereferenceObject(Object);                              \
 }
 
-#endif /* DBG */
 
 
 #include <ip.h>
@@ -143,8 +127,10 @@ typedef struct _DATAGRAM_SEND_REQUEST {
    field holds a pointer to this structure */
 typedef struct _ADDRESS_FILE {
     LIST_ENTRY ListEntry;                 /* Entry on list */
-    KSPIN_LOCK Lock;                      /* Spin lock to manipulate this structure */
+    LONG RefCount;                        /* Reference count */
     OBJECT_FREE_ROUTINE Free;             /* Routine to use to free resources for the object */
+    KSPIN_LOCK Lock;                      /* Spin lock to manipulate this structure */
+    KIRQL OldIrql;                        /* Currently not used */
     IP_ADDRESS Address;                   /* Address of this address file */
     USHORT Family;                        /* Address family */
     USHORT Protocol;                      /* Protocol number */
@@ -264,7 +250,10 @@ typedef struct _TDI_BUCKET {
    to this structure */
 typedef struct _CONNECTION_ENDPOINT {
     LIST_ENTRY ListEntry;       /* Entry on list */
+    LONG RefCount;              /* Reference count */
+    OBJECT_FREE_ROUTINE Free;   /* Routine to use to free resources for the object */
     KSPIN_LOCK Lock;            /* Spin lock to protect this structure */
+    KIRQL OldIrql;              /* The old irql is stored here for use in HandleSignalledConnection */
     PVOID ClientContext;        /* Pointer to client context information */
     PADDRESS_FILE AddressFile;  /* Associated address file object (NULL if none) */
     PVOID SocketContext;        /* Context for lower layer */
@@ -290,6 +279,8 @@ typedef struct _CONNECTION_ENDPOINT {
    field holds a pointer to this structure */
 typedef struct _CONTROL_CHANNEL {
     LIST_ENTRY ListEntry;       /* Entry on list */
+    LONG RefCount;              /* Reference count */
+    OBJECT_FREE_ROUTINE Free;   /* Routine to use to free resources for the object */
     KSPIN_LOCK Lock;            /* Spin lock to protect this structure */
 } CONTROL_CHANNEL, *PCONTROL_CHANNEL;