@@ -70,10 +70,13 @@ void on_topic(
7070 if ((custom_subscription -> datareader_id .id == object_id .id ) &&
7171 (custom_subscription -> datareader_id .type == object_id .type ))
7272 {
73+ UXR_LOCK (& static_buffer_memory .mutex );
74+
7375 rmw_uxrce_mempool_item_t * memory_node = rmw_uxrce_get_static_input_buffer_for_entity (
7476 custom_subscription , custom_subscription -> qos );
7577 if (!memory_node ) {
7678 RMW_SET_ERROR_MSG ("Not available static buffer memory node" );
79+ UXR_UNLOCK (& static_buffer_memory .mutex );
7780 return ;
7881 }
7982
@@ -86,14 +89,14 @@ void on_topic(
8689 length ))
8790 {
8891 put_memory (& static_buffer_memory , memory_node );
89- return ;
92+ } else {
93+ static_buffer -> owner = (void * ) custom_subscription ;
94+ static_buffer -> length = length ;
95+ static_buffer -> timestamp = rmw_uros_epoch_nanos ();
96+ static_buffer -> entity_type = RMW_UXRCE_ENTITY_TYPE_SUBSCRIPTION ;
9097 }
9198
92- static_buffer -> owner = (void * ) custom_subscription ;
93- static_buffer -> length = length ;
94- static_buffer -> timestamp = rmw_uros_epoch_nanos ();
95- static_buffer -> entity_type = RMW_UXRCE_ENTITY_TYPE_SUBSCRIPTION ;
96-
99+ UXR_UNLOCK (& static_buffer_memory .mutex );
97100 return ;
98101 }
99102 subscription_item = subscription_item -> next ;
@@ -119,10 +122,13 @@ void on_request(
119122 // Check if request is related to the service
120123 rmw_uxrce_service_t * custom_service = (rmw_uxrce_service_t * )service_item -> data ;
121124 if (custom_service -> service_data_resquest == request_id ) {
125+ UXR_LOCK (& static_buffer_memory .mutex );
126+
122127 rmw_uxrce_mempool_item_t * memory_node = rmw_uxrce_get_static_input_buffer_for_entity (
123128 custom_service , custom_service -> qos );
124129 if (!memory_node ) {
125130 RMW_SET_ERROR_MSG ("Not available static buffer memory node" );
131+ UXR_UNLOCK (& static_buffer_memory .mutex );
126132 return ;
127133 }
128134
@@ -135,14 +141,15 @@ void on_request(
135141 length ))
136142 {
137143 put_memory (& static_buffer_memory , memory_node );
138- return ;
144+ } else {
145+ static_buffer -> owner = (void * ) custom_service ;
146+ static_buffer -> length = length ;
147+ static_buffer -> related .sample_id = * sample_id ;
148+ static_buffer -> timestamp = rmw_uros_epoch_nanos ();
149+ static_buffer -> entity_type = RMW_UXRCE_ENTITY_TYPE_SERVICE ;
139150 }
140151
141- static_buffer -> owner = (void * ) custom_service ;
142- static_buffer -> length = length ;
143- static_buffer -> related .sample_id = * sample_id ;
144- static_buffer -> timestamp = rmw_uros_epoch_nanos ();
145- static_buffer -> entity_type = RMW_UXRCE_ENTITY_TYPE_SERVICE ;
152+ UXR_UNLOCK (& static_buffer_memory .mutex );
146153
147154 return ;
148155 }
@@ -169,10 +176,13 @@ void on_reply(
169176 // Check if reply is related to the client
170177 rmw_uxrce_client_t * custom_client = (rmw_uxrce_client_t * )client_item -> data ;
171178 if (custom_client -> client_data_request == request_id ) {
179+ UXR_LOCK (& static_buffer_memory .mutex );
180+
172181 rmw_uxrce_mempool_item_t * memory_node = rmw_uxrce_get_static_input_buffer_for_entity (
173182 custom_client , custom_client -> qos );
174183 if (!memory_node ) {
175184 RMW_SET_ERROR_MSG ("Not available static buffer memory node" );
185+ UXR_UNLOCK (& static_buffer_memory .mutex );
176186 return ;
177187 }
178188
@@ -185,14 +195,14 @@ void on_reply(
185195 length ))
186196 {
187197 put_memory (& static_buffer_memory , memory_node );
188- return ;
198+ } else {
199+ static_buffer -> owner = (void * ) custom_client ;
200+ static_buffer -> length = length ;
201+ static_buffer -> related .reply_id = reply_id ;
202+ static_buffer -> timestamp = rmw_uros_epoch_nanos ();
203+ static_buffer -> entity_type = RMW_UXRCE_ENTITY_TYPE_CLIENT ;
189204 }
190-
191- static_buffer -> owner = (void * ) custom_client ;
192- static_buffer -> length = length ;
193- static_buffer -> related .reply_id = reply_id ;
194- static_buffer -> timestamp = rmw_uros_epoch_nanos ();
195- static_buffer -> entity_type = RMW_UXRCE_ENTITY_TYPE_CLIENT ;
205+ UXR_UNLOCK (& static_buffer_memory .mutex );
196206
197207 return ;
198208 }
0 commit comments