Skip to content

Commit b664f08

Browse files
kcudnikyejianquan
andauthored
[syncd] Move logSet logGet under mutex to prevent race condition (#1505)
* [syncd] Move logSet logGet under mutex to prevent race condition Fixes: sonic-net/sonic-buildimage#21180 Mutex is added to protect m_logLevelMap when doing logSet from multiple thread Co-authored-by: Jianquan Ye <[email protected]>
1 parent e11a959 commit b664f08

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

syncd/VendorSai.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,7 @@ sai_status_t VendorSai::logSet(
19491949
_In_ sai_api_t api,
19501950
_In_ sai_log_level_t log_level)
19511951
{
1952+
MUTEX();
19521953
SWSS_LOG_ENTER();
19531954

19541955
m_logLevelMap[api] = log_level;
@@ -1967,6 +1968,7 @@ sai_status_t VendorSai::queryApiVersion(
19671968
sai_log_level_t VendorSai::logGet(
19681969
_In_ sai_api_t api)
19691970
{
1971+
MUTEX();
19701972
SWSS_LOG_ENTER();
19711973

19721974
auto it = m_logLevelMap.find(api);

unittest/syncd/TestVendorSai.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,17 @@ TEST(VendorSai, bulk_meter_rules)
15441544
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.remove((sai_object_type_t)SAI_OBJECT_TYPE_METER_POLICY, meter_policy1));
15451545
}
15461546

1547+
TEST(VendorSai, logSet_logGet)
1548+
{
1549+
VendorSai sai;
1550+
sai.apiInitialize(0, &test_services);
1551+
1552+
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.logSet(SAI_API_PORT, SAI_LOG_LEVEL_DEBUG));
1553+
1554+
EXPECT_EQ(SAI_LOG_LEVEL_DEBUG, sai.logGet(SAI_API_PORT));
1555+
EXPECT_EQ(SAI_LOG_LEVEL_NOTICE, sai.logGet(SAI_API_SWITCH));
1556+
}
1557+
15471558
TEST_F(VendorSaiTest, bulk_prefix_compression_entry)
15481559
{
15491560
sai_prefix_compression_entry_t *e = nullptr;

0 commit comments

Comments
 (0)