Skip to content

Commit

Permalink
Make accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
sampettersson committed Apr 8, 2023
1 parent 9b9d703 commit 4e793ed
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions crates/epaint/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ mod mutex_impl {
}
}

#[inline(always)]
pub fn mutex_ptr() -> *const c_void
{
&mutex_impl::HELD_LOCKS_TLS as *const LocalKey<RefCell<mutex_impl::HeldLocks>> as *const c_void
}

#[inline(always)]
pub fn set_mutex_ptr(ptr: *const c_void)
{
unsafe { mutex_impl::HELD_LOCKS_TLS_POINTER = &*(ptr as *const LocalKey<RefCell<mutex_impl::HeldLocks>>) };
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(debug_assertions)]
mod mutex_impl {
Expand All @@ -44,7 +56,7 @@ mod mutex_impl {
pub struct MutexGuard<'a, T>(parking_lot::MutexGuard<'a, T>, *const ());

#[derive(Default)]
struct HeldLocks(Vec<*const ()>);
pub(crate) struct HeldLocks(Vec<*const ()>);

impl HeldLocks {
#[inline(always)]
Expand All @@ -64,22 +76,10 @@ mod mutex_impl {
}

thread_local! {
static HELD_LOCKS_TLS: std::cell::RefCell<HeldLocks> = Default::default();
pub(crate) static HELD_LOCKS_TLS: std::cell::RefCell<HeldLocks> = Default::default();
}

static mut HELD_LOCKS_TLS_POINTER : &LocalKey<RefCell<HeldLocks>> = &HELD_LOCKS_TLS;

#[inline(always)]
pub fn mutex_ptr() -> *const c_void
{
&HELD_LOCKS_TLS as *const LocalKey<RefCell<HeldLocks>> as *const c_void
}

#[inline(always)]
pub fn set_context_ptr(ptr: *const c_void)
{
unsafe { HELD_LOCKS_TLS_POINTER = &*(ptr as *const LocalKey<RefCell<HeldLocks>>) };
}
pub(crate) static mut HELD_LOCKS_TLS_POINTER : &LocalKey<RefCell<HeldLocks>> = &HELD_LOCKS_TLS;

impl<T> Mutex<T> {
#[inline(always)]
Expand Down Expand Up @@ -429,6 +429,9 @@ mod rw_lock_impl {

// ----------------------------------------------------------------------------

use std::cell::RefCell;
use std::ffi::c_void;
use std::thread::LocalKey;
pub use mutex_impl::{Mutex, MutexGuard};
pub use rw_lock_impl::{RwLock, RwLockReadGuard, RwLockWriteGuard};

Expand Down

0 comments on commit 4e793ed

Please sign in to comment.