Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/session/segment_manager.h> |
| 17 | #include <vnet/session/session.h> |
| 18 | #include <vnet/session/application.h> |
| 19 | |
| 20 | /** |
| 21 | * Counter used to build segment names |
| 22 | */ |
| 23 | u32 segment_name_counter = 0; |
| 24 | |
| 25 | /** |
| 26 | * Pool of segment managers |
| 27 | */ |
| 28 | segment_manager_t *segment_managers = 0; |
| 29 | |
| 30 | /** |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 31 | * Process private segment index |
| 32 | */ |
| 33 | u32 private_segment_index = ~0; |
| 34 | |
| 35 | /** |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 36 | * Default fifo and segment size. TODO config. |
| 37 | */ |
| 38 | u32 default_fifo_size = 1 << 16; |
| 39 | u32 default_segment_size = 1 << 20; |
| 40 | |
| 41 | void |
| 42 | segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size) |
| 43 | { |
| 44 | svm_fifo_segment_private_t *s; |
| 45 | s = svm_fifo_get_segment (index); |
| 46 | *name = s->h->segment_name; |
| 47 | *size = s->ssvm.ssvm_size; |
| 48 | } |
| 49 | |
| 50 | always_inline int |
| 51 | session_manager_add_segment_i (segment_manager_t * sm, u32 segment_size, |
| 52 | u8 * segment_name) |
| 53 | { |
| 54 | svm_fifo_segment_create_args_t _ca, *ca = &_ca; |
| 55 | int rv; |
| 56 | |
| 57 | memset (ca, 0, sizeof (*ca)); |
| 58 | |
| 59 | ca->segment_name = (char *) segment_name; |
| 60 | ca->segment_size = segment_size; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 61 | ca->rx_fifo_size = sm->properties->rx_fifo_size; |
| 62 | ca->tx_fifo_size = sm->properties->tx_fifo_size; |
| 63 | ca->preallocated_fifo_pairs = sm->properties->preallocated_fifo_pairs; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 64 | |
| 65 | rv = svm_fifo_segment_create (ca); |
| 66 | if (rv) |
| 67 | { |
| 68 | clib_warning ("svm_fifo_segment_create ('%s', %d) failed", |
| 69 | ca->segment_name, ca->segment_size); |
| 70 | vec_free (segment_name); |
| 71 | return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL; |
| 72 | } |
| 73 | |
| 74 | vec_add1 (sm->segment_indices, ca->new_segment_index); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | int |
| 80 | session_manager_add_segment (segment_manager_t * sm) |
| 81 | { |
| 82 | u8 *segment_name; |
| 83 | svm_fifo_segment_create_args_t _ca, *ca = &_ca; |
| 84 | u32 add_segment_size; |
| 85 | int rv; |
| 86 | |
| 87 | memset (ca, 0, sizeof (*ca)); |
| 88 | segment_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0); |
| 89 | add_segment_size = sm->properties->add_segment_size ? |
| 90 | sm->properties->add_segment_size : default_segment_size; |
| 91 | |
| 92 | rv = session_manager_add_segment_i (sm, add_segment_size, segment_name); |
| 93 | vec_free (segment_name); |
| 94 | return rv; |
| 95 | } |
| 96 | |
| 97 | int |
| 98 | session_manager_add_first_segment (segment_manager_t * sm, u32 segment_size) |
| 99 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 100 | u8 *segment_name; |
| 101 | int rv; |
| 102 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 103 | segment_name = format (0, "%d-%d%c", getpid (), segment_name_counter++, 0); |
| 104 | rv = session_manager_add_segment_i (sm, segment_size, segment_name); |
| 105 | vec_free (segment_name); |
| 106 | return rv; |
| 107 | } |
| 108 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 109 | static void |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 110 | segment_manager_alloc_process_private_segment |
| 111 | (segment_manager_properties_t * props) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 112 | { |
| 113 | svm_fifo_segment_create_args_t _a, *a = &_a; |
| 114 | |
| 115 | if (private_segment_index != ~0) |
| 116 | return; |
| 117 | |
| 118 | memset (a, 0, sizeof (*a)); |
| 119 | a->segment_name = "process-private-segment"; |
| 120 | a->segment_size = ~0; |
| 121 | a->new_segment_index = ~0; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 122 | a->rx_fifo_size = props->rx_fifo_size; |
| 123 | a->tx_fifo_size = props->tx_fifo_size; |
| 124 | a->preallocated_fifo_pairs = props->preallocated_fifo_pairs; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 125 | |
| 126 | if (svm_fifo_segment_create_process_private (a)) |
| 127 | clib_warning ("Failed to create process private segment"); |
| 128 | |
| 129 | private_segment_index = a->new_segment_index; |
| 130 | ASSERT (private_segment_index != ~0); |
| 131 | } |
| 132 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Initializes segment manager based on options provided. |
| 135 | * Returns error if svm segment allocation fails. |
| 136 | */ |
| 137 | int |
| 138 | segment_manager_init (segment_manager_t * sm, |
| 139 | segment_manager_properties_t * properties, |
| 140 | u32 first_seg_size) |
| 141 | { |
| 142 | int rv; |
| 143 | |
| 144 | /* app allocates these */ |
| 145 | sm->properties = properties; |
| 146 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 147 | first_seg_size = first_seg_size > 0 ? first_seg_size : default_segment_size; |
| 148 | |
| 149 | if (sm->properties->use_private_segment == 0) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 150 | { |
| 151 | rv = session_manager_add_first_segment (sm, first_seg_size); |
| 152 | if (rv) |
| 153 | { |
| 154 | clib_warning ("Failed to allocate segment"); |
| 155 | return rv; |
| 156 | } |
| 157 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 158 | else |
| 159 | { |
| 160 | if (private_segment_index == ~0) |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 161 | segment_manager_alloc_process_private_segment (properties); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 162 | ASSERT (private_segment_index != ~0); |
| 163 | vec_add1 (sm->segment_indices, private_segment_index); |
| 164 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 165 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 166 | clib_spinlock_init (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Removes segment manager. |
| 172 | * |
| 173 | * Since the fifos allocated in the segment keep backpointers to the sessions |
| 174 | * prior to removing the segment, we call session disconnect. This |
| 175 | * subsequently propages into transport. |
| 176 | */ |
| 177 | void |
| 178 | segment_manager_del (segment_manager_t * sm) |
| 179 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 180 | int j; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 181 | |
| 182 | /* Across all fifo segments used by the server */ |
| 183 | for (j = 0; j < vec_len (sm->segment_indices); j++) |
| 184 | { |
| 185 | svm_fifo_segment_private_t *fifo_segment; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 186 | svm_fifo_t *fifo; |
| 187 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 188 | /* Vector of fifos allocated in the segment */ |
| 189 | fifo_segment = svm_fifo_get_segment (sm->segment_indices[j]); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 190 | fifo = svm_fifo_segment_get_fifo_list (fifo_segment); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * Remove any residual sessions from the session lookup table |
| 194 | * Don't bother deleting the individual fifos, we're going to |
| 195 | * throw away the fifo segment in a minute. |
| 196 | */ |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 197 | while (fifo) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 198 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 199 | u32 session_index, thread_index; |
| 200 | stream_session_t *session; |
| 201 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 202 | session_index = fifo->master_session_index; |
| 203 | thread_index = fifo->master_thread_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 204 | |
| 205 | session = stream_session_get (session_index, thread_index); |
| 206 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 207 | /* Instead of directly removing the session call disconnect */ |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 208 | session_send_session_evt_to_thread (stream_session_handle (session), |
| 209 | FIFO_EVENT_DISCONNECT, |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 210 | thread_index); |
| 211 | fifo = fifo->next; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 214 | /* Instead of removing the segment, test when cleaning up disconnected |
| 215 | * sessions if the segment can be removed. |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 216 | */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 219 | clib_spinlock_free (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 220 | pool_put (segment_managers, sm); |
| 221 | } |
| 222 | |
| 223 | static int |
| 224 | segment_manager_notify_app_seg_add (segment_manager_t * sm, |
| 225 | u32 fifo_segment_index) |
| 226 | { |
| 227 | application_t *app = application_get (sm->app_index); |
| 228 | u32 seg_size = 0; |
| 229 | u8 *seg_name; |
| 230 | |
| 231 | /* Send an API message to the external app, to map new segment */ |
| 232 | ASSERT (app->cb_fns.add_segment_callback); |
| 233 | |
| 234 | segment_manager_get_segment_info (fifo_segment_index, &seg_name, &seg_size); |
| 235 | return app->cb_fns.add_segment_callback (app->api_client_index, seg_name, |
| 236 | seg_size); |
| 237 | } |
| 238 | |
| 239 | int |
| 240 | segment_manager_alloc_session_fifos (segment_manager_t * sm, |
| 241 | svm_fifo_t ** server_rx_fifo, |
| 242 | svm_fifo_t ** server_tx_fifo, |
| 243 | u32 * fifo_segment_index) |
| 244 | { |
| 245 | svm_fifo_segment_private_t *fifo_segment; |
| 246 | u32 fifo_size, sm_index; |
| 247 | u8 added_a_segment = 0; |
| 248 | int i; |
| 249 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 250 | ASSERT (vec_len (sm->segment_indices)); |
| 251 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 252 | /* Make sure we don't have multiple threads trying to allocate segments |
| 253 | * at the same time. */ |
| 254 | clib_spinlock_lock (&sm->lockp); |
| 255 | |
| 256 | /* Allocate svm fifos */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 257 | again: |
| 258 | for (i = 0; i < vec_len (sm->segment_indices); i++) |
| 259 | { |
| 260 | *fifo_segment_index = sm->segment_indices[i]; |
| 261 | fifo_segment = svm_fifo_get_segment (*fifo_segment_index); |
| 262 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 263 | /* FC: cleanup, make sure sm->properties->xxx_fifo_size always set */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 264 | fifo_size = sm->properties->rx_fifo_size; |
| 265 | fifo_size = (fifo_size == 0) ? default_fifo_size : fifo_size; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 266 | *server_rx_fifo = |
| 267 | svm_fifo_segment_alloc_fifo (fifo_segment, fifo_size, |
| 268 | FIFO_SEGMENT_RX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 269 | |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 270 | /* FC: cleanup, make sure sm->properties->xxx_fifo_size always set */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 271 | fifo_size = sm->properties->tx_fifo_size; |
| 272 | fifo_size = (fifo_size == 0) ? default_fifo_size : fifo_size; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 273 | *server_tx_fifo = |
| 274 | svm_fifo_segment_alloc_fifo (fifo_segment, fifo_size, |
| 275 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 276 | |
| 277 | if (*server_rx_fifo == 0) |
| 278 | { |
| 279 | /* This would be very odd, but handle it... */ |
| 280 | if (*server_tx_fifo != 0) |
| 281 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 282 | svm_fifo_segment_free_fifo (fifo_segment, *server_tx_fifo, |
| 283 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 284 | *server_tx_fifo = 0; |
| 285 | } |
| 286 | continue; |
| 287 | } |
| 288 | if (*server_tx_fifo == 0) |
| 289 | { |
| 290 | if (*server_rx_fifo != 0) |
| 291 | { |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 292 | svm_fifo_segment_free_fifo (fifo_segment, *server_rx_fifo, |
| 293 | FIFO_SEGMENT_RX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 294 | *server_rx_fifo = 0; |
| 295 | } |
| 296 | continue; |
| 297 | } |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | /* See if we're supposed to create another segment */ |
| 302 | if (*server_rx_fifo == 0) |
| 303 | { |
| 304 | if (sm->properties->add_segment) |
| 305 | { |
| 306 | if (added_a_segment) |
| 307 | { |
| 308 | clib_warning ("added a segment, still cant allocate a fifo"); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame^] | 309 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 310 | return SESSION_ERROR_NEW_SEG_NO_SPACE; |
| 311 | } |
| 312 | |
| 313 | if (session_manager_add_segment (sm)) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 314 | { |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame^] | 315 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 316 | return VNET_API_ERROR_URI_FIFO_CREATE_FAILED; |
| 317 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 318 | |
| 319 | added_a_segment = 1; |
| 320 | goto again; |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | clib_warning ("No space to allocate fifos!"); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame^] | 325 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 326 | return SESSION_ERROR_NO_SPACE; |
| 327 | } |
| 328 | } |
| 329 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 330 | /* Backpointers to segment manager */ |
| 331 | sm_index = segment_manager_index (sm); |
| 332 | (*server_tx_fifo)->segment_manager = sm_index; |
| 333 | (*server_rx_fifo)->segment_manager = sm_index; |
| 334 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 335 | clib_spinlock_unlock (&sm->lockp); |
| 336 | |
| 337 | if (added_a_segment) |
| 338 | return segment_manager_notify_app_seg_add (sm, *fifo_segment_index); |
| 339 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | void |
| 344 | segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo, |
| 345 | svm_fifo_t * tx_fifo) |
| 346 | { |
| 347 | segment_manager_t *sm; |
| 348 | svm_fifo_segment_private_t *fifo_segment; |
| 349 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 350 | sm = segment_manager_get_if_valid (rx_fifo->segment_manager); |
| 351 | |
| 352 | /* It's possible to have no segment manager if the session was removed |
| 353 | * as result of a detach */ |
| 354 | if (!sm) |
| 355 | return; |
| 356 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 357 | fifo_segment = svm_fifo_get_segment (svm_segment_index); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 358 | svm_fifo_segment_free_fifo (fifo_segment, rx_fifo, |
| 359 | FIFO_SEGMENT_RX_FREELIST); |
| 360 | svm_fifo_segment_free_fifo (fifo_segment, tx_fifo, |
| 361 | FIFO_SEGMENT_TX_FREELIST); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 362 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 363 | /* Remove segment only if it holds no fifos and not the first */ |
| 364 | if (sm->segment_indices[0] != svm_segment_index |
| 365 | && !svm_fifo_segment_has_fifos (fifo_segment)) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 366 | { |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame^] | 367 | clib_spinlock_lock (&sm->lockp); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 368 | svm_fifo_segment_delete (fifo_segment); |
| 369 | vec_del1 (sm->segment_indices, svm_segment_index); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame^] | 370 | clib_spinlock_unlock (&sm->lockp); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 374 | /** |
| 375 | * Allocates shm queue in the first segment |
| 376 | */ |
| 377 | unix_shared_memory_queue_t * |
| 378 | segment_manager_alloc_queue (segment_manager_t * sm, u32 queue_size) |
| 379 | { |
| 380 | ssvm_shared_header_t *sh; |
| 381 | svm_fifo_segment_private_t *segment; |
| 382 | unix_shared_memory_queue_t *q; |
| 383 | void *oldheap; |
| 384 | |
| 385 | ASSERT (sm->segment_indices != 0); |
| 386 | |
| 387 | segment = svm_fifo_get_segment (sm->segment_indices[0]); |
| 388 | sh = segment->ssvm.sh; |
| 389 | |
| 390 | oldheap = ssvm_push_heap (sh); |
| 391 | q = |
| 392 | unix_shared_memory_queue_init (queue_size, sizeof (session_fifo_event_t), |
| 393 | 0 /* consumer pid */ , 0 |
| 394 | /* signal when queue non-empty */ ); |
| 395 | ssvm_pop_heap (oldheap); |
| 396 | return q; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Frees shm queue allocated in the first segment |
| 401 | */ |
| 402 | void |
| 403 | segment_manager_dealloc_queue (segment_manager_t * sm, |
| 404 | unix_shared_memory_queue_t * q) |
| 405 | { |
| 406 | ssvm_shared_header_t *sh; |
| 407 | svm_fifo_segment_private_t *segment; |
| 408 | void *oldheap; |
| 409 | |
| 410 | ASSERT (sm->segment_indices != 0); |
| 411 | |
| 412 | segment = svm_fifo_get_segment (sm->segment_indices[0]); |
| 413 | sh = segment->ssvm.sh; |
| 414 | |
| 415 | oldheap = ssvm_push_heap (sh); |
| 416 | unix_shared_memory_queue_free (q); |
| 417 | ssvm_pop_heap (oldheap); |
| 418 | } |
| 419 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 420 | /* |
| 421 | * fd.io coding-style-patch-verification: ON |
| 422 | * |
| 423 | * Local Variables: |
| 424 | * eval: (c-set-style "gnu") |
| 425 | * End: |
| 426 | */ |