Skip to content

Commit

Permalink
directly use SemaphoreHandle_t as pointer (finalize merge)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Nov 24, 2024
1 parent bfa38fe commit bada311
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/usercode/GwUserCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TaskInterfacesStorage{
lock=xSemaphoreCreateMutex();
}
bool set(const String &file, const String &name, const String &task,GwApi::TaskInterfaces::Ptr v){
GWSYNCHRONIZED(&lock);
GWSYNCHRONIZED(lock);
auto it=registrations().find(name);
if (it == registrations().end()){
LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s not known",name.c_str());
Expand Down Expand Up @@ -141,7 +141,7 @@ class TaskInterfacesStorage{
return true;
}
GwApi::TaskInterfaces::Ptr get(const String &name, int &result){
GWSYNCHRONIZED(&lock);
GWSYNCHRONIZED(lock);
auto it = values.find(name);
if (it == values.end())
{
Expand Down Expand Up @@ -188,7 +188,7 @@ class TaskApi : public GwApiInternal
{
GwApiInternal *api=nullptr;
int sourceId;
SemaphoreHandle_t *mainLock;
SemaphoreHandle_t mainLock;
SemaphoreHandle_t localLock;
std::map<int,GwCounter<String>> counter;
std::map<String,GwApi::HandlerFunction> webHandlers;
Expand All @@ -200,7 +200,7 @@ class TaskApi : public GwApiInternal
public:
TaskApi(GwApiInternal *api,
int sourceId,
SemaphoreHandle_t *mainLock,
SemaphoreHandle_t mainLock,
const String &name,
TaskInterfacesStorage *s,
bool init=false)
Expand Down Expand Up @@ -264,14 +264,14 @@ class TaskApi : public GwApiInternal
vSemaphoreDelete(localLock);
};
virtual void fillStatus(GwJsonDocument &status){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
if (! counterUsed) return;
for (auto it=counter.begin();it != counter.end();it++){
it->second.toJson(status);
}
};
virtual int getJsonSize(){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
if (! counterUsed) return 0;
int rt=0;
for (auto it=counter.begin();it != counter.end();it++){
Expand All @@ -280,26 +280,26 @@ class TaskApi : public GwApiInternal
return rt;
};
virtual void increment(int idx,const String &name,bool failed=false){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
counterUsed=true;
auto it=counter.find(idx);
if (it == counter.end()) return;
if (failed) it->second.addFail(name);
else (it->second.add(name));
};
virtual void reset(int idx){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
counterUsed=true;
auto it=counter.find(idx);
if (it == counter.end()) return;
it->second.reset();
};
virtual void remove(int idx){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
counter.erase(idx);
}
virtual int addCounter(const String &name){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
counterUsed=true;
counterIdx++;
//avoid the need for an empty counter constructor
Expand All @@ -317,7 +317,7 @@ class TaskApi : public GwApiInternal
return api->addXdrMapping(def);
}
virtual void registerRequestHandler(const String &url,HandlerFunction handler){
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
webHandlers[url]=handler;
}
virtual void addCapability(const String &name, const String &value){
Expand All @@ -344,7 +344,7 @@ class TaskApi : public GwApiInternal
{
GwApi::HandlerFunction handler;
{
GWSYNCHRONIZED(&localLock);
GWSYNCHRONIZED(localLock);
auto it = webHandlers.find(url);
if (it == webHandlers.end())
{
Expand All @@ -359,10 +359,9 @@ class TaskApi : public GwApiInternal
}
};

GwUserCode::GwUserCode(GwApiInternal *api,SemaphoreHandle_t *mainLock){
GwUserCode::GwUserCode(GwApiInternal *api){
this->logger=api->getLogger();
this->api=api;
this->mainLock=mainLock;
this->taskData=new TaskInterfacesStorage(this->logger);
}
GwUserCode::~GwUserCode(){
Expand Down

0 comments on commit bada311

Please sign in to comment.