-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update fmt::Debug to produce new info #86
Changes from 13 commits
71072fa
6ca2488
0bba9c8
9272ee4
e31a7a0
5075f46
9ed2090
82f1d8d
4a110cd
af4bbd4
9ef1d94
416524c
4a87b35
84c7a62
999f455
e9a8dae
5c8647a
ef10c5a
8094298
eb152c5
944a547
c5eb467
84b077e
7dfd50a
c50fbd4
7b352ce
a10783b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,14 +116,14 @@ struct Inner<T> { | |
/// The number of notified entries, or `usize::MAX` if all of them have been notified. | ||
/// | ||
/// If there are no entries, this value is set to `usize::MAX`. | ||
notified: AtomicUsize, | ||
pub notified: AtomicUsize, | ||
|
||
/// Inner queue of event listeners. | ||
/// | ||
/// On `std` platforms, this is an intrusive linked list. On `no_std` platforms, this is a | ||
/// more traditional `Vec` of listeners, with an atomic queue used as a backup for high | ||
/// contention. | ||
list: sys::List<T>, | ||
pub list: sys::List<T>, | ||
} | ||
|
||
impl<T> Inner<T> { | ||
|
@@ -171,7 +171,15 @@ impl<T> core::panic::RefUnwindSafe for Event<T> {} | |
|
||
impl<T> fmt::Debug for Event<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Event { .. }") | ||
let inner = self.inner(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of calling |
||
let notified_count = unsafe { (*inner).notified.load(Ordering::Relaxed) }; | ||
let total_count = unsafe { (*inner).list.total_listeners() }; | ||
|
||
write!( | ||
f, | ||
"Event {{\n Number of notified listeners: {:?}\n Total number of listeners: {:?}\n}}", | ||
notified_count, total_count | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To simplify, use |
||
} | ||
} | ||
|
||
|
@@ -202,7 +210,6 @@ impl<T> Event<T> { | |
inner: AtomicPtr::new(ptr::null_mut()), | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add back these lines to reduce diff noise? |
||
/// Tell whether any listeners are currently notified. | ||
/// | ||
/// # Examples | ||
|
@@ -456,7 +463,6 @@ impl Event<()> { | |
inner: AtomicPtr::new(ptr::null_mut()), | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
/// Notifies a number of active listeners without emitting a `SeqCst` fence. | ||
/// | ||
/// The number is allowed to be zero or exceed the current number of listeners. | ||
|
@@ -650,7 +656,15 @@ unsafe impl<T: Send> Sync for EventListener<T> {} | |
|
||
impl<T> fmt::Debug for EventListener<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("EventListener { .. }") | ||
let mut ds = f.debug_struct("EventListener"); | ||
|
||
if self.is_listening() { | ||
ds.field("Listening", &"Yes"); | ||
} else { | ||
ds.field("Listening", &"No"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
|
||
ds.finish() | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,14 @@ impl<T> List<T> { | |
queue: concurrent_queue::ConcurrentQueue::unbounded(), | ||
} | ||
} | ||
pub fn total_listeners(&self) -> usize { | ||
self.inner | ||
.try_lock() | ||
.as_ref() | ||
.map(|lock| &**lock) | ||
.map(|listener_slab| listener_slab.listeners.len()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
.unwrap_or(0) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This returns something different from the |
||
} | ||
|
||
/// The guard returned by [`Inner::lock`]. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,10 @@ impl<T> List<T> { | |
notified: 0, | ||
})) | ||
} | ||
// Accessor method because fields are private, not sure how to go around it | ||
pub fn total_listeners(&self) -> Result<usize, &str> { | ||
self.0.lock().map(|mutex| mutex.len).map_err(|_| "<locked>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do |
||
} | ||
} | ||
|
||
impl<T> crate::Inner<T> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fields don't need to be
pub
, I think.