Skip to content

Commit

Permalink
directly use SemaphoreHandle_t as pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Nov 24, 2024
1 parent 54ccb5d commit bfa38fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/exampletask/GwExampleTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ class ExampleWebData{
vSemaphoreDelete(lock);
}
void set(int v){
GWSYNCHRONIZED(&lock);
GWSYNCHRONIZED(lock);
data=v;
}
int get(){
GWSYNCHRONIZED(&lock);
GWSYNCHRONIZED(lock);
return data;
}
};
Expand Down
6 changes: 3 additions & 3 deletions lib/socketserver/GwTcpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void GwTcpClient::resolveHost(String host)
{
LOG_DEBUG(GwLog::LOG,"start resolving %s",host.c_str());
{
GWSYNCHRONIZED(&locker);
GWSYNCHRONIZED(locker);
resolvedAddress.resolved = false;
}
state = C_RESOLVING;
Expand Down Expand Up @@ -283,12 +283,12 @@ void GwTcpClient::resolveHost(String host)
void GwTcpClient::setResolved(IPAddress addr, bool valid){
LOG_DEBUG(GwLog::LOG,"setResolved %s, valid=%s",
addr.toString().c_str(),(valid?"true":"false"));
GWSYNCHRONIZED(&locker);
GWSYNCHRONIZED(locker);
resolvedAddress.address=addr;
resolvedAddress.resolved=valid;
state=C_RESOLVED;
}
GwTcpClient::ResolvedAddress GwTcpClient::getResolved(){
GWSYNCHRONIZED(&locker);
GWSYNCHRONIZED(locker);
return resolvedAddress;
}
5 changes: 3 additions & 2 deletions lib/usercode/GwUserCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ class TaskInterfacesStorage;
class GwUserCode{
GwLog *logger;
GwApiInternal *api;
SemaphoreHandle_t *mainLock;
SemaphoreHandle_t mainLock=nullptr;
TaskInterfacesStorage *taskData;
void startAddOnTask(GwApiInternal *api,GwUserTask *task,int sourceId,String name);
public:
~GwUserCode();
typedef std::map<String,String> Capabilities;
GwUserCode(GwApiInternal *api, SemaphoreHandle_t *mainLock);
GwUserCode(GwApiInternal *api);
void begin(SemaphoreHandle_t mainLock){this->mainLock=mainLock;}
void startUserTasks(int baseId);
void startInitTasks(int baseId);
void startAddonTask(String name,TaskFunction_t task, int id);
Expand Down
13 changes: 7 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,17 @@ void SendNMEA0183Message(const tNMEA0183Msg &NMEA0183Msg, int sourceId,bool conv
class CalibrationValues {
using Map=std::map<String,double>;
Map values;
SemaphoreHandle_t lock;
SemaphoreHandle_t lock=nullptr;
public:
CalibrationValues(){
lock=xSemaphoreCreateMutex();
}
void set(const String &name,double value){
GWSYNCHRONIZED(&lock);
GWSYNCHRONIZED(lock);
values[name]=value;
}
bool get(const String &name, double &value){
GWSYNCHRONIZED(&lock);
GWSYNCHRONIZED(lock);
auto it=values.find(name);
if (it==values.end()) return false;
value=it->second;
Expand Down Expand Up @@ -373,7 +373,7 @@ bool delayedRestart(){
},"reset",2000,&logger,0,NULL) == pdPASS;
}
ApiImpl *apiImpl=new ApiImpl(MIN_USER_TASK);
GwUserCode userCodeHandler(apiImpl,&mainLock);
GwUserCode userCodeHandler(apiImpl);

#define JSON_OK "{\"status\":\"OK\"}"
#define JSON_INVALID_PASS F("{\"status\":\"invalid password\"}")
Expand Down Expand Up @@ -788,6 +788,7 @@ void setup() {
logger.setWriter(new DefaultLogWriter());
#endif
boatData.begin();
userCodeHandler.begin(mainLock);
userCodeHandler.startInitTasks(MIN_USER_TASK);
channels.preinit();
config.stopChanges();
Expand Down Expand Up @@ -937,7 +938,7 @@ void setup() {
logger.logDebug(GwLog::LOG,"starting addon tasks");
logger.flush();
{
GWSYNCHRONIZED(&mainLock);
GWSYNCHRONIZED(mainLock);
userCodeHandler.startUserTasks(MIN_USER_TASK);
}
timers.addAction(HEAP_REPORT_TIME,[](){
Expand Down Expand Up @@ -967,7 +968,7 @@ void handleSendAndRead(bool handleRead){
void loopRun() {
//logger.logDebug(GwLog::DEBUG,"main loop start");
monitor.reset();
GWSYNCHRONIZED(&mainLock);
GWSYNCHRONIZED(mainLock);
logger.flush();
monitor.setTime(1);
gwWifi.loop();
Expand Down

0 comments on commit bfa38fe

Please sign in to comment.