Skip to content

Commit b392300

Browse files
qiluo-msftkcudnik
authored andcommitted
Refactor isDefaultFunction into lambda functions (sonic-net#83)
* Refactor isDefaultFunction into lambda functions * Refactor isDefaultQueueId/isDefaultPriorityGroupId into lambda functions
1 parent 4258663 commit b392300

File tree

3 files changed

+10
-46
lines changed

3 files changed

+10
-46
lines changed

syncd/syncd.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <thread>
88
#include <mutex>
99
#include <thread>
10+
#include <set>
1011

1112
#include <unistd.h>
1213
#include <execinfo.h>
@@ -15,7 +16,6 @@
1516

1617
#ifdef SAITHRIFT
1718
#include <utility>
18-
#include <set>
1919
#include <algorithm>
2020
#include <switch_sai_rpc_server.h>
2121
#endif // SAITHRIFT
@@ -65,6 +65,8 @@ extern "C" {
6565
extern void exit_and_notify(int status) __attribute__ ((__noreturn__));
6666

6767
extern std::mutex g_mutex;
68+
extern std::set<sai_object_id_t> g_defaultPriorityGroupsRids;
69+
extern std::set<sai_object_id_t> g_defaultQueuesRids;
6870

6971
void onSyncdStart(bool warmStart);
7072
void hardReinit();
@@ -175,12 +177,4 @@ std::unordered_map<sai_uint32_t, sai_object_id_t> redisGetLaneMap();
175177

176178
std::vector<sai_object_id_t> saiGetPortList();
177179

178-
typedef bool (*isDefaultFunction)(sai_object_id_t);
179-
180-
bool isDefaultQueueId(sai_object_id_t queueId);
181-
bool isDefaultPriorityGroupId(sai_object_id_t pgId);
182-
bool isDefaultVirtualRouterId(sai_object_id_t id);
183-
bool isDefaultTrapGroupId(sai_object_id_t id);
184-
bool isDefaultPortId(sai_object_id_t id);
185-
186180
#endif // __SYNCD_H__

syncd/syncd_hard_reinit.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ void hardReinit()
270270
checkAllIds();
271271
}
272272

273+
template<typename FUN>
273274
bool shouldSkipCreateion(
274275
sai_object_id_t vid,
275276
sai_object_id_t& rid,
276277
bool& createObject,
277-
isDefaultFunction fun)
278+
FUN fun)
278279
{
279280
auto it = g_vidToRidMap.find(vid);
280281

@@ -330,35 +331,35 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
330331

331332
if (objectType == SAI_OBJECT_TYPE_VIRTUAL_ROUTER)
332333
{
333-
if (shouldSkipCreateion(vid, rid, createObject, isDefaultVirtualRouterId))
334+
if (shouldSkipCreateion(vid, rid, createObject, [](sai_object_id_t id) { return id == redisGetDefaultVirtualRouterId(); }))
334335
{
335336
SWSS_LOG_INFO("default virtual router will not be created, processed VID %llx to RID %llx", vid, rid);
336337
}
337338
}
338339
else if (objectType == SAI_OBJECT_TYPE_QUEUE)
339340
{
340-
if (shouldSkipCreateion(vid, rid, createObject, isDefaultQueueId))
341+
if (shouldSkipCreateion(vid, rid, createObject, [&](sai_object_id_t queueId) { return g_defaultQueuesRids.find(queueId) != g_defaultQueuesRids.end(); }))
341342
{
342343
SWSS_LOG_DEBUG("default queue will not be created, processed VID %llx to RID %llx", vid, rid);
343344
}
344345
}
345346
else if (objectType == SAI_OBJECT_TYPE_PRIORITY_GROUP)
346347
{
347-
if (shouldSkipCreateion(vid, rid, createObject, isDefaultPriorityGroupId))
348+
if (shouldSkipCreateion(vid, rid, createObject, [&](sai_object_id_t pgId) { return g_defaultPriorityGroupsRids.find(pgId) != g_defaultPriorityGroupsRids.end(); }))
348349
{
349350
SWSS_LOG_DEBUG("default priority group will not be created, processed VID %llx to RID %llx", vid, rid);
350351
}
351352
}
352353
else if (objectType == SAI_OBJECT_TYPE_TRAP_GROUP)
353354
{
354-
if (shouldSkipCreateion(vid, rid, createObject, isDefaultTrapGroupId))
355+
if (shouldSkipCreateion(vid, rid, createObject, [](sai_object_id_t id) { return id == redisGetDefaultTrapGroupId(); }))
355356
{
356357
SWSS_LOG_INFO("default trap group will not be created, processed VID %llx to RID %llx", vid, rid);
357358
}
358359
}
359360
else if (objectType == SAI_OBJECT_TYPE_PORT)
360361
{
361-
if (shouldSkipCreateion(vid, rid, createObject, isDefaultPortId))
362+
if (shouldSkipCreateion(vid, rid, createObject, [](sai_object_id_t) { return true; }))
362363
{
363364
SWSS_LOG_INFO("port will not be created, processed VID %llx to RID %llx", vid, rid);
364365
}

syncd/syncd_reinit.cpp

-31
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,6 @@ std::vector<sai_object_id_t> saiGetPortQueues(sai_object_id_t portId)
675675
// later we need to have this in redis with port mapping
676676
std::set<sai_object_id_t> g_defaultQueuesRids;
677677

678-
bool isDefaultQueueId(sai_object_id_t queueId)
679-
{
680-
return g_defaultQueuesRids.find(queueId) != g_defaultQueuesRids.end();
681-
}
682-
683678
void helperCheckQueuesIds()
684679
{
685680
SWSS_LOG_ENTER();
@@ -765,11 +760,6 @@ std::vector<sai_object_id_t> saiGetPortPriorityGroups(sai_object_id_t portId)
765760
// later we need to have this in redis with port mapping
766761
std::set<sai_object_id_t> g_defaultPriorityGroupsRids;
767762

768-
bool isDefaultPriorityGroupId(sai_object_id_t pgId)
769-
{
770-
return g_defaultPriorityGroupsRids.find(pgId) != g_defaultPriorityGroupsRids.end();
771-
}
772-
773763
void helperCheckPriorityGroupsIds()
774764
{
775765
SWSS_LOG_ENTER();
@@ -795,27 +785,6 @@ void helperCheckPriorityGroupsIds()
795785
}
796786
}
797787

798-
bool isDefaultVirtualRouterId(sai_object_id_t id)
799-
{
800-
sai_object_id_t defaultVirtualRouterId = redisGetDefaultVirtualRouterId();
801-
802-
return id == defaultVirtualRouterId;
803-
}
804-
805-
bool isDefaultTrapGroupId(sai_object_id_t id)
806-
{
807-
sai_object_id_t defaultTrapGroupId = redisGetDefaultTrapGroupId();
808-
809-
return id == defaultTrapGroupId;
810-
}
811-
812-
bool isDefaultPortId(sai_object_id_t id)
813-
{
814-
// currenty all ports are considered default
815-
816-
return true;
817-
}
818-
819788
void onSyncdStart(bool warmStart)
820789
{
821790
// it may happen that after initialize we will receive

0 commit comments

Comments
 (0)