Hi,
I have one question regarding using spin lock.
I have 2 structures:
typedef struct {
ULONG subcount1;
ULONG subcount2;
KSPIN_LOCK SubLock;
} SubStructure, *PSubStructure;
typedef struct {
SubStructure MySubStruct[NumberOfElements];
ULONG count1;
ULONG count2
KSPIN_LOCK Lock;
} MyStructure, *PMyStructure;
Should I use 2 spin locks (Lock and Sublock) to protect shared data from modifications ot it’s enough to use only one Lock? MyStructure contains SubStructure here.
Thank you,
Andrew
It depends, do you ever pass a PSubStructure pointer to an element of
MySubStruct? If the SubStructure can ever be accessed without the
MyStructure you need something. The reason I say something, is you should
look at Interlocked operations if the SubStructure elements are truly
ULONG’s they may eliminate the locks for you. Or you can look at a way to
reorganize the code to have only the Lock in MyStructure and use if for
everything.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
“Andrey Kamchatnikov” wrote in message
news:xxxxx@ntdev…
Hi,
I have one question regarding using spin lock.
I have 2 structures:
typedef struct {
ULONG subcount1;
ULONG subcount2;
KSPIN_LOCK SubLock;
} SubStructure, *PSubStructure;
typedef struct {
SubStructure MySubStruct[NumberOfElements];
ULONG count1;
ULONG count2
KSPIN_LOCK Lock;
} MyStructure, *PMyStructure;
Should I use 2 spin locks (Lock and Sublock) to protect shared data from
modifications ot it’s enough to use only one Lock? MyStructure contains
SubStructure here.
Thank you,
Andrew
this is an open ended question.
If you can guarentee that your inner struct will never be used independently
then u dnt need the two locks. But it it is, then you need it.
amitr0
On 7/10/07, Andrey Kamchatnikov wrote:
>
> Hi,
>
> I have one question regarding using spin lock.
>
> I have 2 structures:
>
>
> typedef struct {
>
> *ULONG subcount1; *
>
> *ULONG subcount2; *
>
> *KSPIN_LOCK SubLock; *
>
> *} SubStructure, PSubStructure;
>
>
>
> typedef struct {
>
> *SubStructure MySubStruct[NumberOfElements]; *
>
> *ULONG count1; *
>
> *ULONG count2 *
>
> KSPIN_LOCK Lock;
>
> *} MyStructure, PMyStructure;
>
>
>
> *Should I use 2 spin locks (Lock and Sublock) to protect shared data from
> modifications ot it’s enough to use only one Lock? MyStructure contains
> SubStructure here. *
>
>
>
> Thank you,
>
> **
>
> Andrew
>
> —
> 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
>
–
- amitr0
>Should I use 2 spin locks (Lock and Sublock) to protect shared data from
modifications ot it’s enough to use only one Lock? MyStructure contains
SubStructure here.
Both ways are OK, this is a design choice. If you have significant amount of
routines which only access Substructure but not Structure - create 2 locks,
otherwise, create 1.
–
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com