Skip to content

Commit 358e77e

Browse files
authored
Move apiInitialized flag to Globals namespace (sonic-net#545)
* Move api mutex to global class and add sairedis namespace * Move apiInitialized flag to Globals namespace * Fix spelling
1 parent 33ac34e commit 358e77e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lib/inc/Globals.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ namespace sairedis
2626
* a global API mutex is declared.
2727
*/
2828
static std::mutex apimutex;
29+
30+
/**
31+
* @brief Indicates whether SAI interface API is initialized.
32+
*/
33+
static bool apiInitialized;
2934
};
3035
}

lib/src/Globals.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "Globals.h"
22

33
std::mutex sairedis::Globals::apimutex;
4+
5+
bool sairedis::Globals::apiInitialized = false;

lib/src/sai_redis_interfacequery.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include "swss/selectableevent.h"
99
#include <string.h>
1010

11+
using namespace sairedis;
12+
1113
sai_service_method_table_t g_services;
12-
bool g_apiInitialized = false;
1314
volatile bool g_run = false;
1415

1516
// this event is used to nice end notifications thread
@@ -102,7 +103,7 @@ sai_status_t sai_api_initialize(
102103

103104
SWSS_LOG_ENTER();
104105

105-
if (g_apiInitialized)
106+
if (Globals::apiInitialized)
106107
{
107108
SWSS_LOG_ERROR("api already initialized");
108109

@@ -140,7 +141,7 @@ sai_status_t sai_api_initialize(
140141

141142
notification_thread = std::make_shared<std::thread>(ntf_thread);
142143

143-
g_apiInitialized = true;
144+
Globals::apiInitialized = true;
144145

145146
return SAI_STATUS_SUCCESS;
146147
}
@@ -151,7 +152,7 @@ sai_status_t sai_api_uninitialize(void)
151152

152153
SWSS_LOG_ENTER();
153154

154-
if (!g_apiInitialized)
155+
if (!Globals::apiInitialized)
155156
{
156157
SWSS_LOG_ERROR("api not initialized");
157158

@@ -167,7 +168,7 @@ sai_status_t sai_api_uninitialize(void)
167168

168169
notification_thread->join();
169170

170-
g_apiInitialized = false;
171+
Globals::apiInitialized = false;
171172

172173
return SAI_STATUS_SUCCESS;
173174
}
@@ -205,7 +206,7 @@ sai_status_t sai_api_query(
205206
return SAI_STATUS_INVALID_PARAMETER;
206207
}
207208

208-
if (!g_apiInitialized)
209+
if (!Globals::apiInitialized)
209210
{
210211
SWSS_LOG_ERROR("SAI API not initialized before calling API query");
211212
return SAI_STATUS_UNINITIALIZED;

0 commit comments

Comments
 (0)