Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions rust/ittapi/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::CString, marker::PhantomData};
use std::ffi::CString;

/// See the [Event API] documentation.
///
Expand Down Expand Up @@ -51,19 +51,18 @@ impl Event {
let result = unsafe { start_fn(self.0) };
assert!(result == 0, "unable to start event");
}
StartedEvent {
event: self.0,
phantom: PhantomData,
}
StartedEvent { event: self.0 }
}
}

pub struct StartedEvent<'a> {
/// Contains the information about a started event.
///
/// Allows for the drop implementation to end the event when it goes out of scope.
pub struct StartedEvent {
event: ittapi_sys::__itt_event,
phantom: PhantomData<&'a mut ()>,
}

impl StartedEvent<'_> {
impl StartedEvent {
/// End the event.
#[allow(clippy::unused_self)]
pub fn end(self) {
Expand All @@ -72,7 +71,7 @@ impl StartedEvent<'_> {
}
}

impl Drop for StartedEvent<'_> {
impl Drop for StartedEvent {
fn drop(&mut self) {
if let Some(end_fn) = unsafe { ittapi_sys::__itt_event_end_ptr__3_0 } {
let result = unsafe { end_fn(self.event) };
Expand All @@ -91,4 +90,13 @@ mod tests {
let _started_event = event.start();
// Dropping `started_event` ends the event.
}

#[test]
fn double_end() {
let event = Event::new("test");
let s1 = event.start();
let s2 = event.start();
s2.end();
s1.end();
}
}
2 changes: 1 addition & 1 deletion rust/ittapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod util;

pub use collection_control::{detach, pause, resume};
pub use domain::Domain;
pub use event::Event;
pub use event::{Event, StartedEvent};
pub use region::{MarkedRegion, Region};
pub use string::StringHandle;
pub use task::Task;
Loading