Skip to content

Commit

Permalink
Move apiInitialized flag to Globals namespace (sonic-net#545)
Browse files Browse the repository at this point in the history
* Move api mutex to global class and add sairedis namespace

* Move apiInitialized flag to Globals namespace

* Fix spelling
  • Loading branch information
kcudnik authored Dec 9, 2019
1 parent 33ac34e commit 358e77e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/inc/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ namespace sairedis
* a global API mutex is declared.
*/
static std::mutex apimutex;

/**
* @brief Indicates whether SAI interface API is initialized.
*/
static bool apiInitialized;
};
}
2 changes: 2 additions & 0 deletions lib/src/Globals.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "Globals.h"

std::mutex sairedis::Globals::apimutex;

bool sairedis::Globals::apiInitialized = false;
13 changes: 7 additions & 6 deletions lib/src/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "swss/selectableevent.h"
#include <string.h>

using namespace sairedis;

sai_service_method_table_t g_services;
bool g_apiInitialized = false;
volatile bool g_run = false;

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

SWSS_LOG_ENTER();

if (g_apiInitialized)
if (Globals::apiInitialized)
{
SWSS_LOG_ERROR("api already initialized");

Expand Down Expand Up @@ -140,7 +141,7 @@ sai_status_t sai_api_initialize(

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

g_apiInitialized = true;
Globals::apiInitialized = true;

return SAI_STATUS_SUCCESS;
}
Expand All @@ -151,7 +152,7 @@ sai_status_t sai_api_uninitialize(void)

SWSS_LOG_ENTER();

if (!g_apiInitialized)
if (!Globals::apiInitialized)
{
SWSS_LOG_ERROR("api not initialized");

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

notification_thread->join();

g_apiInitialized = false;
Globals::apiInitialized = false;

return SAI_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -205,7 +206,7 @@ sai_status_t sai_api_query(
return SAI_STATUS_INVALID_PARAMETER;
}

if (!g_apiInitialized)
if (!Globals::apiInitialized)
{
SWSS_LOG_ERROR("SAI API not initialized before calling API query");
return SAI_STATUS_UNINITIALIZED;
Expand Down

0 comments on commit 358e77e

Please sign in to comment.