+static inline vcl_session_handle_t
+ldp_fd_entry_sh (ldp_fd_entry_t * fde)
+{
+ return vppcom_session_handle (fde->session_index);
+}
+
+static int
+ldp_fd_alloc (vcl_session_handle_t sh)
+{
+ ldp_fd_entry_t *fde;
+
+ clib_rwlock_writer_lock (&ldp->fd_table_lock);
+ if (pool_elts (ldp->fd_pool) >= (1ULL << 32) - ldp->sh_bit_val)
+ {
+ clib_rwlock_writer_unlock (&ldp->fd_table_lock);
+ return -1;
+ }
+ pool_get (ldp->fd_pool, fde);
+ fde->session_index = vppcom_session_index (sh);
+ fde->worker_index = vppcom_session_worker (sh);
+ fde->fd_index = fde - ldp->fd_pool;
+ fde->fd = fde->fd_index + ldp->sh_bit_val;
+ hash_set (ldp->session_index_to_fd_table, fde->session_index, fde->fd);
+ clib_spinlock_init (&fde->lock);
+ clib_rwlock_writer_unlock (&ldp->fd_table_lock);
+ return fde->fd;
+}
+
+static ldp_fd_entry_t *
+ldp_fd_entry_get (u32 fd_index)
+{
+ if (pool_is_free_index (ldp->fd_pool, fd_index))
+ return 0;
+ return pool_elt_at_index (ldp->fd_pool, fd_index);
+}
+
+static ldp_fd_entry_t *
+ldp_fd_entry_lock (u32 fd_index)
+{
+ ldp_fd_entry_t *fe;
+ clib_rwlock_reader_lock (&ldp->fd_table_lock);
+ if (pool_is_free_index (ldp->fd_pool, fd_index))
+ {
+ clib_rwlock_reader_unlock (&ldp->fd_table_lock);
+ return 0;
+ }
+
+ fe = pool_elt_at_index (ldp->fd_pool, fd_index);
+ clib_spinlock_lock (&fe->lock);
+ return fe;
+}
+
+static void
+ldp_fd_entry_unlock (ldp_fd_entry_t * fde)
+{
+ clib_spinlock_unlock (&fde->lock);
+ clib_rwlock_reader_unlock (&ldp->fd_table_lock);
+}
+