Skip to content

Commit b0f6f46

Browse files
committed
ai safe: HdlrDom WDom Log SafePtr MsgSelf Sem ThPoolBack
1 parent fc6cf04 commit b0f6f46

File tree

9 files changed

+28
-9
lines changed

9 files changed

+28
-9
lines changed

src/domino/HdlrDomino.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ bool HdlrDomino<aDominoType>::setMsgSelfOK(const S_PTR<MsgSelf>& aMsgSelf) noexc
205205
template<class aDominoType>
206206
void HdlrDomino<aDominoType>::triggerHdlr_(const SharedMsgCB& aValidHdlr, Domino::Event aValidEv) noexcept
207207
{
208+
if (! msgSelf_)
209+
{
210+
ERR("(HdlrDom) Failed!!! since MsgSelf is invalid in triggerHdlr_().");
211+
return;
212+
}
208213
HID("(HdlrDom) trigger a new msg.");
209214
msgSelf_->newMsgOK(
210215
[weakMsgCB = WeakMsgCB(aValidHdlr)]() mutable noexcept // WeakMsgCB is to support rm hdlr

src/domino/WbasicDatDom.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ S_PTR<void> WbasicDatDom<aDominoType>::getData(const Domino::EvName& aEvName) co
5757
if (not isWrCtrl_(ev))
5858
return aDominoType::getData_(ev);
5959

60-
WRN("(WbasicDatDom) Failed!!! EvName=" << aEvName << " is not write-protect so unavailable via this func!!!");
60+
WRN("(WbasicDatDom) Failed!!! EvName=" << aEvName << " is write-protect so unavailable via this func!!!");
6161
return nullptr;
6262
}
6363

@@ -74,7 +74,7 @@ bool WbasicDatDom<aDominoType>::replaceDataOK(const Domino::EvName& aEvName, S_P
7474
{
7575
const auto ev = this->getEventBy(aEvName);
7676
if (isWrCtrl_(ev)) {
77-
WRN("(WbasicDatDom) Failed!!! EvName=" << aEvName << " is not write-protect so unavailable via this func!!!")
77+
WRN("(WbasicDatDom) Failed!!! EvName=" << aEvName << " is write-protect so unavailable via this func!!!")
7878
return false;
7979
}
8080
else return aDominoType::replaceDataOK(aEvName, std::move(aData));

src/log/StrCoutFSL.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class StringStreamBuf : public std::streambuf
4646

4747
std::streamsize xsputn(const char* s, std::streamsize n) override
4848
{
49+
if (!s || n <= 0) return 0;
4950
buf_.append(s, static_cast<size_t>(n));
5051
return n;
5152
}

src/log/UniCoutLog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ostream& UniCoutLog::oneLog() noexcept
2121
}
2222

2323
// ***********************************************************************************************
24-
UniCoutLog UniCoutLog::defaultUniLog_;
25-
size_t UniCoutLog::nLogLine_ = 0;
24+
UniCoutLog UniCoutLog::defaultUniLog_;
25+
std::atomic<size_t> UniCoutLog::nLogLine_ = 0;
2626

2727
} // namespaces

src/log/UniCoutLog.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// ***********************************************************************************************
2020
#pragma once
2121

22+
#include <atomic>
2223
#include <iostream>
2324

2425
#include "UniBaseLog.hpp"
@@ -41,8 +42,8 @@ class UniCoutLog
4142

4243
// -------------------------------------------------------------------------------------------
4344
public:
44-
static UniCoutLog defaultUniLog_;
45-
static size_t nLogLine_; // ut only, simpler here
45+
static UniCoutLog defaultUniLog_;
46+
static std::atomic<size_t> nLogLine_; // ut only, simpler here
4647

4748
#ifdef IN_GTEST
4849
// -------------------------------------------------------------------------------------------

src/msg_self/MsgSelf.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class MsgSelf : public UniLog
7575
explicit MsgSelf(const LogName& aUniLogName = ULN_DEFAULT) noexcept : UniLog(aUniLogName) {}
7676
~MsgSelf() noexcept { if (nMsg_) WRN("discard nMsg=" << nMsg_); }
7777

78+
MsgSelf(const MsgSelf&) = delete;
79+
MsgSelf& operator=(const MsgSelf&) = delete;
80+
MsgSelf(MsgSelf&&) = delete;
81+
MsgSelf& operator=(MsgSelf&&) = delete;
82+
7883
bool newMsgOK(MsgCB, const EMsgPriority = EMsgPri_NORM) noexcept;
7984
size_t nMsg() const noexcept { return nMsg_; }
8085
size_t nMsg(const EMsgPriority aPri) const noexcept { return aPri < EMsgPri_MAX ? msgQueues_[aPri].size() : 0; }

src/safe_mem/SafePtr.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ SafeWeak<T>::SafeWeak(const SafePtr<T>& aSafeFrom) noexcept
266266
template<typename T>
267267
SafePtr<T> SafeWeak<T>::lock() const noexcept
268268
{
269-
return (pT_.expired())
270-
? nullptr
271-
: SafePtr<T>(pT_.lock(), realType_, lastType_); // constructor is faster
269+
auto sp = pT_.lock();
270+
if (!sp) return SafePtr<T>();
271+
return SafePtr<T>(std::move(sp), realType_, lastType_); // constructor is faster
272272
}
273273
} // namespace
274274

src/thread/MT_Semaphore.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void MT_Semaphore::timedwait(const size_t aSec, const size_t aRestNsec) noexcept
3939
mt_notified_.clear(std::memory_order_release); // release: publish flag clear to other threads
4040
return;
4141
}
42+
else if (errno != EINTR) // EINVAL or other unexpected error
43+
break;
4244

4345
// impossible since MT_Semaphore's constructor
4446
// else if (errno == EINVAL) // avoid dead loop

src/thread/ThPoolBack.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class ThPoolBack : public ThreadBack
3939
explicit ThPoolBack(size_t aMaxThread = 10) noexcept(false);
4040
~ThPoolBack() noexcept;
4141

42+
ThPoolBack(const ThPoolBack&) = delete;
43+
ThPoolBack& operator=(const ThPoolBack&) = delete;
44+
ThPoolBack(ThPoolBack&&) = delete;
45+
ThPoolBack& operator=(ThPoolBack&&) = delete;
46+
4247
bool newTaskOK(MT_TaskEntryFN, TaskBackFN, UniLog& = UniLog::defaultUniLog_) noexcept override;
4348

4449
private:

0 commit comments

Comments
 (0)