1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use std::{fmt::Debug, sync::{atomic::{AtomicBool, AtomicUsize, Ordering}, Arc, Weak}};
//#[cfg(feature="count_waiting_senders_and_receivers")]
//use crate::ScopedIncrementer;
///
/// Details that are shared between sender and receiver parts of a channel.
///
pub struct SharedDetails<Q, N = ()>
{
queue: Q,
//sender_count: Weak<()>,
//receiver_count: Weak<()>,
//active_receiver_count: AtomicUsize,
receivers_notifier: N,
//#[cfg(feature="count_waiting_senders_and_receivers")]
//receivers_awiting_notification_count: AtomicUsize,
//receivers_do_not_wait: AtomicBool
}
impl<Q, N> SharedDetails<Q, N>
{
pub fn new(queue: Q, receivers_notifier: N) -> Self //, sender_count: &Arc<()>, receiver_count: &Arc<()>) -> Self
{
Self
{
queue,
//sender_count: Arc::downgrade(sender_count),
//receiver_count: Arc::downgrade(receiver_count),
//active_receiver_count: AtomicUsize::new(0),
receivers_notifier,
//#[cfg(feature="count_waiting_senders_and_receivers")]
//receivers_awiting_notification_count: AtomicUsize::new(0),
//receivers_do_not_wait: AtomicBool::new(false)
}
}
pub fn queue_ref(&self) -> &Q
{
&self.queue
}
//active_receiver_count
/*
pub fn inc_active_receiver_count(&self) -> usize
{
self.active_receiver_count.fetch_add(1, Ordering::SeqCst)
}
pub fn dec_active_receiver_count(&self) -> usize
{
self.active_receiver_count.fetch_sub(1, Ordering::SeqCst)
}
pub fn current_active_receiver_count(&self) -> usize
{
self.active_receiver_count.load(Ordering::Acquire)
}
*/
//
pub fn receivers_notifier_ref(&self) -> &N
{
&self.receivers_notifier
}
/*
pub fn receivers_do_not_wait(&self) -> bool
{
self.receivers_do_not_wait.load(Ordering::Acquire)
}
pub fn receivers_do_not_wait_t(&self)
{
self.receivers_do_not_wait.store(true, Ordering::Release);
}
#[cfg(feature="count_waiting_senders_and_receivers")]
pub fn temp_inc_receivers_awaiting_notification_count<'a>(&'a self) -> ScopedIncrementer<'a>
{
ScopedIncrementer::new(&self.receivers_awiting_notification_count)
}
*/
}
impl<Q, N> Debug for SharedDetails<Q, N>
where Q: Debug,
N: Debug
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SharedDetails").field("queue", &self.queue).field("receivers_notifier", &self.receivers_notifier).finish()
}
}