jvmti_rs/wrapper/jvmtifns/
raw_monitor.rs

1use std::ptr;
2
3use jni::strings::JNIString;
4
5use crate::{
6    errors::*,
7    JVMTIEnv,
8    objects::*,
9};
10use crate::sys::{jlong, jrawMonitorID};
11
12impl<'a> JVMTIEnv<'a> {
13    pub fn create_raw_monitor<N>(&self, name: N) -> Result<Option<JRawMonitorID>>
14        where
15            N: Into<JNIString>, {
16        let ffi_name = name.into();
17        let mut value_ptr: jrawMonitorID = ptr::null_mut();
18        let res = jvmti_call_result!(self.jvmti_raw(), CreateRawMonitor,
19            ffi_name.as_ptr(),
20            &mut value_ptr
21        );
22        jvmti_error_code_to_result(res)?;
23
24        if value_ptr.is_null() {
25            return Ok(None);
26        }
27        Ok(Some(value_ptr.into()))
28    }
29
30    pub fn destroy_raw_monitor(&self, monitor_id: &JRawMonitorID) -> Result<()> {
31        jvmti_call!(self.jvmti_raw(), DestroyRawMonitor,
32            monitor_id.into()
33        )
34    }
35
36    pub fn raw_monitor_enter(&self, monitor_id: &JRawMonitorID) -> Result<()> {
37        jvmti_call!(self.jvmti_raw(), RawMonitorEnter,
38            monitor_id.into()
39        )
40    }
41
42    pub fn raw_monitor_exit(&self, monitor_id: &JRawMonitorID) -> Result<()> {
43        jvmti_call!(self.jvmti_raw(), RawMonitorExit,
44            monitor_id.into()
45        )
46    }
47
48    pub fn raw_monitor_wait(&self, monitor_id: &JRawMonitorID, millis: jlong) -> Result<()> {
49        jvmti_call!(self.jvmti_raw(), RawMonitorWait,
50            monitor_id.into(),
51            millis
52        )
53    }
54
55    pub fn raw_monitor_notify(&self, monitor_id: &JRawMonitorID) -> Result<()> {
56        jvmti_call!(self.jvmti_raw(), RawMonitorNotify,
57            monitor_id.into()
58        )
59    }
60
61    pub fn raw_monitor_notify_all(&self, monitor_id: &JRawMonitorID) -> Result<()> {
62        jvmti_call!(self.jvmti_raw(), RawMonitorNotifyAll,
63            monitor_id.into()
64        )
65    }
66}