Skip to content

Commit 0150e46

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Rename private and internal data members from "Lock" to "Mutex"
Replaced the word "Lock" with "Mutex", in the identifier of private and internal member variables that are declared as `std::mutex`: MersenneTwisterRandomVariateGenerator::m_InstanceLock FFTWGlobalConfiguration::m_Lock FFTWGlobalConfigurationGlobals::m_CreationLock FEMFactoryBase::m_CreationLock m_MetricCalculationLock (from RegistrationFunction classes) MultiThreaderBaseGlobals::globalDefaultInitializerLock PlatformMultiThreader::m_SpawnedThreadActiveFlagLock ioDefaultSplitterLock createImageIOLock Follow-up to commit d0a8534 "ENH: using standard library's mutex primitives", Dženan Zukić, October 31, 2018.
1 parent 8149ba9 commit 0150e46

24 files changed

+46
-46
lines changed

Modules/Core/Common/include/itkMersenneTwisterRandomVariateGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class ITKCommon_EXPORT MersenneTwisterRandomVariateGenerator : public RandomVari
324324
CreateInstance();
325325

326326
// Local lock to enable concurrent access to singleton
327-
std::mutex m_InstanceLock{};
327+
std::mutex m_InstanceMutex{};
328328

329329
// Static/Global Variable need to be thread-safely accessed
330330

@@ -337,7 +337,7 @@ class ITKCommon_EXPORT MersenneTwisterRandomVariateGenerator : public RandomVari
337337
inline void
338338
MersenneTwisterRandomVariateGenerator::Initialize(const IntegerType seed)
339339
{
340-
const std::lock_guard<std::mutex> mutexHolder(m_InstanceLock);
340+
const std::lock_guard<std::mutex> mutexHolder(m_InstanceMutex);
341341
this->m_Seed = seed;
342342
// Initialize generator state with seed
343343
// See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.

Modules/Core/Common/include/itkPlatformMultiThreader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class ITKCommon_EXPORT PlatformMultiThreader : public MultiThreaderBase
162162
/** Storage of MutexFunctions and ints used to control spawned
163163
* threads and the spawned thread ids. */
164164
int m_SpawnedThreadActiveFlag[ITK_MAX_THREADS]{};
165-
std::shared_ptr<std::mutex> m_SpawnedThreadActiveFlagLock[ITK_MAX_THREADS]{};
165+
std::shared_ptr<std::mutex> m_SpawnedThreadActiveFlagMutex[ITK_MAX_THREADS]{};
166166
ThreadProcessIdType m_SpawnedThreadProcessID[ITK_MAX_THREADS]{};
167167
WorkUnitInfo m_SpawnedThreadInfoArray[ITK_MAX_THREADS]{};
168168

Modules/Core/Common/src/itkMultiThreaderBase.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct MultiThreaderBaseGlobals
6767
// API is ever used by the developer, the developers choice is
6868
// respected over the environmental variable.
6969
bool GlobalDefaultThreaderTypeIsInitialized{ false };
70-
std::mutex globalDefaultInitializerLock;
70+
std::mutex globalDefaultInitializerMutex;
7171

7272
// Global value to control which threader to be used by default. First it is initialized with the default preprocessor
7373
// definition from CMake configuration value, for compile time control of default. This initial value can be
@@ -114,7 +114,7 @@ MultiThreaderBase::GetGlobalDefaultUseThreadPool()
114114
void
115115
MultiThreaderBase::SetGlobalDefaultThreaderPrivate(ThreaderEnum threaderType)
116116
{
117-
// m_PimplGlobals->globalDefaultInitializerLock must be already held here!
117+
// m_PimplGlobals->globalDefaultInitializerMutex must be already held here!
118118

119119
m_PimplGlobals->m_GlobalDefaultThreader = threaderType;
120120
m_PimplGlobals->GlobalDefaultThreaderTypeIsInitialized = true;
@@ -126,15 +126,15 @@ MultiThreaderBase::SetGlobalDefaultThreader(ThreaderEnum threaderType)
126126
itkInitGlobalsMacro(PimplGlobals);
127127

128128
// Acquire mutex then call private method to do the real work.
129-
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerLock);
129+
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerMutex);
130130

131131
MultiThreaderBase::SetGlobalDefaultThreaderPrivate(threaderType);
132132
}
133133

134134
MultiThreaderBase::ThreaderEnum
135135
MultiThreaderBase::GetGlobalDefaultThreaderPrivate()
136136
{
137-
// m_PimplGlobals->globalDefaultInitializerLock must be already held here!
137+
// m_PimplGlobals->globalDefaultInitializerMutex must be already held here!
138138

139139
if (!m_PimplGlobals->GlobalDefaultThreaderTypeIsInitialized)
140140
{
@@ -182,7 +182,7 @@ MultiThreaderBase::GetGlobalDefaultThreader()
182182
itkInitGlobalsMacro(PimplGlobals);
183183

184184
// Acquire mutex then call private method to do the real work.
185-
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerLock);
185+
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerMutex);
186186

187187
return MultiThreaderBase::GetGlobalDefaultThreaderPrivate();
188188
}
@@ -233,7 +233,7 @@ MultiThreaderBase::SetGlobalDefaultNumberOfThreads(ThreadIdType val)
233233
{
234234
itkInitGlobalsMacro(PimplGlobals);
235235

236-
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerLock);
236+
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerMutex);
237237

238238
m_PimplGlobals->m_GlobalDefaultNumberOfThreads =
239239
std::clamp<ThreadIdType>(val, 1, m_PimplGlobals->m_GlobalMaximumNumberOfThreads);
@@ -263,7 +263,7 @@ MultiThreaderBase::GetGlobalDefaultNumberOfThreads()
263263
{
264264
itkInitGlobalsMacro(PimplGlobals);
265265

266-
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerLock);
266+
const std::lock_guard<std::mutex> lock(m_PimplGlobals->globalDefaultInitializerMutex);
267267

268268
if (m_PimplGlobals->m_GlobalDefaultNumberOfThreads == 0) // need to initialize
269269
{

Modules/Core/Common/src/itkPlatformMultiThreader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ PlatformMultiThreader::PlatformMultiThreader()
5757
#endif
5858

5959
m_SpawnedThreadActiveFlag[i] = 0;
60-
m_SpawnedThreadActiveFlagLock[i] = nullptr;
60+
m_SpawnedThreadActiveFlagMutex[i] = nullptr;
6161
m_SpawnedThreadInfoArray[i].WorkUnitID = i;
6262
}
6363
}

Modules/Core/Common/src/itkPlatformMultiThreaderPosix.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ PlatformMultiThreader::SpawnThread(ThreadFunctionType f, void * UserData)
109109

110110
for (; id < ITK_MAX_THREADS; ++id)
111111
{
112-
if (!m_SpawnedThreadActiveFlagLock[id])
112+
if (!m_SpawnedThreadActiveFlagMutex[id])
113113
{
114-
m_SpawnedThreadActiveFlagLock[id] = std::make_shared<std::mutex>();
114+
m_SpawnedThreadActiveFlagMutex[id] = std::make_shared<std::mutex>();
115115
}
116-
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagLock[id]);
116+
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagMutex[id]);
117117

118118
if (m_SpawnedThreadActiveFlag[id] == 0)
119119
{
@@ -131,7 +131,7 @@ PlatformMultiThreader::SpawnThread(ThreadFunctionType f, void * UserData)
131131
m_SpawnedThreadInfoArray[id].UserData = UserData;
132132
m_SpawnedThreadInfoArray[id].NumberOfWorkUnits = 1;
133133
m_SpawnedThreadInfoArray[id].ActiveFlag = &m_SpawnedThreadActiveFlag[id];
134-
m_SpawnedThreadInfoArray[id].ActiveFlagLock = m_SpawnedThreadActiveFlagLock[id];
134+
m_SpawnedThreadInfoArray[id].ActiveFlagLock = m_SpawnedThreadActiveFlagMutex[id];
135135

136136
pthread_attr_t attr;
137137

@@ -161,13 +161,13 @@ PlatformMultiThreader::TerminateThread(ThreadIdType WorkUnitID)
161161
}
162162

163163
{
164-
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagLock[WorkUnitID]);
164+
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagMutex[WorkUnitID]);
165165
m_SpawnedThreadActiveFlag[WorkUnitID] = 0;
166166
}
167167

168168
pthread_join(m_SpawnedThreadProcessID[WorkUnitID], nullptr);
169169

170-
m_SpawnedThreadActiveFlagLock[WorkUnitID] = nullptr;
170+
m_SpawnedThreadActiveFlagMutex[WorkUnitID] = nullptr;
171171
}
172172
#endif
173173

Modules/Core/Common/src/itkPlatformMultiThreaderWindows.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ PlatformMultiThreader::SpawnThread(ThreadFunctionType f, void * UserData)
104104

105105
for (; id < ITK_MAX_THREADS; ++id)
106106
{
107-
if (!m_SpawnedThreadActiveFlagLock[id])
107+
if (!m_SpawnedThreadActiveFlagMutex[id])
108108
{
109-
m_SpawnedThreadActiveFlagLock[id] = std::make_shared<std::mutex>();
109+
m_SpawnedThreadActiveFlagMutex[id] = std::make_shared<std::mutex>();
110110
}
111-
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagLock[id]);
111+
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagMutex[id]);
112112

113113
if (m_SpawnedThreadActiveFlag[id] == 0)
114114
{
@@ -126,7 +126,7 @@ PlatformMultiThreader::SpawnThread(ThreadFunctionType f, void * UserData)
126126
m_SpawnedThreadInfoArray[id].UserData = UserData;
127127
m_SpawnedThreadInfoArray[id].NumberOfWorkUnits = 1;
128128
m_SpawnedThreadInfoArray[id].ActiveFlag = &m_SpawnedThreadActiveFlag[id];
129-
m_SpawnedThreadInfoArray[id].ActiveFlagLock = m_SpawnedThreadActiveFlagLock[id];
129+
m_SpawnedThreadInfoArray[id].ActiveFlagLock = m_SpawnedThreadActiveFlagMutex[id];
130130

131131
// Using _beginthreadex on a PC
132132
//
@@ -148,13 +148,13 @@ PlatformMultiThreader::TerminateThread(ThreadIdType WorkUnitID)
148148
}
149149

150150
{
151-
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagLock[WorkUnitID]);
151+
const std::lock_guard<std::mutex> lockGuard(*m_SpawnedThreadActiveFlagMutex[WorkUnitID]);
152152
m_SpawnedThreadActiveFlag[WorkUnitID] = 0;
153153
}
154154

155155
WaitForSingleObject(m_SpawnedThreadProcessID[WorkUnitID], INFINITE);
156156
CloseHandle(m_SpawnedThreadProcessID[WorkUnitID]);
157-
m_SpawnedThreadActiveFlagLock[WorkUnitID] = nullptr;
157+
m_SpawnedThreadActiveFlagMutex[WorkUnitID] = nullptr;
158158
}
159159
#endif
160160

Modules/Filtering/FFT/include/itkFFTWGlobalConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object
367367

368368
static FFTWGlobalConfigurationGlobals * m_PimplGlobals;
369369

370-
std::mutex m_Lock;
370+
std::mutex m_Mutex;
371371
bool m_NewWisdomAvailable{ false };
372372
int m_PlanRigor{ 0 };
373373
bool m_WriteWisdomCache{ false };

Modules/Filtering/FFT/src/itkFFTWGlobalConfiguration.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct FFTWGlobalConfigurationGlobals
4848
: m_Instance(nullptr){};
4949

5050
FFTWGlobalConfiguration::Pointer m_Instance;
51-
std::mutex m_CreationLock;
51+
std::mutex m_CreationMutex;
5252
};
5353

5454
WisdomFilenameGeneratorBase::WisdomFilenameGeneratorBase() = default;
@@ -148,7 +148,7 @@ FFTWGlobalConfiguration::GetInstance()
148148
itkInitGlobalsMacro(PimplGlobals);
149149
if (!m_PimplGlobals->m_Instance)
150150
{
151-
const std::lock_guard<std::mutex> lockGuard(m_PimplGlobals->m_CreationLock);
151+
const std::lock_guard<std::mutex> lockGuard(m_PimplGlobals->m_CreationMutex);
152152
// Need to make sure that during gaining access
153153
// to the lock that some other thread did not
154154
// initialize the singleton.
@@ -734,7 +734,7 @@ FFTWGlobalConfiguration::ExportWisdomFileDouble(const std::string &
734734
std::mutex &
735735
FFTWGlobalConfiguration::GetLockMutex()
736736
{
737-
return GetInstance()->m_Lock;
737+
return GetInstance()->m_Mutex;
738738
}
739739

740740
void

Modules/IO/ImageBase/src/itkImageIOBase.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ ImageIOBase::ReadBufferAsASCII(std::istream & is, void * buffer, IOComponentEnum
937937

938938
namespace
939939
{
940-
std::mutex ioDefaultSplitterLock;
940+
std::mutex ioDefaultSplitterMutex;
941941
ImageRegionSplitterBase::Pointer ioDefaultSplitter;
942942

943943
} // namespace
@@ -949,7 +949,7 @@ ImageIOBase::GetImageRegionSplitter() const
949949
{
950950
// thread safe lazy initialization, prevent race condition on
951951
// setting, with an atomic set if null.
952-
const std::lock_guard<std::mutex> lock(ioDefaultSplitterLock);
952+
const std::lock_guard<std::mutex> lock(ioDefaultSplitterMutex);
953953
if (ioDefaultSplitter.IsNull())
954954
{
955955
ioDefaultSplitter = ImageRegionSplitterSlowDimension::New().GetPointer();

Modules/IO/ImageBase/src/itkImageIOFactory.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ namespace itk
2626

2727
namespace
2828
{
29-
std::mutex createImageIOLock;
29+
std::mutex createImageIOMutex;
3030
}
3131

3232
ImageIOBase::Pointer
3333
ImageIOFactory::CreateImageIO(const char * path, IOFileModeEnum mode)
3434
{
3535
std::list<ImageIOBase::Pointer> possibleImageIO;
3636

37-
const std::lock_guard<std::mutex> mutexHolder(createImageIOLock);
37+
const std::lock_guard<std::mutex> mutexHolder(createImageIOMutex);
3838

3939
for (auto & allobject : ObjectFactoryBase::CreateAllInstance("itkImageIOBase"))
4040
{

0 commit comments

Comments
 (0)