Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results
The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.
Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/
Hi everyone.
I have a function where I add a data to the List_Entry. In my function I call a subfunction(IsDuplicate) to check the whole list so that the data is not duplicate.
I called the ExAcquireFastMutex function in the main function that adds the data. And then I called my subfunction, IsDuplicate.
Does FastMutex work well in subfunction or should we get a new FastMutex?
bool AddItem(List_Entry Entry){
ExAcquireFastMutex (mutex);
if(isnotduplicate(entry)){
inserttaillist(Listhead,Entry);
}
ExReleaseFastMutex(mutex)
}
bool isnotduplicate(List_entry Entry){
//Searches the entire list for the desired data
//if is not duplicate return true
}
Upcoming OSR Seminars | ||
---|---|---|
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead! | ||
Writing WDF Drivers | 7 Dec 2020 | LIVE ONLINE |
Internals & Software Drivers | 25 Jan 2021 | LIVE ONLINE |
Developing Minifilters | 8 March 2021 | LIVE ONLINE |
Comments
Did you read the documentation?
Your question implies that you do not understand the purpose of the fast mutex. A single mutex generally protects a single resource. It you have two routines access the resource, it does no good at all to hat two mutexes protecting it.
In your case, you just need to establish a policy that whoever calls isnotduplicate must hold the mutex before calling.
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
According to you, the above code example is correct because AddItem locked the Mutex before calling isnotduplicate.
Right?
As long as isnotduplicate does not ALSO grab the mutex, yes, this is fine.
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
excellent.
I ask to be sure.
Considering that we lock mutex in the main function(AddItem), then mutex is locked in the isnotduplicate and no problem occurs?
Is my data protected in isnotduplicate ? Is not isnotduplicate manipulated by two threads at the same time?
You have to make a rule. Anyone that calls isnotduplicate must hold the mutex. As long as you follow that rule, then no, it cannot be called by two threads at the same time. One of them will be blocked waiting for the mutex. That's the point of the mutex.
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
thank you so much