2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/io/remlock.c
5 * PURPOSE: Remove Lock Support
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Filip Navara (navaraf@reactos.org)
10 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS *****************************************************************/
23 IoInitializeRemoveLockEx(IN PIO_REMOVE_LOCK RemoveLock
,
25 IN ULONG MaxLockedMinutes
,
26 IN ULONG HighWatermark
,
29 PEXTENDED_IO_REMOVE_LOCK Lock
= (PEXTENDED_IO_REMOVE_LOCK
)RemoveLock
;
32 /* Check if this is a debug lock */
33 if (RemlockSize
== sizeof(IO_REMOVE_LOCK_DBG_BLOCK
))
36 RtlZeroMemory(Lock
, RemlockSize
);
38 /* Setup debug parameters */
39 Lock
->Dbg
.HighWatermark
= HighWatermark
;
40 Lock
->Dbg
.MaxLockedTicks
= MaxLockedMinutes
* 600000000;
41 Lock
->Dbg
.AllocateTag
= AllocateTag
;
42 KeInitializeSpinLock(&Lock
->Dbg
.Spin
);
46 /* Otherwise, setup a free block */
47 Lock
->Common
.Removed
= FALSE
;
48 Lock
->Common
.IoCount
= 1;
49 KeInitializeEvent(&Lock
->Common
.RemoveEvent
,
60 IoAcquireRemoveLockEx(IN PIO_REMOVE_LOCK RemoveLock
,
61 IN OPTIONAL PVOID Tag
,
66 PEXTENDED_IO_REMOVE_LOCK Lock
= (PEXTENDED_IO_REMOVE_LOCK
)RemoveLock
;
68 /* Increase the lock count */
69 InterlockedIncrement(&Lock
->Common
.IoCount
);
70 if (!Lock
->Common
.Removed
)
72 /* Check what kind of lock this is */
73 if (RemlockSize
== sizeof(IO_REMOVE_LOCK_DBG_BLOCK
))
75 /* FIXME: Not yet supported */
76 DPRINT1("UNIMPLEMENTED\n");
82 /* Otherwise, decrement the count and check if it's gone */
83 if (!InterlockedDecrement(&Lock
->Common
.IoCount
))
85 /* Signal the event */
86 KeSetEvent(&Lock
->Common
.RemoveEvent
, IO_NO_INCREMENT
, FALSE
);
89 /* Return pending delete */
90 return STATUS_DELETE_PENDING
;
93 /* Otherwise, return success */
94 return STATUS_SUCCESS
;
102 IoReleaseRemoveLockEx(IN PIO_REMOVE_LOCK RemoveLock
,
104 IN ULONG RemlockSize
)
106 PEXTENDED_IO_REMOVE_LOCK Lock
= (PEXTENDED_IO_REMOVE_LOCK
)RemoveLock
;
108 /* Check what kind of lock this is */
109 if (RemlockSize
== sizeof(IO_REMOVE_LOCK_DBG_BLOCK
))
111 /* FIXME: Not yet supported */
112 DPRINT1("UNIMPLEMENTED\n");
116 /* Decrement the lock count */
117 if (!InterlockedDecrement(&Lock
->Common
.IoCount
))
119 /* Signal the event */
120 KeSetEvent(&Lock
->Common
.RemoveEvent
, IO_NO_INCREMENT
, FALSE
);
129 IoReleaseRemoveLockAndWaitEx(IN PIO_REMOVE_LOCK RemoveLock
,
131 IN ULONG RemlockSize
)
133 PEXTENDED_IO_REMOVE_LOCK Lock
= (PEXTENDED_IO_REMOVE_LOCK
)RemoveLock
;
136 /* Remove the lock and decrement the count */
137 Lock
->Common
.Removed
= TRUE
;
138 if (InterlockedDecrement(&Lock
->Common
.IoCount
) > 0)
141 KeWaitForSingleObject(&Lock
->Common
.RemoveEvent
,
148 /* Check what kind of lock this is */
149 if (RemlockSize
== sizeof(IO_REMOVE_LOCK_DBG_BLOCK
))
151 /* FIXME: Not yet supported */
152 DPRINT1("UNIMPLEMENTED\n");