Skip to content

Commit

Permalink
Make RuntimeContext not Send and not Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Ying authored and Boddlnagg committed Feb 9, 2019
1 parent 716084c commit 5bd1992
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/rt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::marker::PhantomData;
use std::ptr;

use super::{ComInterface, HString, HStringReference, HStringArg, ComPtr, ComArray, ComIid, Guid};
Expand Down Expand Up @@ -781,7 +782,7 @@ impl IMemoryBufferByteAccess {

/// Manages initialization and uninitialization of the Windows Runtime.
pub struct RuntimeContext {
token: () // only allow construction from inside this module
token: PhantomData<*mut ()> // only allow construction from inside this module, and make it !Send/!Sync.
}

impl RuntimeContext {
Expand All @@ -793,12 +794,9 @@ impl RuntimeContext {
pub fn init() -> RuntimeContext {
let hr = unsafe { RoInitialize(RO_INIT_MULTITHREADED) };
assert!(hr == S_OK || hr == S_FALSE, "failed to call RoInitialize: error {}", hr);
/*let mut f: ::w::UINT32 = 0;
assert!(RoGetErrorReportingFlags(&mut f) == S_OK);
println!("ErrorReportingFlags: {:?}", f);*/
RuntimeContext { token: () }
RuntimeContext { token: PhantomData }
}

/// Unitializes the Windows Runtime. This must not be called as long as any Windows Runtime
/// object is still alive.
#[inline]
Expand All @@ -812,4 +810,4 @@ impl Drop for RuntimeContext {
fn drop(&mut self) {
unsafe { RoUninitialize() };
}
}
}

0 comments on commit 5bd1992

Please sign in to comment.