Skip to content

Commit

Permalink
feat(multithreading): Adding new macro for assertions and rename UA_L…
Browse files Browse the repository at this point in the history
…OCK_RELEASE to UA_LOCK_DESTROY
  • Loading branch information
ckmk14 authored and jpfr committed Aug 27, 2019
1 parent 7345ab0 commit 30c8b7d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions arch/eCos/ua_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ int gethostname_ecos(char* name, size_t len);
#define UA_LOCK_TYPE(mutexName)
#define UA_LOCK_TYPE_POINTER(mutexName)
#define UA_LOCK_INIT(mutexName)
#define UA_LOCK_RELEASE(mutexName)
#define UA_LOCK_DESTROY(mutexName)
#define UA_LOCK(mutexName)
#define UA_UNLOCK(mutexName)
#define UA_LOCK_SWITCH(currentMutex, newMutex)
#define UA_LOCK_ASSERT(mutexName, num)
#endif

#include <open62541/architecture_functions.h>
Expand Down
4 changes: 2 additions & 2 deletions arch/freertosLWIP/ua_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#define UA_LOCK_TYPE(mutexName)
#define UA_LOCK_TYPE_POINTER(mutexName)
#define UA_LOCK_INIT(mutexName)
#define UA_LOCK_RELEASE(mutexName)
#define UA_LOCK_DESTROY(mutexName)
#define UA_LOCK(mutexName)
#define UA_UNLOCK(mutexName)
#define UA_LOCK_SWITCH(currentMutex, newMutex)
#define UA_LOCK_ASSERT(mutexName, num)
#endif

#include <open62541/architecture_functions.h>
Expand Down
9 changes: 4 additions & 5 deletions arch/posix/ua_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,23 @@ extern void * (*UA_globalRealloc)(void *ptr, size_t size);
pthread_mutexattr_settype(&mutexName##_attr, PTHREAD_MUTEX_RECURSIVE); \
pthread_mutex_init(&mutexName, &mutexName##_attr); \
mutexName##Counter = 0;
#define UA_LOCK_RELEASE(mutexName) pthread_mutex_destroy(&mutexName); \
#define UA_LOCK_DESTROY(mutexName) pthread_mutex_destroy(&mutexName); \
pthread_mutexattr_destroy(&mutexName##_attr);

#define UA_LOCK(mutexName) pthread_mutex_lock(&mutexName); \
UA_assert(++(mutexName##Counter) == 1); \

#define UA_UNLOCK(mutexName) UA_assert(--(mutexName##Counter) == 0); \
pthread_mutex_unlock(&mutexName);
#define UA_LOCK_SWITCH(currentMutex, newMutex) UA_UNLOCK(currentMutex) \
UA_LOCK(newMutex)
#define UA_LOCK_ASSERT(mutexName, num) UA_assert(mutexName##Counter == num);
#else
#define UA_LOCK_TYPE_NAME
#define UA_LOCK_TYPE(mutexName)
#define UA_LOCK_INIT(mutexName)
#define UA_LOCK_RELEASE(mutexName)
#define UA_LOCK_DESTROY(mutexName)
#define UA_LOCK(mutexName)
#define UA_UNLOCK(mutexName)
#define UA_LOCK_SWITCH(currentMutex, newMutex)
#define UA_LOCK_ASSERT(mutexName, num)
#endif

#include <open62541/architecture_functions.h>
Expand Down
4 changes: 2 additions & 2 deletions arch/vxworks/ua_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@
#define UA_LOCK_TYPE(mutexName)
#define UA_LOCK_TYPE_POINTER(mutexName)
#define UA_LOCK_INIT(mutexName)
#define UA_LOCK_RELEASE(mutexName)
#define UA_LOCK_DESTROY(mutexName)
#define UA_LOCK(mutexName)
#define UA_UNLOCK(mutexName)
#define UA_LOCK_SWITCH(currentMutex, newMutex)
#define UA_LOCK_ASSERT(mutexName, num)
#endif

#include <open62541/architecture_functions.h>
Expand Down
3 changes: 1 addition & 2 deletions arch/wec7/ua_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ char *strerror(int errnum);
#define UA_LOCK_TYPE(mutexName)
#define UA_LOCK_TYPE_POINTER(mutexName)
#define UA_LOCK_INIT(mutexName)
#define UA_LOCK_RELEASE(mutexName)
#define UA_LOCK_DESTROY(mutexName)
#define UA_LOCK(mutexName)
#define UA_UNLOCK(mutexName)
#define UA_LOCK_SWITCH(currentMutex, newMutex)
#endif

#include <open62541/architecture_functions.h>
Expand Down
9 changes: 4 additions & 5 deletions arch/win32/ua_architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,21 @@
int mutexName##Counter;
#define UA_LOCK_INIT(mutexName) InitializeCriticalSection(&mutexName); \
mutexName##Counter = 0;;
#define UA_LOCK_RELEASE(mutexName) DeleteCriticalSection(&mutexName);
#define UA_LOCK_DESTROY(mutexName) DeleteCriticalSection(&mutexName);
#define UA_LOCK(mutexName) EnterCriticalSection(&mutexName); \
UA_assert(++(mutexName##Counter) == 1);
#define UA_UNLOCK(mutexName) UA_assert(--(mutexName##Counter) == 0); \
LeaveCriticalSection(&mutexName);
#define UA_LOCK_SWITCH(currentMutex, newMutex) UA_UNLOCK(currentMutex) \
UA_LOCK(newMutex)
#define UA_LOCK_ASSERT(mutexName, num) UA_assert(mutexName##Counter == num);
#else
#define UA_LOCK_TYPE_NAME
#define UA_LOCK_TYPE(mutexName)
#define UA_LOCK_TYPE_POINTER(mutexName)
#define UA_LOCK_INIT(mutexName)
#define UA_LOCK_RELEASE(mutexName)
#define UA_LOCK_DESTROY(mutexName)
#define UA_LOCK(mutexName)
#define UA_UNLOCK(mutexName)
#define UA_LOCK_SWITCH(currentMutex, newMutex)
#define UA_LOCK_ASSERT(mutexName, num)
#endif

#include <open62541/architecture_functions.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/ua_nodestore_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ UA_Nodestore_delete(void *nsCtx) {

NodeMap *ns = (NodeMap*)nsCtx;
#if UA_MULTITHREADING >= 100
UA_LOCK_RELEASE(ns->lock);
UA_LOCK_DESTROY(ns->lock);
#endif
ZIP_ITER(NodeTree, &ns->root, deleteNodeVisitor, NULL);
UA_free(ns);
Expand Down
4 changes: 2 additions & 2 deletions src/server/ua_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ void UA_Server_delete(UA_Server *server) {
#endif

#if UA_MULTITHREADING >= 100
UA_LOCK_RELEASE(server->networkMutex)
UA_LOCK_RELEASE(server->serviceMutex)
UA_LOCK_DESTROY(server->networkMutex)
UA_LOCK_DESTROY(server->serviceMutex)
#endif

/* Clean up the Admin Session */
Expand Down

0 comments on commit 30c8b7d

Please sign in to comment.