+ clib_rwlock_reader_unlock (&cm->app_segs_lock);
+
+ /*
+ * No segment, try to alloc one and notify the server
+ */
+
+ if (ct_seg_index == ~0)
+ {
+ seg_size = clib_max (props->segment_size, 128 << 20);
+ fs_index = segment_manager_add_segment (sm, seg_size, 0);
+ if (fs_index < 0)
+ {
+ rv = -1;
+ goto failed;
+ }
+
+ /* Make sure the segment is not used for other fifos */
+ fs = segment_manager_get_segment_w_lock (sm, fs_index);
+ fifo_segment_flags (fs) |= FIFO_SEGMENT_F_CUSTOM_USE;
+ segment_manager_segment_reader_unlock (sm);
+
+ clib_rwlock_writer_lock (&cm->app_segs_lock);
+
+ if (seg_ctx_index == ~0)
+ {
+ pool_get_zero (cm->app_seg_ctxs, seg_ctx);
+ seg_ctx_index = seg_ctx - cm->app_seg_ctxs;
+ hash_set (cm->app_segs_ctxs_table, table_handle, seg_ctx_index);
+ seg_ctx->server_wrk = server_wrk->wrk_index;
+ seg_ctx->client_wrk = ct->client_wrk;
+ seg_ctx->sm_index = sm_index;
+ }
+ else
+ seg_ctx = pool_elt_at_index (cm->app_seg_ctxs, seg_ctx_index);
+
+ pool_get_zero (seg_ctx->segments, ct_seg);
+ ct_seg->segment_index = fs_index;
+ ct_seg->server_n_sessions += 1;
+ ct_seg_index = ct_seg - seg_ctx->segments;
+
+ clib_rwlock_writer_unlock (&cm->app_segs_lock);
+
+ /* New segment, notify the server. Client notification sent after
+ * server accepts the connection */
+ seg_handle = segment_manager_make_segment_handle (sm_index, fs_index);
+ if ((rv = app_worker_add_segment_notify (server_wrk, seg_handle)))
+ {
+ segment_manager_lock_and_del_segment (sm, fs_index);
+
+ clib_rwlock_writer_lock (&cm->app_segs_lock);
+ pool_put_index (seg_ctx->segments, ct_seg_index);
+ clib_rwlock_writer_unlock (&cm->app_segs_lock);
+
+ goto failed_fix_count;
+ }
+ }
+
+ /*
+ * Allocate and initialize the fifos
+ */
+ fs = segment_manager_get_segment_w_lock (sm, fs_index);
+ rv = segment_manager_try_alloc_fifos (
+ fs, ls->thread_index, props->rx_fifo_size, props->tx_fifo_size,
+ &ls->rx_fifo, &ls->tx_fifo);