Browse Source

feat(multithreading): Protecting incoming service requests (send from a client) with locks

Ubuntu 5 years ago
parent
commit
7345ab0778

+ 2 - 0
src/server/ua_server_binary.c

@@ -539,7 +539,9 @@ processMSGDecoded(UA_Server *server, UA_SecureChannel *channel, UA_UInt32 reques
 #endif
 
     /* Dispatch the synchronous service call and send the response */
+    UA_LOCK(server->serviceMutex);
     service(server, session, requestHeader, responseHeader);
+    UA_UNLOCK(server->serviceMutex);
     return sendResponse(channel, requestId, requestHeader->requestHandle,
                         responseHeader, responseType);
 }

+ 11 - 11
src/server/ua_services.h

@@ -183,7 +183,7 @@ void Service_CloseSession(UA_Server *server, UA_Session *session,
  * AddNodes Service
  * ^^^^^^^^^^^^^^^^
  * Used to add one or more Nodes into the AddressSpace hierarchy. */
-UA_THREADSAFE void Service_AddNodes(UA_Server *server, UA_Session *session,
+void Service_AddNodes(UA_Server *server, UA_Session *session,
                       const UA_AddNodesRequest *request,
                       UA_AddNodesResponse *response);
 
@@ -191,7 +191,7 @@ UA_THREADSAFE void Service_AddNodes(UA_Server *server, UA_Session *session,
  * AddReferences Service
  * ^^^^^^^^^^^^^^^^^^^^^
  * Used to add one or more References to one or more Nodes. */
-UA_THREADSAFE void Service_AddReferences(UA_Server *server, UA_Session *session,
+void Service_AddReferences(UA_Server *server, UA_Session *session,
                            const UA_AddReferencesRequest *request,
                            UA_AddReferencesResponse *response);
 
@@ -199,7 +199,7 @@ UA_THREADSAFE void Service_AddReferences(UA_Server *server, UA_Session *session,
  * DeleteNodes Service
  * ^^^^^^^^^^^^^^^^^^^
  * Used to delete one or more Nodes from the AddressSpace. */
-UA_THREADSAFE void Service_DeleteNodes(UA_Server *server, UA_Session *session,
+void Service_DeleteNodes(UA_Server *server, UA_Session *session,
                          const UA_DeleteNodesRequest *request,
                          UA_DeleteNodesResponse *response);
 
@@ -207,7 +207,7 @@ UA_THREADSAFE void Service_DeleteNodes(UA_Server *server, UA_Session *session,
  * DeleteReferences
  * ^^^^^^^^^^^^^^^^
  * Used to delete one or more References of a Node. */
-UA_THREADSAFE void Service_DeleteReferences(UA_Server *server, UA_Session *session,
+void Service_DeleteReferences(UA_Server *server, UA_Session *session,
                               const UA_DeleteReferencesRequest *request,
                               UA_DeleteReferencesResponse *response);
 
@@ -302,8 +302,8 @@ void Service_UnregisterNodes(UA_Server *server, UA_Session *session,
  * elements are indexed, such as an array, this Service allows Clients to read
  * the entire set of indexed values as a composite, to read individual elements
  * or to read ranges of elements of the composite. */
-UA_THREADSAFE void Service_Read(UA_Server *server, UA_Session *session,
-                                const UA_ReadRequest *request, UA_ReadResponse *response);
+void Service_Read(UA_Server *server, UA_Session *session,
+                  const UA_ReadRequest *request, UA_ReadResponse *response);
 
 /**
  * Write Service
@@ -312,8 +312,8 @@ UA_THREADSAFE void Service_Read(UA_Server *server, UA_Session *session,
  * elements are indexed, such as an array, this Service allows Clients to write
  * the entire set of indexed values as a composite, to write individual elements
  * or to write ranges of elements of the composite. */
-UA_THREADSAFE void Service_Write(UA_Server *server, UA_Session *session,
-                                 const UA_WriteRequest *request, UA_WriteResponse *response);
+void Service_Write(UA_Server *server, UA_Session *session,
+                   const UA_WriteRequest *request, UA_WriteResponse *response);
 
 /**
  * HistoryRead Service
@@ -353,9 +353,9 @@ Service_HistoryUpdate(UA_Server *server, UA_Session *session,
  * context of an existing Session. If the Session is terminated, the results of
  * the method's execution cannot be returned to the Client and are discarded. */
 #ifdef UA_ENABLE_METHODCALLS
-UA_THREADSAFE void Service_Call(UA_Server *server, UA_Session *session,
-                                const UA_CallRequest *request,
-                                UA_CallResponse *response);
+void Service_Call(UA_Server *server, UA_Session *session,
+                  const UA_CallRequest *request,
+                  UA_CallResponse *response);
 #endif
 
 #ifdef UA_ENABLE_SUBSCRIPTIONS

+ 2 - 4
src/server/ua_services_attribute.c

@@ -504,13 +504,12 @@ Service_Read(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex);
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session, (UA_ServiceOperation)Operation_Read,
                                            request,
                                            &request->nodesToReadSize, &UA_TYPES[UA_TYPES_READVALUEID],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_DATAVALUE]);
-    UA_UNLOCK(server->serviceMutex);
 }
 
 UA_DataValue
@@ -1454,12 +1453,11 @@ Service_Write(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex)
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session, (UA_ServiceOperation)Operation_Write, NULL,
                                            &request->nodesToWriteSize, &UA_TYPES[UA_TYPES_WRITEVALUE],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
-    UA_UNLOCK(server->serviceMutex);
 }
 
 UA_StatusCode

+ 1 - 2
src/server/ua_services_method.c

@@ -269,12 +269,11 @@ void Service_Call(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex);
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session, (UA_ServiceOperation)Operation_CallMethod, NULL,
                                            &request->methodsToCallSize, &UA_TYPES[UA_TYPES_CALLMETHODREQUEST],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_CALLMETHODRESULT]);
-    UA_UNLOCK(server->serviceMutex);
 }
 
 UA_CallMethodResult UA_EXPORT

+ 4 - 8
src/server/ua_services_nodemanagement.c

@@ -1285,13 +1285,12 @@ Service_AddNodes(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex);
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session,
                                            (UA_ServiceOperation)Operation_addNode, NULL,
                                            &request->nodesToAddSize, &UA_TYPES[UA_TYPES_ADDNODESITEM],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_ADDNODESRESULT]);
-    UA_UNLOCK(server->serviceMutex)
 }
 
 UA_StatusCode
@@ -1623,14 +1622,13 @@ void Service_DeleteNodes(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex);
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session,
                                            (UA_ServiceOperation)deleteNodeOperation,
                                            NULL, &request->nodesToDeleteSize,
                                            &UA_TYPES[UA_TYPES_DELETENODESITEM],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
-    UA_UNLOCK(server->serviceMutex);
 }
 
 UA_StatusCode
@@ -1748,14 +1746,13 @@ void Service_AddReferences(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex);
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session,
                                            (UA_ServiceOperation)Operation_addReference,
                                            NULL, &request->referencesToAddSize,
                                            &UA_TYPES[UA_TYPES_ADDREFERENCESITEM],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
-    UA_UNLOCK(server->serviceMutex);
 }
 
 UA_StatusCode
@@ -1831,14 +1828,13 @@ Service_DeleteReferences(UA_Server *server, UA_Session *session,
         response->responseHeader.serviceResult = UA_STATUSCODE_BADTOOMANYOPERATIONS;
         return;
     }
-    UA_LOCK(server->serviceMutex);
+
     response->responseHeader.serviceResult =
         UA_Server_processServiceOperations(server, session,
                                            (UA_ServiceOperation)Operation_deleteReference,
                                            NULL, &request->referencesToDeleteSize,
                                            &UA_TYPES[UA_TYPES_DELETEREFERENCESITEM],
                                            &response->resultsSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
-    UA_UNLOCK(server->serviceMutex);
 }
 
 UA_StatusCode