directly use SemaphoreHandle_t as pointer (finalize merge)

This commit is contained in:
andreas 2024-11-24 16:27:13 +01:00
parent bfa38fe2e4
commit bada311f83
1 changed files with 13 additions and 14 deletions

View File

@ -113,7 +113,7 @@ class TaskInterfacesStorage{
lock=xSemaphoreCreateMutex(); lock=xSemaphoreCreateMutex();
} }
bool set(const String &file, const String &name, const String &task,GwApi::TaskInterfaces::Ptr v){ bool set(const String &file, const String &name, const String &task,GwApi::TaskInterfaces::Ptr v){
GWSYNCHRONIZED(&lock); GWSYNCHRONIZED(lock);
auto it=registrations().find(name); auto it=registrations().find(name);
if (it == registrations().end()){ if (it == registrations().end()){
LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s not known",name.c_str()); LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s not known",name.c_str());
@ -141,7 +141,7 @@ class TaskInterfacesStorage{
return true; return true;
} }
GwApi::TaskInterfaces::Ptr get(const String &name, int &result){ GwApi::TaskInterfaces::Ptr get(const String &name, int &result){
GWSYNCHRONIZED(&lock); GWSYNCHRONIZED(lock);
auto it = values.find(name); auto it = values.find(name);
if (it == values.end()) if (it == values.end())
{ {
@ -188,7 +188,7 @@ class TaskApi : public GwApiInternal
{ {
GwApiInternal *api=nullptr; GwApiInternal *api=nullptr;
int sourceId; int sourceId;
SemaphoreHandle_t *mainLock; SemaphoreHandle_t mainLock;
SemaphoreHandle_t localLock; SemaphoreHandle_t localLock;
std::map<int,GwCounter<String>> counter; std::map<int,GwCounter<String>> counter;
std::map<String,GwApi::HandlerFunction> webHandlers; std::map<String,GwApi::HandlerFunction> webHandlers;
@ -200,7 +200,7 @@ class TaskApi : public GwApiInternal
public: public:
TaskApi(GwApiInternal *api, TaskApi(GwApiInternal *api,
int sourceId, int sourceId,
SemaphoreHandle_t *mainLock, SemaphoreHandle_t mainLock,
const String &name, const String &name,
TaskInterfacesStorage *s, TaskInterfacesStorage *s,
bool init=false) bool init=false)
@ -264,14 +264,14 @@ public:
vSemaphoreDelete(localLock); vSemaphoreDelete(localLock);
}; };
virtual void fillStatus(GwJsonDocument &status){ virtual void fillStatus(GwJsonDocument &status){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
if (! counterUsed) return; if (! counterUsed) return;
for (auto it=counter.begin();it != counter.end();it++){ for (auto it=counter.begin();it != counter.end();it++){
it->second.toJson(status); it->second.toJson(status);
} }
}; };
virtual int getJsonSize(){ virtual int getJsonSize(){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
if (! counterUsed) return 0; if (! counterUsed) return 0;
int rt=0; int rt=0;
for (auto it=counter.begin();it != counter.end();it++){ for (auto it=counter.begin();it != counter.end();it++){
@ -280,7 +280,7 @@ public:
return rt; return rt;
}; };
virtual void increment(int idx,const String &name,bool failed=false){ virtual void increment(int idx,const String &name,bool failed=false){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
counterUsed=true; counterUsed=true;
auto it=counter.find(idx); auto it=counter.find(idx);
if (it == counter.end()) return; if (it == counter.end()) return;
@ -288,18 +288,18 @@ public:
else (it->second.add(name)); else (it->second.add(name));
}; };
virtual void reset(int idx){ virtual void reset(int idx){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
counterUsed=true; counterUsed=true;
auto it=counter.find(idx); auto it=counter.find(idx);
if (it == counter.end()) return; if (it == counter.end()) return;
it->second.reset(); it->second.reset();
}; };
virtual void remove(int idx){ virtual void remove(int idx){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
counter.erase(idx); counter.erase(idx);
} }
virtual int addCounter(const String &name){ virtual int addCounter(const String &name){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
counterUsed=true; counterUsed=true;
counterIdx++; counterIdx++;
//avoid the need for an empty counter constructor //avoid the need for an empty counter constructor
@ -317,7 +317,7 @@ public:
return api->addXdrMapping(def); return api->addXdrMapping(def);
} }
virtual void registerRequestHandler(const String &url,HandlerFunction handler){ virtual void registerRequestHandler(const String &url,HandlerFunction handler){
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
webHandlers[url]=handler; webHandlers[url]=handler;
} }
virtual void addCapability(const String &name, const String &value){ virtual void addCapability(const String &name, const String &value){
@ -344,7 +344,7 @@ public:
{ {
GwApi::HandlerFunction handler; GwApi::HandlerFunction handler;
{ {
GWSYNCHRONIZED(&localLock); GWSYNCHRONIZED(localLock);
auto it = webHandlers.find(url); auto it = webHandlers.find(url);
if (it == webHandlers.end()) if (it == webHandlers.end())
{ {
@ -359,10 +359,9 @@ public:
} }
}; };
GwUserCode::GwUserCode(GwApiInternal *api,SemaphoreHandle_t *mainLock){ GwUserCode::GwUserCode(GwApiInternal *api){
this->logger=api->getLogger(); this->logger=api->getLogger();
this->api=api; this->api=api;
this->mainLock=mainLock;
this->taskData=new TaskInterfacesStorage(this->logger); this->taskData=new TaskInterfacesStorage(this->logger);
} }
GwUserCode::~GwUserCode(){ GwUserCode::~GwUserCode(){