File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818#include <rmw_microxrcedds_c/config.h>
1919#include <rmw/allocators.h>
2020
21+ #include <uxr/client/profile/multithread/multithread.h>
22+
2123bool has_memory (
2224 rmw_uxrce_mempool_t * mem )
2325{
24- return mem -> freeitems != NULL ? true : false;
26+ UXR_LOCK (& mem -> mutex );
27+ bool rv = mem -> freeitems != NULL ? true : false;
28+ UXR_UNLOCK (& mem -> mutex );
29+
30+ return rv ;
2531}
2632
2733rmw_uxrce_mempool_item_t * get_memory (
2834 rmw_uxrce_mempool_t * mem )
2935{
36+ UXR_LOCK (& mem -> mutex );
37+
3038 rmw_uxrce_mempool_item_t * item = NULL ;
3139
3240 if (has_memory (mem ))
@@ -62,13 +70,18 @@ rmw_uxrce_mempool_item_t* get_memory(
6270 item = get_memory (mem );
6371#endif /* ifdef RMW_UXRCE_ALLOW_DYNAMIC_ALLOCATIONS */
6472 }
73+
74+ UXR_UNLOCK (& mem -> mutex );
75+
6576 return item ;
6677}
6778
6879void put_memory (
6980 rmw_uxrce_mempool_t * mem ,
7081 rmw_uxrce_mempool_item_t * item )
7182{
83+ UXR_LOCK (& mem -> mutex );
84+
7285 // Gets item from allocated pool
7386 if (item -> prev )
7487 {
@@ -101,4 +114,6 @@ void put_memory(
101114 }
102115 item -> prev = NULL ;
103116 mem -> freeitems = item ;
117+
118+ UXR_UNLOCK (& mem -> mutex );
104119}
Original file line number Diff line number Diff line change 1818#include <stdbool.h>
1919#include <stddef.h>
2020
21+ #include <uxr/client/profile/multithread/multithread.h>
22+
2123typedef struct rmw_uxrce_mempool_item_t
2224{
2325 bool is_dynamic_memory ;
@@ -26,14 +28,18 @@ typedef struct rmw_uxrce_mempool_item_t
2628 void * data ;
2729} rmw_uxrce_mempool_item_t ;
2830
29-
3031typedef struct rmw_uxrce_mempool_t
3132{
3233 struct rmw_uxrce_mempool_item_t * allocateditems ;
3334 struct rmw_uxrce_mempool_item_t * freeitems ;
3435
3536 bool is_initialized ;
3637 size_t element_size ;
38+
39+ #ifdef UCLIENT_PROFILE_MULTITHREAD
40+ uxrMutex mutex ;
41+ #endif // UCLIENT_PROFILE_MULTITHREAD
42+
3743} rmw_uxrce_mempool_t ;
3844
3945bool has_memory (
Original file line number Diff line number Diff line change 2020
2121#include <rmw_uros/options.h>
2222
23+ #include <uxr/client/profile/multithread/multithread.h>
24+
2325bool flush_session (
2426 uxrSession * session )
2527{
@@ -83,6 +85,8 @@ rmw_publish(
8385 custom_publisher -> cs_cb_serialization (& mb );
8486 }
8587
88+ UXR_UNLOCK_STREAM_ID (& custom_publisher -> owner_node -> context -> session , custom_publisher -> stream_id );
89+
8690 if (UXR_BEST_EFFORT_STREAM == custom_publisher -> stream_id .type )
8791 {
8892 uxr_flash_output_streams (& custom_publisher -> owner_node -> context -> session );
Original file line number Diff line number Diff line change 1717#include <rmw/rmw.h>
1818#include <rmw/error_handling.h>
1919
20+ #include <uxr/client/profile/multithread/multithread.h>
21+
2022rmw_ret_t
2123rmw_send_request (
2224 const rmw_client_t * client ,
@@ -48,6 +50,8 @@ rmw_send_request(
4850
4951 functions -> cdr_serialize (ros_request , & mb );
5052
53+ UXR_UNLOCK_STREAM_ID (& custom_node -> context -> session , custom_client -> stream_id );
54+
5155 if (UXR_INVALID_REQUEST_ID == * sequence_id )
5256 {
5357 RMW_SET_ERROR_MSG ("Micro XRCE-DDS service request error." );
Original file line number Diff line number Diff line change 1717#include <rmw/rmw.h>
1818#include <rmw/error_handling.h>
1919
20+ #include <uxr/client/profile/multithread/multithread.h>
21+
2022rmw_ret_t
2123rmw_send_response (
2224 const rmw_service_t * service ,
@@ -61,6 +63,8 @@ rmw_send_response(
6163 uxr_serialize_SampleIdentity (& mb , & sample_id );
6264 functions -> cdr_serialize (ros_response , & mb );
6365
66+ UXR_UNLOCK_STREAM_ID (& custom_node -> context -> session , custom_service -> stream_id );
67+
6468 if (UXR_INVALID_REQUEST_ID == rc )
6569 {
6670 RMW_SET_ERROR_MSG ("Micro XRCE-DDS service response error." );
Original file line number Diff line number Diff line change 2828#include "rmw/allocators.h"
2929#include <rmw/error_handling.h>
3030
31+ #include <uxr/client/profile/multithread/multithread.h>
32+
3133// Static memory pools
3234
3335char rmw_uxrce_entity_naming_buffer [RMW_UXRCE_ENTITY_NAMING_BUFFER_LENGTH ];
@@ -65,6 +67,7 @@ rmw_uxrce_static_input_buffer_t custom_static_buffers[RMW_UXRCE_MAX_HISTORY];
6567 size_t size) \
6668 { \
6769 if (size > 0 && !memory->is_initialized){ \
70+ UXR_INIT_LOCK(&memory->mutex); \
6871 memory->is_initialized = true; \
6972 memory->element_size = sizeof(*array); \
7073 memory->allocateditems = NULL; \
You can’t perform that action at this time.
0 commit comments