Skip to content

Commit

Permalink
[all] Use uniform initialization for LockGuard
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Kobets <[email protected]>
  • Loading branch information
mykola-kobets-epam committed Oct 3, 2024
1 parent 587e954 commit 272ce03
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
16 changes: 8 additions & 8 deletions include/aos/common/tools/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Allocator : private NonCopyable {
*/
void Clear()
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

mAllocations->Clear();
}
Expand All @@ -105,7 +105,7 @@ class Allocator : private NonCopyable {
*/
void* Allocate(size_t size)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

if (mAllocations->IsFull() || GetAllocatedSize() + size > mMaxSize) {
assert(false);
Expand All @@ -130,7 +130,7 @@ class Allocator : private NonCopyable {
*/
void Free(void* data)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

[[maybe_unused]] auto curEnd = mAllocations->end();
[[maybe_unused]] auto newEnd
Expand All @@ -147,7 +147,7 @@ class Allocator : private NonCopyable {
*/
RetWithError<Allocation*> FindAllocation(const void* data)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

return mAllocations->Find([data](const Allocation& allocation) { return allocation.Data() == data; });
}
Expand Down Expand Up @@ -185,7 +185,7 @@ class Allocator : private NonCopyable {
*/
size_t FreeSize() const
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

return mMaxSize - GetAllocatedSize();
}
Expand All @@ -197,7 +197,7 @@ class Allocator : private NonCopyable {
*/
size_t MaxSize() const
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

return mMaxSize;
}
Expand All @@ -209,7 +209,7 @@ class Allocator : private NonCopyable {
*/
size_t MaxAllocatedSize() const
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

return mMaxAllocatedSize;
}
Expand All @@ -219,7 +219,7 @@ class Allocator : private NonCopyable {
*/
void ResetMaxAllocatedSize()
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

mMaxAllocatedSize = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions include/aos/common/tools/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class ThreadPool : private NonCopyable {
template <typename T>
Error AddTask(T functor, void* arg = nullptr)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

auto err = mQueue.Push(Function());
if (!err.IsNone()) {
Expand Down Expand Up @@ -508,7 +508,7 @@ class ThreadPool : private NonCopyable {
*/
Error Run()
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

mShutdown = false;

Expand Down
4 changes: 2 additions & 2 deletions include/aos/common/tools/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Timer {
template <typename F>
Error Create(unsigned int intervalMs, F functor, bool oneShot = true, void* arg = nullptr)
{
aos::LockGuard lock(mMutex);
aos::LockGuard lock {mMutex};

if (mTimerID != 0) {
auto err = Stop();
Expand Down Expand Up @@ -98,7 +98,7 @@ class Timer {
*/
Error Stop()
{
aos::LockGuard lock(mMutex);
aos::LockGuard lock {mMutex};

mStop = true;

Expand Down
2 changes: 1 addition & 1 deletion src/common/monitoring/resourcemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Error ResourceMonitor::StopInstanceMonitoring(const String& instanceID)

Error ResourceMonitor::GetAverageMonitoringData(NodeMonitoringData& monitoringData)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

auto err = mAverage.GetData(monitoringData);
if (!err.IsNone()) {
Expand Down
8 changes: 4 additions & 4 deletions src/common/pkcs11/pkcs11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ RetWithError<CK_FUNCTION_LIST_PTR> DynamicLibraryContext::Init()

Error LibraryContext::Init()
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

Error err = ErrorEnum::eNone;

Expand Down Expand Up @@ -467,7 +467,7 @@ Error LibraryContext::GetLibInfo(LibInfo& libInfo) const

RetWithError<SharedPtr<SessionContext>> LibraryContext::OpenSession(SlotID slotID, Flags flags)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

SessionParams params = {slotID, flags};

Expand Down Expand Up @@ -503,7 +503,7 @@ RetWithError<SharedPtr<SessionContext>> LibraryContext::OpenSession(SlotID slotI

void LibraryContext::ClearSessions()
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

mSessions.Clear();
}
Expand Down Expand Up @@ -928,7 +928,7 @@ Error SessionContext::FindObjectsFinal() const

SharedPtr<LibraryContext> PKCS11Manager::OpenLibrary(const String& library)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

for (auto& lib : mLibraries) {
if (lib.mFirst == library) {
Expand Down
22 changes: 11 additions & 11 deletions src/iam/certhandler/certhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CertHandler::CertHandler()

Error CertHandler::RegisterModule(CertModule& module)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_INF() << "Register module: type = " << module.GetCertType();

Expand All @@ -30,7 +30,7 @@ Error CertHandler::RegisterModule(CertModule& module)

Error CertHandler::GetCertTypes(Array<StaticString<cCertTypeLen>>& certTypes)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Get all registered IAM certificate types";

Expand All @@ -46,7 +46,7 @@ Error CertHandler::GetCertTypes(Array<StaticString<cCertTypeLen>>& certTypes)

Error CertHandler::SetOwner(const String& certType, const String& password)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Set owner: type = " << certType;

Expand All @@ -65,7 +65,7 @@ Error CertHandler::SetOwner(const String& certType, const String& password)

Error CertHandler::Clear(const String& certType)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Clear all certificates: type = " << certType;

Expand All @@ -85,7 +85,7 @@ Error CertHandler::Clear(const String& certType)
Error CertHandler::CreateKey(
const String& certType, const String& subjectCommonName, const String& password, String& pemCSR)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Create key: type = " << certType << ", subject = " << subjectCommonName;

Expand All @@ -109,7 +109,7 @@ Error CertHandler::CreateKey(

Error CertHandler::ApplyCertificate(const String& certType, const String& pemCert, CertInfo& info)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Apply cert: type = " << certType;

Expand All @@ -129,7 +129,7 @@ Error CertHandler::ApplyCertificate(const String& certType, const String& pemCer
Error CertHandler::GetCertificate(
const String& certType, const Array<uint8_t>& issuer, const Array<uint8_t>& serial, CertInfo& resCert)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

StaticString<crypto::cSerialNumStrLen> serialInHex;

Expand All @@ -155,7 +155,7 @@ Error CertHandler::GetCertificate(

Error CertHandler::SubscribeCertReceiver(const String& certType, CertReceiverItf& certReceiver)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Subscribe certificate receiver: type = " << certType;

Expand All @@ -181,7 +181,7 @@ Error CertHandler::SubscribeCertReceiver(const String& certType, CertReceiverItf

Error CertHandler::UnsubscribeCertReceiver(CertReceiverItf& certReceiver)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

Error err = ErrorEnum::eNone;
CertReceiverSubscription* subscription = nullptr;
Expand All @@ -196,7 +196,7 @@ Error CertHandler::UnsubscribeCertReceiver(CertReceiverItf& certReceiver)

Error CertHandler::CreateSelfSignedCert(const String& certType, const String& password)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Create self signed cert: type = " << certType;

Expand All @@ -215,7 +215,7 @@ Error CertHandler::CreateSelfSignedCert(const String& certType, const String& pa

RetWithError<ModuleConfig> CertHandler::GetModuleConfig(const String& certType) const
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

auto* module = FindModule(certType);
if (module == nullptr) {
Expand Down
12 changes: 6 additions & 6 deletions src/iam/nodemanager/nodemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace aos::iam::nodemanager {

Error NodeManager::Init(NodeInfoStorageItf& storage)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

mStorage = &storage;

Expand Down Expand Up @@ -46,7 +46,7 @@ Error NodeManager::Init(NodeInfoStorageItf& storage)

Error NodeManager::SetNodeInfo(const NodeInfo& info)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

Error err = ErrorEnum::eNone;

Expand Down Expand Up @@ -80,7 +80,7 @@ Error NodeManager::SetNodeStatus(const String& nodeId, NodeStatus status)

Error NodeManager::GetNodeInfo(const String& nodeId, NodeInfo& nodeInfo) const
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

auto cachedInfo = GetNodeFromCache(nodeId);

Expand All @@ -95,7 +95,7 @@ Error NodeManager::GetNodeInfo(const String& nodeId, NodeInfo& nodeInfo) const

Error NodeManager::GetAllNodeIds(Array<StaticString<cNodeIDLen>>& ids) const
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

for (const auto& nodeInfo : mNodeInfoCache) {
auto err = ids.PushBack(nodeInfo.mNodeID);
Expand All @@ -109,7 +109,7 @@ Error NodeManager::GetAllNodeIds(Array<StaticString<cNodeIDLen>>& ids) const

Error NodeManager::RemoveNodeInfo(const String& nodeId)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

auto cachedInfo = GetNodeFromCache(nodeId);
if (cachedInfo == nullptr) {
Expand All @@ -136,7 +136,7 @@ Error NodeManager::RemoveNodeInfo(const String& nodeId)

Error NodeManager::SubscribeNodeInfoChange(NodeInfoListenerItf& listener)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

mNodeInfoListener = &listener;

Expand Down
6 changes: 3 additions & 3 deletions src/iam/permhandler/permhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace permhandler {
RetWithError<StaticString<cSecretLen>> PermHandler::RegisterInstance(
const InstanceIdent& instanceIdent, const Array<FunctionalServicePermissions>& instancePermissions)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Register instance: instance = " << instanceIdent;

Expand All @@ -44,7 +44,7 @@ RetWithError<StaticString<cSecretLen>> PermHandler::RegisterInstance(

Error PermHandler::UnregisterInstance(const InstanceIdent& instanceIdent)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Unregister instance: instance = " << instanceIdent;

Expand All @@ -61,7 +61,7 @@ Error PermHandler::UnregisterInstance(const InstanceIdent& instanceIdent)
Error PermHandler::GetPermissions(const String& secret, const String& funcServerID, InstanceIdent& instanceIdent,
Array<PermKeyValue>& servicePermissions)
{
LockGuard lock(mMutex);
LockGuard lock {mMutex};

LOG_DBG() << "Get permission: secret = " << secret << ", funcServerID = " << funcServerID;

Expand Down
Loading

0 comments on commit 272ce03

Please sign in to comment.