- MMS server: added semaphore for open connections map to prevent problem in multi-threaded mode

pull/147/head
Michael Zillgith 7 years ago
parent d24f0c44c5
commit 4ae7a268de

@ -1,7 +1,7 @@
/* /*
* mms_mapping.c * mms_mapping.c
* *
* Copyright 2013-2018 Michael Zillgith * Copyright 2013-2019 Michael Zillgith
* *
* This file is part of libIEC61850. * This file is part of libIEC61850.
* *

@ -119,6 +119,10 @@ struct sMmsServer {
MmsNamedVariableListChangedHandler variableListChangedHandler; //TODO this is only required if dynamic data sets are supported! MmsNamedVariableListChangedHandler variableListChangedHandler; //TODO this is only required if dynamic data sets are supported!
void* variableListChangedHandlerParameter; void* variableListChangedHandlerParameter;
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore openConnectionsLock;
#endif
Map openConnections; Map openConnections;
Map valueCaches; Map valueCaches;
bool isLocked; bool isLocked;

@ -61,6 +61,8 @@ MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration)
self->transmitBuffer = ByteBuffer_create(NULL, CONFIG_MMS_MAXIMUM_PDU_SIZE); self->transmitBuffer = ByteBuffer_create(NULL, CONFIG_MMS_MAXIMUM_PDU_SIZE);
#if (CONFIG_MMS_THREADLESS_STACK != 1) #if (CONFIG_MMS_THREADLESS_STACK != 1)
self->openConnectionsLock = Semaphore_create(1);
self->modelMutex = Semaphore_create(1); self->modelMutex = Semaphore_create(1);
self->transmitBufferMutex = Semaphore_create(1); self->transmitBufferMutex = Semaphore_create(1);
@ -299,6 +301,8 @@ MmsServer_destroy(MmsServer self)
Map_deleteDeep(self->valueCaches, false, (void (*) (void*)) deleteSingleCache); Map_deleteDeep(self->valueCaches, false, (void (*) (void*)) deleteSingleCache);
#if (CONFIG_MMS_THREADLESS_STACK != 1) #if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_destroy(self->openConnectionsLock);
Semaphore_destroy(self->modelMutex); Semaphore_destroy(self->modelMutex);
Semaphore_destroy(self->transmitBufferMutex); Semaphore_destroy(self->transmitBufferMutex);
#endif #endif
@ -401,23 +405,41 @@ static void /* will be called by ISO server stack */
isoConnectionIndicationHandler(IsoConnectionIndication indication, isoConnectionIndicationHandler(IsoConnectionIndication indication,
void* parameter, IsoConnection connection) void* parameter, IsoConnection connection)
{ {
MmsServer mmsServer = (MmsServer) parameter; MmsServer self = (MmsServer) parameter;
if (indication == ISO_CONNECTION_OPENED) { if (indication == ISO_CONNECTION_OPENED) {
MmsServerConnection mmsCon = MmsServerConnection_init(0, mmsServer, connection); MmsServerConnection mmsCon = MmsServerConnection_init(0, self, connection);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_wait(self->openConnectionsLock);
#endif
Map_addEntry(mmsServer->openConnections, connection, mmsCon); Map_addEntry(self->openConnections, connection, mmsCon);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_post(self->openConnectionsLock);
#endif
if (mmsServer->connectionHandler != NULL) if (self->connectionHandler != NULL)
mmsServer->connectionHandler(mmsServer->connectionHandlerParameter, self->connectionHandler(self->connectionHandlerParameter,
mmsCon, MMS_SERVER_NEW_CONNECTION); mmsCon, MMS_SERVER_NEW_CONNECTION);
} }
else if (indication == ISO_CONNECTION_CLOSED) { else if (indication == ISO_CONNECTION_CLOSED) {
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_wait(self->openConnectionsLock);
#endif
MmsServerConnection mmsCon = (MmsServerConnection) MmsServerConnection mmsCon = (MmsServerConnection)
Map_removeEntry(mmsServer->openConnections, connection, false); Map_removeEntry(self->openConnections, connection, false);
#if (CONFIG_MMS_THREADLESS_STACK != 1)
Semaphore_post(self->openConnectionsLock);
#endif
if (mmsServer->connectionHandler != NULL) if (self->connectionHandler != NULL)
mmsServer->connectionHandler(mmsServer->connectionHandlerParameter, self->connectionHandler(self->connectionHandlerParameter,
mmsCon, MMS_SERVER_CONNECTION_CLOSED); mmsCon, MMS_SERVER_CONNECTION_CLOSED);
if (mmsCon != NULL) if (mmsCon != NULL)

Loading…
Cancel
Save