Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitccf312a

Browse files
committed
Remove return values of ConditionVariableSignal/Broadcast.
In the wake of commitaced5a9, the semantics of these results area bit squishy: we can tell whether we signaled some other process(es),but we do not know which ones were real waiters versus mere sentinelsfor ConditionVariableBroadcast operations. It does not help much thatConditionVariableBroadcast will attempt to pass on the signal to thenext real waiter, because (a) there might not be one, and (b) that willonly happen awhile later, anyway. So these results could overstate howmuch effect the calls really had.However, no existing caller of either function pays any attention to itsresult value, so it seems reasonable to just define that as a requiredproperty of a correct algorithm. To encourage correctness and save sometiny number of cycles, change both functions to return void.Patch by me, per an observation by Thomas Munro. No back-patch, sinceif any third parties happen to be using these functions, they might notappreciate an API break in a minor release.Discussion:https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
1 parent3cac0ec commitccf312a

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

‎src/backend/storage/lmgr/condition_variable.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,14 @@ ConditionVariableCancelSleep(void)
186186
}
187187

188188
/*
189-
* Wake upone sleeping process, assuming there isat least one.
189+
* Wake upthe oldest process sleeping on the CV, if there isany.
190190
*
191-
* The return value indicates whether or not we woke somebody up.
191+
* Note: it's difficult to tell whether this has any real effect: we know
192+
* whether we took an entry off the list, but the entry might only be a
193+
* sentinel. Hence, think twice before proposing that this should return
194+
* a flag telling whether it woke somebody.
192195
*/
193-
bool
196+
void
194197
ConditionVariableSignal(ConditionVariable*cv)
195198
{
196199
PGPROC*proc=NULL;
@@ -203,24 +206,19 @@ ConditionVariableSignal(ConditionVariable *cv)
203206

204207
/* If we found someone sleeping, set their latch to wake them up. */
205208
if (proc!=NULL)
206-
{
207209
SetLatch(&proc->procLatch);
208-
return true;
209-
}
210-
211-
/* No sleeping processes. */
212-
return false;
213210
}
214211

215212
/*
216-
* Wake up all sleepingprocesses.
213+
* Wake up allprocessessleepingon the given CV.
217214
*
218-
* The return value indicates the number of processes we woke.
215+
* This guarantees to wake all processes that were sleeping on the CV
216+
* at time of call, but processes that add themselves to the list mid-call
217+
* will typically not get awakened.
219218
*/
220-
int
219+
void
221220
ConditionVariableBroadcast(ConditionVariable*cv)
222221
{
223-
intnwoken=0;
224222
intpgprocno=MyProc->pgprocno;
225223
PGPROC*proc=NULL;
226224
boolhave_sentinel= false;
@@ -270,10 +268,7 @@ ConditionVariableBroadcast(ConditionVariable *cv)
270268

271269
/* Awaken first waiter, if there was one. */
272270
if (proc!=NULL)
273-
{
274271
SetLatch(&proc->procLatch);
275-
++nwoken;
276-
}
277272

278273
while (have_sentinel)
279274
{
@@ -297,11 +292,6 @@ ConditionVariableBroadcast(ConditionVariable *cv)
297292
SpinLockRelease(&cv->mutex);
298293

299294
if (proc!=NULL&&proc!=MyProc)
300-
{
301295
SetLatch(&proc->procLatch);
302-
++nwoken;
303-
}
304296
}
305-
306-
returnnwoken;
307297
}

‎src/include/storage/condition_variable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern void ConditionVariableCancelSleep(void);
5353
externvoidConditionVariablePrepareToSleep(ConditionVariable*);
5454

5555
/* Wake up a single waiter (via signal) or all waiters (via broadcast). */
56-
externboolConditionVariableSignal(ConditionVariable*);
57-
externintConditionVariableBroadcast(ConditionVariable*);
56+
externvoidConditionVariableSignal(ConditionVariable*cv);
57+
externvoidConditionVariableBroadcast(ConditionVariable*cv);
5858

5959
#endif/* CONDITION_VARIABLE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp