ReXGlue SDK
Loading...
Searching...
No Matches
rex::kernel::MutantObject Struct Reference

Public Member Functions

 MutantObject (bool initial_owner, u32 guest_mutant_in=0)
X_STATUS Release (bool abandon, i32 *previous_state=nullptr)
bool OnAcquired (const rex::platform::WaitHandle *waited)
void Adopt (MutantObject &fresh)

Public Attributes

PublishedPtr< rex::platform::Mutant > mutant
std::atomic< u32 > owner_thread_id {0}
std::atomic< i32 > hold_count {0}
std::atomic< bool > abandoned {false}
u32 guest_mutant = 0
std::mutex state_mutex

Constructor & Destructor Documentation

◆ MutantObject()

rex::kernel::MutantObject::MutantObject ( bool initial_owner,
u32 guest_mutant_in = 0 )
explicit
Parameters
initial_ownerTrue when the creating thread owns the mutant at once.
guest_mutant_inThe guest KMUTANT the object backs, 0 for none.

Member Function Documentation

◆ Adopt()

void rex::kernel::MutantObject::Adopt ( MutantObject & fresh)

Replaces the host mutant and the owner state with those of a new object.

Parameters
freshA mutant no other thread can see, whose host mutant is taken.

◆ OnAcquired()

bool rex::kernel::MutantObject::OnAcquired ( const rex::platform::WaitHandle * waited)

Sets the current thread as the owner after a successful wait.

Parameters
waitedThe host mutant the wait returned on. A replaced mutant leaves the owner as it is.
Returns
True when the mutant was abandoned since its last acquire.

◆ Release()

X_STATUS rex::kernel::MutantObject::Release ( bool abandon,
i32 * previous_state = nullptr )

Releases a mutant held by the current thread.

Parameters
abandonTrue to release every hold and mark the mutant abandoned.
previous_stateReceives the signal state before the release, may be null.
Returns
X_STATUS_SUCCESS, or X_STATUS_MUTANT_NOT_OWNED when the caller does not own it.

Member Data Documentation

◆ abandoned

std::atomic<bool> rex::kernel::MutantObject::abandoned {false}

Set by an abandon, cleared by the next acquire.

◆ guest_mutant

u32 rex::kernel::MutantObject::guest_mutant = 0

The guest KMUTANT the object backs, 0 for none.

◆ hold_count

std::atomic<i32> rex::kernel::MutantObject::hold_count {0}

Number of recursive acquires by the owner, 0 when unowned.

◆ mutant

PublishedPtr<rex::platform::Mutant> rex::kernel::MutantObject::mutant

Host mutant that waiters block on.

◆ owner_thread_id

std::atomic<u32> rex::kernel::MutantObject::owner_thread_id {0}

ID of the owning thread, 0 when no thread owns the mutant.

◆ state_mutex

std::mutex rex::kernel::MutantObject::state_mutex

Orders Release, OnAcquired and Adopt, so a replaced host mutant never changes the owner.


The documentation for this struct was generated from the following file: