55
66#include < seastar/util/later.hh>
77
8+ SET_SUBSYS (osd);
9+ // TODO: SET_SUBSYS(crimson_tri_mutex);
10+
811seastar::future<> read_lock::lock ()
912{
1013 return static_cast <tri_mutex*>(this )->lock_for_read ();
@@ -57,20 +60,28 @@ void excl_lock_from_write::unlock()
5760
5861tri_mutex::~tri_mutex ()
5962{
63+ LOG_PREFIX (tri_mutex::~tri_mutex ());
64+ DEBUGDPP (" " , *this );
6065 assert (!is_acquired ());
6166}
6267
6368seastar::future<> tri_mutex::lock_for_read ()
6469{
70+ LOG_PREFIX (tri_mutex::lock_for_read ());
71+ DEBUGDPP (" " , *this );
6572 if (try_lock_for_read ()) {
73+ DEBUGDPP (" lock_for_read successfully" , *this );
6674 return seastar::now ();
6775 }
76+ DEBUGDPP (" can't lock_for_read, adding to waiters" , *this );
6877 waiters.emplace_back (seastar::promise<>(), type_t ::read);
6978 return waiters.back ().pr .get_future ();
7079}
7180
7281bool tri_mutex::try_lock_for_read () noexcept
7382{
83+ LOG_PREFIX (tri_mutex::try_lock_for_read ());
84+ DEBUGDPP (" " , *this );
7485 if (!writers && !exclusively_used && waiters.empty ()) {
7586 ++readers;
7687 return true ;
@@ -81,6 +92,8 @@ bool tri_mutex::try_lock_for_read() noexcept
8192
8293void tri_mutex::unlock_for_read ()
8394{
95+ LOG_PREFIX (tri_mutex::unlock_for_read ());
96+ DEBUGDPP (" " , *this );
8497 assert (readers > 0 );
8598 if (--readers == 0 ) {
8699 wake ();
@@ -89,29 +102,39 @@ void tri_mutex::unlock_for_read()
89102
90103void tri_mutex::promote_from_read ()
91104{
105+ LOG_PREFIX (tri_mutex::promote_from_read ());
106+ DEBUGDPP (" " , *this );
92107 assert (readers == 1 );
93108 --readers;
94109 exclusively_used = true ;
95110}
96111
97112void tri_mutex::demote_to_read ()
98113{
114+ LOG_PREFIX (tri_mutex::demote_to_read ());
115+ DEBUGDPP (" " , *this );
99116 assert (exclusively_used);
100117 exclusively_used = false ;
101118 ++readers;
102119}
103120
104121seastar::future<> tri_mutex::lock_for_write ()
105122{
123+ LOG_PREFIX (tri_mutex::lock_for_write ());
124+ DEBUGDPP (" " , *this );
106125 if (try_lock_for_write ()) {
126+ DEBUGDPP (" lock_for_write successfully" , *this );
107127 return seastar::now ();
108128 }
129+ DEBUGDPP (" can't lock_for_write, adding to waiters" , *this );
109130 waiters.emplace_back (seastar::promise<>(), type_t ::write);
110131 return waiters.back ().pr .get_future ();
111132}
112133
113134bool tri_mutex::try_lock_for_write () noexcept
114135{
136+ LOG_PREFIX (tri_mutex::try_lock_for_write ());
137+ DEBUGDPP (" " , *this );
115138 if (!readers && !exclusively_used) {
116139 if (waiters.empty ()) {
117140 ++writers;
@@ -123,6 +146,8 @@ bool tri_mutex::try_lock_for_write() noexcept
123146
124147void tri_mutex::unlock_for_write ()
125148{
149+ LOG_PREFIX (tri_mutex::unlock_for_write ());
150+ DEBUGDPP (" " , *this );
126151 assert (writers > 0 );
127152 if (--writers == 0 ) {
128153 wake ();
@@ -131,13 +156,17 @@ void tri_mutex::unlock_for_write()
131156
132157void tri_mutex::promote_from_write ()
133158{
159+ LOG_PREFIX (tri_mutex::promote_from_write ());
160+ DEBUGDPP (" " , *this );
134161 assert (writers == 1 );
135162 --writers;
136163 exclusively_used = true ;
137164}
138165
139166void tri_mutex::demote_to_write ()
140167{
168+ LOG_PREFIX (tri_mutex::demote_to_write ());
169+ DEBUGDPP (" " , *this );
141170 assert (exclusively_used);
142171 exclusively_used = false ;
143172 ++writers;
@@ -146,15 +175,21 @@ void tri_mutex::demote_to_write()
146175// for exclusive users
147176seastar::future<> tri_mutex::lock_for_excl ()
148177{
178+ LOG_PREFIX (tri_mutex::lock_for_excl ());
179+ DEBUGDPP (" " , *this );
149180 if (try_lock_for_excl ()) {
181+ DEBUGDPP (" lock_for_excl, successfully" , *this );
150182 return seastar::now ();
151183 }
184+ DEBUGDPP (" can't lock_for_excl, adding to waiters" , *this );
152185 waiters.emplace_back (seastar::promise<>(), type_t ::exclusive);
153186 return waiters.back ().pr .get_future ();
154187}
155188
156189bool tri_mutex::try_lock_for_excl () noexcept
157190{
191+ LOG_PREFIX (tri_mutex::try_lock_for_excl ());
192+ DEBUGDPP (" " , *this );
158193 if (readers == 0u && writers == 0u && !exclusively_used) {
159194 exclusively_used = true ;
160195 return true ;
@@ -165,13 +200,17 @@ bool tri_mutex::try_lock_for_excl() noexcept
165200
166201void tri_mutex::unlock_for_excl ()
167202{
203+ LOG_PREFIX (tri_mutex::unlock_for_excl ());
204+ DEBUGDPP (" " , *this );
168205 assert (exclusively_used);
169206 exclusively_used = false ;
170207 wake ();
171208}
172209
173210bool tri_mutex::is_acquired () const
174211{
212+ LOG_PREFIX (tri_mutex::is_acquired ());
213+ DEBUGDPP (" " , *this );
175214 if (readers != 0u ) {
176215 return true ;
177216 } else if (writers != 0u ) {
@@ -185,6 +224,8 @@ bool tri_mutex::is_acquired() const
185224
186225void tri_mutex::wake ()
187226{
227+ LOG_PREFIX (tri_mutex::wake ());
228+ DEBUGDPP (" " , *this );
188229 assert (!readers && !writers && !exclusively_used);
189230 type_t type = type_t ::none;
190231 while (!waiters.empty ()) {
@@ -210,7 +251,9 @@ void tri_mutex::wake()
210251 default :
211252 assert (0 );
212253 }
254+ // TODO: DEBUGDPP("waking up {} ", *this);
213255 waiter.pr .set_value ();
214256 waiters.pop_front ();
215257 }
258+ DEBUGDPP (" no waiters" , *this );
216259}
0 commit comments