Skip to content

Commit ed8a5a8

Browse files
committed
Made NamedMutex !Send
1 parent 6860367 commit ed8a5a8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

crates/cargo-wdk/src/actions/build/package_task.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,14 @@ impl<'a> PackageTask<'a> {
556556
/// An RAII wrapper over a Win API named mutex
557557
struct NamedMutex {
558558
handle: HANDLE,
559+
// `ReleaseMutex` requires that it is called
560+
// only by threads that own the mutex handle.
561+
// Being `!Send` ensures that's always the case.
562+
_not_send: std::marker::PhantomData<*const ()>,
559563
}
560564

561565
impl NamedMutex {
562-
/// Acquire named mutex
566+
/// Acquires named mutex
563567
pub fn acquire(name: &CStr) -> Result<Self, WinError> {
564568
fn get_last_error() -> WinError {
565569
// SAFETY: We have to just assume this function is safe to call
@@ -593,7 +597,7 @@ impl Drop for NamedMutex {
593597
// because this type itself created it and it
594598
// was never exposed outside
595599
unsafe {
596-
// This Cannot fail as the calling thread is guaranteed
600+
// This cannot fail as the calling thread is guaranteed
597601
// to own the handle since we do not implement Send
598602
let _ = ReleaseMutex(self.handle);
599603

crates/cargo-wdk/tests/test_utils/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ where
191191
/// An RAII wrapper over a Win API named mutex
192192
pub struct NamedMutex {
193193
handle: HANDLE,
194+
// `ReleaseMutex` requires that it is called
195+
// only by threads that own the mutex handle.
196+
// Being `!Send` ensures that's always the case.
197+
_not_send: std::marker::PhantomData<*const ()>,
194198
}
195199

196200
impl NamedMutex {
197-
/// Acquire named mutex
201+
/// Acquires named mutex
198202
pub fn acquire(name: &CStr) -> Result<Self, WinError> {
199203
fn get_last_error() -> WinError {
200204
// SAFETY: We have to just assume this function is safe to call
@@ -228,7 +232,7 @@ impl Drop for NamedMutex {
228232
// because this type itself created it and it
229233
// was never exposed outside
230234
unsafe {
231-
// This Cannot fail as the calling thread is guaranteed
235+
// This cannot fail as the calling thread is guaranteed
232236
// to own the handle since we do not implement Send
233237
let _ = ReleaseMutex(self.handle);
234238

0 commit comments

Comments
 (0)