!783 条件竞争问题整改

Merge pull request !783 from wulimm/master
This commit is contained in:
openharmony_ci 2024-06-11 13:45:57 +00:00 committed by Gitee
commit b2fb4a2d5c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -37,6 +37,7 @@ void HRilEvent::GetNowTime(struct timeval &tv)
bool HRilEvent::GetNextTimeOut(struct timeval &tv)
{
std::lock_guard<std::mutex> mutexLock(listLock_);
std::list<HRilEventMessage>::iterator eventIt = timerList_.begin();
if (eventIt == timerList_.end() || timerList_.empty()) {
return false;
@ -78,6 +79,7 @@ void HRilEvent::ProcessTimerList()
void HRilEvent::ProcessPendingList()
{
std::lock_guard<std::mutex> mutexLock(listLock_);
std::list<HRilEventMessage>::iterator eventIt = pendingList_.begin();
while (eventIt != pendingList_.end()) {
if (eventIt->func != nullptr) {
@ -111,6 +113,7 @@ void HRilEvent::ProcessEvents(fd_set *rfds, int32_t number)
if (rfds == nullptr) {
return;
}
std::lock_guard<std::mutex> mutexLock(listLock_);
auto it = listenEventTable_.begin();
for (; (it != listenEventTable_.end()) && (number > 0); ++it) {
if (*it != nullptr && FD_ISSET((*it)->fd, rfds)) {
@ -125,6 +128,7 @@ void HRilEvent::ProcessEvents(fd_set *rfds, int32_t number)
void HRilEvent::TimerEventInit()
{
std::lock_guard<std::mutex> mutexLock(listLock_);
FD_ZERO(&readFds_);
timerList_.clear();
pendingList_.clear();
@ -202,7 +206,9 @@ void HRilEvent::EventMessageLoop()
TELEPHONY_LOGD("****** EventMessageLoop start ******");
while (1) {
std::unique_lock<std::mutex> mutexLock(listLock_);
(void)memcpy_s(&rfds, sizeof(fd_set), &readFds_, sizeof(fd_set));
mutexLock.unlock();
if (!GetNextTimeOut(timeout)) {
// Enter blocking wait without setting a timer.
TELEPHONY_LOGD("Enter blocking wait without setting a timer.");