Skip to content

Conversation

@ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Nov 3, 2017

Call sync.h primitives "locks" and "mutexes" instead of "blocks" and "waitable critical sections" to match current coding conventions and c++11 standard names.

This PR does not rename the "CCriticalSection" class (though this could be done as a followup) because it's used everywhere and would swamp the other changes in this PR. Plain mutexes should mostly be preferred instead of recursive mutexes in new code anyway.

@promag
Copy link
Contributor

promag commented Nov 3, 2017

Concept ACK.

Drop C prefix too?

@ryanofsky
Copy link
Contributor Author

Concept ACK.

Drop C prefix too?

Thanks, will wait for more feedback. I didn't rename CCriticalSection because it's used everywhere and changing it would make the diff 3 times as big (22 lines -> 73 lines). Also I think we will probably lean toward using non-recursive rather than recursive locks in new code, so CCriticalSection name should not matter as much going forward. I kept the C in CCriticalLock to be consistent with CCriticalSection. CCriticalLock is only used internally in sync.h so again it shouldn't have an impact on new code, and I didn't see a reason to break consistency within sync.h.

@practicalswift
Copy link
Contributor

utACK eec3e22

@TheBlueMatt
Copy link
Contributor

To me, calling it just "Mutex"/"Lock" implies this is what people should use for new mutexs/locks, but that isn't what we want because it doesn't support DEBUG_LOCKORDER. Indeed, we maybe could make it support DEBUG_LOCKORDER and then start migrating to it over our current recursive stuff, but for now I'd prefer to make it more clear that the new typedefs should be discouraged.

@ryanofsky
Copy link
Contributor Author

Is DEBUG_LOCKORDER the only reason you want to discourage these?

@TheBlueMatt
Copy link
Contributor

I suppose, I mean as long as its clear that its non-recursive and someone doesn't introduce a bug on accident cause they're not paying attention, DEBUG_LOCKORDER would be my only complaint.

@ryanofsky
Copy link
Contributor Author

I'll just implement DEBUG_LOCKORDER for these. It should be pretty easy.

@laanwj
Copy link
Member

laanwj commented Nov 9, 2017

If we're renaming them anyway, why not call them what they are? RecursiveMutex. RecursiveLock, Mutex, Lock?

Do we need any special, project-local names for locking constructs at all or could we do with simply the c++11 naming? (I've wondered about this many times)

I'm all for using non-recursive locks in new code, using recursive locks is usually discouraged nowadays.

@TheBlueMatt
Copy link
Contributor

Indeed, after #11640, and because this is scripted, I'd be more than happy to see us drop the "CriticalSection" naming - no one uses that anymore...

@practicalswift
Copy link
Contributor

practicalswift commented Nov 10, 2017

Agree with @laanwj – let's use the standard C++11 naming instead of project-local names for the locking constructs.

Are there any good arguments for continuing with project-local names for the locking constructs?

@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 87 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@laanwj
Copy link
Member

laanwj commented Aug 31, 2018

Please get rid of the "Merge remote-tracking branch 'origin/pull/11640/head'" merge commit

utACK otherwise

@ryanofsky
Copy link
Contributor Author

Please get rid of the "Merge remote-tracking branch 'origin/pull/11640/head'" merge commit

utACK otherwise

@laanwj, could you add your utACK to #11640? The merge just indicates #11599 is based on #11640, and distinguishes the #11599 commits from the #11640 one.

Call sync.h primitives "locks" and "mutexes" instead of "blocks" and "waitable
critical sections" to match current coding conventions and c++11 standard
names.

This PR does not rename the "CCriticalSection" class (though this could be done
as a followup) because it is used everywhere and would swamp the other changes
in this PR. Plain mutexes should mostly be preferred instead of recursive
mutexes in new code anyway.

-BEGIN VERIFY SCRIPT-
set -x
set -e
ren() { git grep -l $1 | xargs sed -i s/$1/$2/; }
ren CCriticalBlock           UniqueLock
ren CWaitableCriticalSection Mutex
ren CConditionVariable       std::condition_variable
ren cs_GenesisWait           g_genesis_wait_mutex
ren condvar_GenesisWait      g_genesis_wait_cv
perl -0777 -pi -e 's/.*typedef.*condition_variable.*\n\n?//g' src/sync.h
-END VERIFY SCRIPT-
@maflcko
Copy link
Member

maflcko commented Aug 31, 2018

Needs rebase

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Aug 31, 2018

Needs rebase

Rebased f21c529 -> 190bf62 (pr/locksren.8 -> pr/locksren.9) after #11599 merge.

@laanwj
Copy link
Member

laanwj commented Aug 31, 2018

utACK 190bf62

@laanwj laanwj merged commit 190bf62 into bitcoin:master Aug 31, 2018
laanwj added a commit that referenced this pull request Aug 31, 2018
190bf62 scripted-diff: Small locking rename (Russell Yanofsky)

Pull request description:

  Call sync.h primitives "locks" and "mutexes" instead of "blocks" and "waitable critical sections" to match current coding conventions and c++11 standard names.

  This PR does not rename the "CCriticalSection" class (though this could be done as a followup) because it's used everywhere and would swamp the other changes in this PR. Plain mutexes should mostly be preferred instead of recursive mutexes in new code anyway.

Tree-SHA512: 39b5b2be8f7a98227be8ab0648bdbb1b620944659bdc1eb9a15b0fcc0c930457fa0c03170cfedaeee0007ea716c526b31a8d84a86dd2333ce9d8bfabd773fe45
@str4d str4d mentioned this pull request Apr 12, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jun 6, 2021
UdjinM6 added a commit to dashpay/dash that referenced this pull request Jun 11, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants