use core::marker::PhantomData;
pub struct UserSync<'a> {
pub(super) handle: nvtx_sys::SyncUserHandle,
pub(super) _lifetime: PhantomData<&'a ()>,
}
impl<'a> UserSync<'a> {
#[must_use = "Dropping the return will violate the state machine"]
pub fn acquire(self) -> UserSyncAcquireStart<'a> {
nvtx_sys::domain_syncuser_acquire_start(self.handle);
UserSyncAcquireStart { sync_object: self }
}
}
impl Drop for UserSync<'_> {
fn drop(&mut self) {
nvtx_sys::domain_syncuser_destroy(self.handle);
}
}
pub struct UserSyncAcquireStart<'a> {
sync_object: UserSync<'a>,
}
impl<'a> UserSyncAcquireStart<'a> {
#[must_use = "Dropping the return will result in the Synchronization Object being destroyed"]
pub fn failed(self) -> UserSync<'a> {
nvtx_sys::domain_syncuser_acquire_failed(self.sync_object.handle);
self.sync_object
}
#[must_use = "Dropping the return will violate the state machine"]
pub fn success(self) -> UserSyncSuccess<'a> {
nvtx_sys::domain_syncuser_acquire_success(self.sync_object.handle);
UserSyncSuccess {
sync_object: self.sync_object,
}
}
}
pub struct UserSyncSuccess<'a> {
sync_object: UserSync<'a>,
}
impl<'a> UserSyncSuccess<'a> {
#[must_use = "Dropping the return will result in the Synchronization Object being destroyed"]
pub fn release(self) -> UserSync<'a> {
nvtx_sys::domain_syncuser_acquire_releasing(self.sync_object.handle);
self.sync_object
}
}