Re: Problem using queued spinlocks on single cpu comp uter

Daniel,

Aren’t you supposed to keep that KLOCK_QUEUE_HANDLE in your pocket, so that
you can pass it to your call to KeReleaseInStackQueueSpinlock ? I would make
a m_psLockQueue member variable in the CSpinLock class, and pass a pointer
to it to the routines. Try this,

class CSpinLock
{
private:
KLOCK_QUEUE_HANDLE *m_psLockQueue;
PKSPIN_LOCK m_oSpinLock;
CString *m_name;
public:
CSpinLock (name)
{
KeInitializeSpinLock(&m_oSpinLock);
m_psLockQueue = new KLOCK_QUEUE_HANDLE;
m_name = new CString(name);
}
~CSpinLock()
{
if (m_name) delete m_name;
if (m_psLockQueue) delete m_psLockQueue;
}
void Lock()
{
if (m_lockQueue) KeAcquireInStackQueuedSpinLock(&m_oSpinLock,
m_psLockQueue);
else Barf(Uninitialized);
}
void Unlock ()
{
if (m_lockQueue) KeReleaseInStackSpinLock (m_psLlockQueue);
else Barf(ReleasedTwice);
}
void Barf(int error)
{
TellHimOffMessageBox(“You dumb ass: spinlock %s is
%s”,m_name,GetErrorMessage(error));
}
};

Or something like it. Hope this helps, and caveat emptor ! Btw, I like the
Java way of laying out classes, much cleaner than spreading it over two
files.

Alberto.

-----Original Message-----
From: Daniel Simard [mailto:xxxxx@matrox.com]
Sent: Thursday, September 25, 2003 10:22 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Problem using queued spinlocks on single cpu
computer

I never use regular and queued spinlock at the same time (mixed together).
I use one type or the other for all my spinlocks. We are using spinlocks
into our drivers through an generic object for all our drivers, so I can
decide for all our drivers what type of spinlocks we use. I of course
initialize the spinlocks with KeInitializeSpinLock before calling the
acquire/release functions. I found the my spinlock object (in queued type
mode) works fine and fix my problem on multi-cpu computers, but slows down
the single cpu computers. All my drivers are always tested through
DriverVerifier with all checks enabled.

Here is my new code:

CSpinLock::CSpinLock()
{
KeInitializeSpinLock(&m_oSpinLock);
}

CSpinLock::Lock()
{
KLOCK_QUEUE_HANDLE* psLockQueue;

psLockQueue = new KLOCK_QUEUE_HANDLE;
KeAcquireInStackQueuedSpinLock(&m_oSpinLock, psLockQueue);
m_psLockQueue = psLockQueue;
}

CSpinLock::Unlock()
{
KLOCK_QUEUE_HANDLE* psLockQueue;

psLockQueue = m_psLockQueue;
m_psLockQueue = 0;
KeReleaseInStackQueuedSpinLock(psLockQueue);
delete psLockQueue;
}

Here is my old code:

CSpinLock::CSpinLock()
{
KeInitializeSpinLock(&m_oSpinLock);
}

CSpinLock::Lock()
{
KeAcquireSpinLock(&m_oSpinLock, &m_oOldIrql);
}

CSpinLock::Unlock()
{
KeReleaseSpinLock(&m_oSpinLock, m_oOldIrql);
}


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

That’s an interesting statement, Chuck, what advantages do you see in
separating these two ?

Alberto.

-----Original Message-----
From: Chuck Batson [mailto:xxxxx@cbatson.com]
Sent: Thursday, September 25, 2003 11:09 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Problem using queued spinlocks on single cpu computer

CSpinLock::CSpinLock()

By the way, a better design is to use two separate classes: one for the
spin lock object itself, and another for acquisition/release.

Chuck


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.