@@ -11,6 +11,7 @@ unsafe extern "Rust" {
1111
1212 fn esp_preempt_semaphore_take ( semaphore : SemaphorePtr , timeout_us : Option < u32 > ) -> bool ;
1313 fn esp_preempt_semaphore_give ( semaphore : SemaphorePtr ) -> bool ;
14+ fn esp_preempt_semaphore_current_count ( semaphore : SemaphorePtr ) -> u32 ;
1415
1516 fn esp_preempt_semaphore_try_take ( semaphore : SemaphorePtr ) -> bool ;
1617}
@@ -51,6 +52,13 @@ pub trait SemaphoreImplementation {
5152 /// `semaphore` must be a pointer returned from [`Self::create`].
5253 unsafe fn give ( semaphore : SemaphorePtr ) -> bool ;
5354
55+ /// Returns the semaphore's current counter value.
56+ ///
57+ /// # Safety
58+ ///
59+ /// `semaphore` must be a pointer returned from [`Self::create`].
60+ unsafe fn current_count ( semaphore : SemaphorePtr ) -> u32 ;
61+
5462 /// Attempts to decrement the semaphore's counter.
5563 ///
5664 /// If the counter is zero, this function must immediately return `false`.
@@ -93,6 +101,12 @@ macro_rules! register_semaphore_implementation {
93101 unsafe { <$t as $crate:: semaphore:: SemaphoreImplementation >:: give( semaphore) }
94102 }
95103
104+ #[ unsafe ( no_mangle) ]
105+ #[ inline]
106+ fn esp_preempt_semaphore_current_count( semaphore: $crate:: semaphore:: SemaphorePtr ) -> u32 {
107+ unsafe { <$t as $crate:: semaphore:: SemaphoreImplementation >:: current_count( semaphore) }
108+ }
109+
96110 #[ unsafe ( no_mangle) ]
97111 #[ inline]
98112 fn esp_preempt_semaphore_try_take( semaphore: $crate:: semaphore:: SemaphorePtr ) -> bool {
@@ -157,6 +171,11 @@ impl SemaphoreHandle {
157171 unsafe { esp_preempt_semaphore_give ( self . 0 ) }
158172 }
159173
174+ /// Returns the current counter value.
175+ pub fn current_count ( & self ) -> u32 {
176+ unsafe { esp_preempt_semaphore_current_count ( self . 0 ) }
177+ }
178+
160179 /// Attempts to decrement the semaphore's counter.
161180 ///
162181 /// If the counter is zero, this function returns `false`.
0 commit comments