I understand that you are trying to build the same posix semantics for
your spinlocks.
You can try the following (AT YOUR RISK!!) with a caveat that you cannot
use MYSPINLOCK_SLEEP at dispatch level.
Declare your spinlock struct as
typedef struct {
KSPIN_LOCK SpinLock; /* spin lock */
KSEMAPHORE Sem; /* semaphore object */
ULONG nsleepers; /* # of threads sleeping
*/
ULONG nwakeups; /* # of wakeups */
} my_spinlock_t;
MYSPINLOCK_LOCK simply aquires the SpinLock and MYSPINLOCK_UNLOCK
releases the SpinLock
MYSPINLOCK_SLEEP(lock) macro /* assumes that lock is already aquired */
do {
KIRQL zopri;
++(lock)->nsleepers; \
zopri = PASSIVE_LEVEL; \
MYSPINLOCK_UNLOCK(lock, zopri); \
KeWaitForSingleObject(&(lock)->Sem, \
Executive, KernelMode, FALSE, NULL);\
MYSPINLOCK_LOCK(lock, zopri); \
–(lock)->nsleepers; \
–(lock)->nwakeups; \
} while (0)
MYSPINLOCK_WAKEUP(lock) macro to wakeup all those sleeping
do {
if ((lock)->nsleepers > (lock)->nwakeups) { \
KeReleaseSemaphore(&(lock)->Sem, \
IO_NO_INCREMENT, \
(lock)->nsleepers - \
(lock)->nwakeups, FALSE); \
(lock)->nwakeups = (lock)->nsleepers; \
} \
} while (0)
MYSPINLOCK_WAKEUP_ONE would be a variant in which you would release only
1 Semaphore resource.
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-268957-
xxxxx@lists.osr.com] On Behalf Of xxxxx@bitdefender.com
Sent: Monday, November 06, 2006 12:47 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] spinlock & event question
Hi all,
Is it possible to both release a spinlock and wait for a notification
event, atomically, as a single operation?
Does the kernel offer such support, and if yes, with which routine?
thank you very much,
Sandor LUKACS
Virus Analyst, SOFTWIN
ps. it might be a very simple question, but I’m looking for
such a function for over a hour and just doesn’t see it 
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer