2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
21 #include <arpa/inet.h>
25 #include <vpp-api/vapi/vapi_dbg.h>
26 #include <vpp-api/vapi/vapi.h>
27 #include <vpp-api/vapi/vapi_internal.h>
28 #include <vppinfra/types.h>
29 #include <vppinfra/pool.h>
30 #include <vlib/vlib.h>
31 #include <vlibapi/api_common.h>
32 #include <vlibmemory/memory_client.h>
34 #include <vapi/memclnt.api.vapi.h>
35 #include <vapi/vlib.api.vapi.h>
37 /* we need to use control pings for some stuff and because we're forced to put
38 * the code in headers, we need a way to be able to grab the ids of these
39 * messages - so declare them here as extern */
40 vapi_msg_id_t vapi_msg_id_control_ping = 0;
41 vapi_msg_id_t vapi_msg_id_control_ping_reply = 0;
43 DEFINE_VAPI_MSG_IDS_MEMCLNT_API_JSON;
44 DEFINE_VAPI_MSG_IDS_VLIB_API_JSON;
49 vapi_message_desc_t **msgs;
50 size_t max_len_name_with_crc;
61 static const u32 context_counter_mask = (1 << 31);
65 vapi_error_e (*cb) (vapi_ctx_t ctx, void *callback_ctx, vapi_msg_id_t id,
68 } vapi_generic_cb_with_ctx;
72 vapi_error_e (*cb) (vapi_ctx_t ctx, void *callback_ctx, void *payload);
74 } vapi_event_cb_with_ctx;
79 int requests_size; /* size of the requests array (circular queue) */
80 int requests_start; /* index of first request */
81 int requests_count; /* number of used slots */
84 vapi_generic_cb_with_ctx generic_cb;
85 vapi_event_cb_with_ctx *event_cbs;
86 u16 *vapi_msg_id_t_to_vl_msg_id;
88 vapi_msg_id_t *vl_msg_id_to_vapi_msg_t;
90 bool handle_keepalives;
91 pthread_mutex_t requests_mutex;
95 vapi_gen_req_context (vapi_ctx_t ctx)
97 ++ctx->context_counter;
98 ctx->context_counter %= context_counter_mask;
99 return ctx->context_counter | context_counter_mask;
103 vapi_get_request_count (vapi_ctx_t ctx)
105 return ctx->requests_count;
109 vapi_requests_full (vapi_ctx_t ctx)
111 return (ctx->requests_count == ctx->requests_size);
115 vapi_requests_empty (vapi_ctx_t ctx)
117 return (0 == ctx->requests_count);
121 vapi_requests_end (vapi_ctx_t ctx)
123 return (ctx->requests_start + ctx->requests_count) % ctx->requests_size;
127 vapi_store_request (vapi_ctx_t ctx, u32 context, bool is_dump,
128 vapi_cb_t callback, void *callback_ctx)
130 assert (!vapi_requests_full (ctx));
131 /* if the mutex is not held, bad things will happen */
132 assert (0 != pthread_mutex_trylock (&ctx->requests_mutex));
133 const int requests_end = vapi_requests_end (ctx);
134 vapi_req_t *slot = &ctx->requests[requests_end];
135 slot->is_dump = is_dump;
136 slot->context = context;
137 slot->callback = callback;
138 slot->callback_ctx = callback_ctx;
139 VAPI_DBG ("stored@%d: context:%x (start is @%d)", requests_end, context,
140 ctx->requests_start);
141 ++ctx->requests_count;
142 assert (!vapi_requests_empty (ctx));
146 struct to_be_freed_s;
150 struct to_be_freed_s *next;
153 static struct to_be_freed_s *to_be_freed = NULL;
156 vapi_add_to_be_freed (void *v)
158 struct to_be_freed_s *prev = NULL;
159 struct to_be_freed_s *tmp;
161 while (tmp && tmp->v)
170 tmp = to_be_freed = calloc (1, sizeof (*to_be_freed));
174 tmp = prev->next = calloc (1, sizeof (*to_be_freed));
177 VAPI_DBG ("To be freed %p", v);
182 vapi_trace_free (void *v)
184 struct to_be_freed_s *tmp = to_be_freed;
185 while (tmp && tmp->v != v)
189 if (tmp && tmp->v == v)
191 VAPI_DBG ("Freed %p", v);
196 VAPI_ERR ("Trying to free untracked pointer %p", v);
202 vapi_to_be_freed_validate ()
204 struct to_be_freed_s *tmp = to_be_freed;
209 VAPI_ERR ("Unfreed msg %p!", tmp->v);
218 vapi_msg_alloc (vapi_ctx_t ctx, size_t size)
224 void *rv = vl_msg_api_alloc_or_null (size);
227 clib_memset (rv, 0, size);
233 vapi_msg_free (vapi_ctx_t ctx, void *msg)
240 vapi_trace_free (msg);
242 vl_msg_api_free (msg);
246 vapi_lookup_vapi_msg_id_t (vapi_ctx_t ctx, u16 vl_msg_id)
248 if (vl_msg_id <= ctx->vl_msg_id_max)
250 return ctx->vl_msg_id_to_vapi_msg_t[vl_msg_id];
252 return VAPI_INVALID_MSG_ID;
256 vapi_ctx_alloc (vapi_ctx_t * result)
258 vapi_ctx_t ctx = calloc (1, sizeof (struct vapi_ctx_s));
263 ctx->context_counter = 0;
264 ctx->vapi_msg_id_t_to_vl_msg_id =
265 malloc (__vapi_metadata.count *
266 sizeof (*ctx->vapi_msg_id_t_to_vl_msg_id));
267 if (!ctx->vapi_msg_id_t_to_vl_msg_id)
271 clib_memset (ctx->vapi_msg_id_t_to_vl_msg_id, ~0,
272 __vapi_metadata.count *
273 sizeof (*ctx->vapi_msg_id_t_to_vl_msg_id));
274 ctx->event_cbs = calloc (__vapi_metadata.count, sizeof (*ctx->event_cbs));
279 pthread_mutex_init (&ctx->requests_mutex, NULL);
288 vapi_ctx_free (vapi_ctx_t ctx)
290 assert (!ctx->connected);
291 free (ctx->requests);
292 free (ctx->vapi_msg_id_t_to_vl_msg_id);
293 free (ctx->event_cbs);
294 free (ctx->vl_msg_id_to_vapi_msg_t);
295 pthread_mutex_destroy (&ctx->requests_mutex);
300 vapi_is_msg_available (vapi_ctx_t ctx, vapi_msg_id_t id)
302 return vapi_lookup_vl_msg_id (ctx, id) != UINT16_MAX;
306 vapi_connect (vapi_ctx_t ctx, const char *name,
307 const char *chroot_prefix,
308 int max_outstanding_requests,
309 int response_queue_size, vapi_mode_e mode,
310 bool handle_keepalives)
312 if (response_queue_size <= 0 || max_outstanding_requests <= 0)
316 if (!clib_mem_get_per_cpu_heap () && !clib_mem_init (0, 1024 * 1024 * 32))
320 ctx->requests_size = max_outstanding_requests;
321 const size_t size = ctx->requests_size * sizeof (*ctx->requests);
322 void *tmp = realloc (ctx->requests, size);
328 clib_memset (ctx->requests, 0, size);
329 /* coverity[MISSING_LOCK] - 177211 requests_mutex is not needed here */
330 ctx->requests_start = ctx->requests_count = 0;
333 VAPI_DBG ("set memory root path `%s'", chroot_prefix);
334 vl_set_memory_root_path ((char *) chroot_prefix);
336 static char api_map[] = "/vpe-api";
337 VAPI_DBG ("client api map `%s'", api_map);
338 if ((vl_client_api_map (api_map)) < 0)
340 return VAPI_EMAP_FAIL;
342 VAPI_DBG ("connect client `%s'", name);
343 if (vl_client_connect ((char *) name, 0, response_queue_size) < 0)
345 vl_client_api_unmap ();
346 return VAPI_ECON_FAIL;
348 #if VAPI_DEBUG_CONNECT
349 VAPI_DBG ("start probing messages");
353 for (i = 0; i < __vapi_metadata.count; ++i)
355 vapi_message_desc_t *m = __vapi_metadata.msgs[i];
356 u8 scratch[m->name_with_crc_len + 1];
357 memcpy (scratch, m->name_with_crc, m->name_with_crc_len + 1);
358 u32 id = vl_msg_api_get_msg_index (scratch);
359 if (VAPI_INVALID_MSG_ID != id)
363 VAPI_ERR ("Returned vl_msg_id `%u' > UINT16MAX `%u'!", id,
368 if (id > ctx->vl_msg_id_max)
370 vapi_msg_id_t *tmp = realloc (ctx->vl_msg_id_to_vapi_msg_t,
372 (*ctx->vl_msg_id_to_vapi_msg_t) *
379 ctx->vl_msg_id_to_vapi_msg_t = tmp;
380 ctx->vl_msg_id_max = id;
382 ctx->vl_msg_id_to_vapi_msg_t[id] = m->id;
383 ctx->vapi_msg_id_t_to_vl_msg_id[m->id] = id;
384 #if VAPI_DEBUG_CONNECT
385 VAPI_DBG ("Message `%s' has vl_msg_id `%u'", m->name_with_crc,
391 ctx->vapi_msg_id_t_to_vl_msg_id[m->id] = UINT16_MAX;
392 VAPI_DBG ("Message `%s' not available", m->name_with_crc);
395 #if VAPI_DEBUG_CONNECT
396 VAPI_DBG ("finished probing messages");
398 if (!vapi_is_msg_available (ctx, vapi_msg_id_control_ping) ||
399 !vapi_is_msg_available (ctx, vapi_msg_id_control_ping_reply))
402 ("control ping or control ping reply not available, cannot connect");
403 rv = VAPI_EINCOMPATIBLE;
407 ctx->connected = true;
408 if (vapi_is_msg_available (ctx, vapi_msg_id_memclnt_keepalive))
410 ctx->handle_keepalives = handle_keepalives;
414 ctx->handle_keepalives = false;
418 vl_client_disconnect ();
419 vl_client_api_unmap ();
424 vapi_disconnect (vapi_ctx_t ctx)
430 vl_client_disconnect ();
431 vl_client_api_unmap ();
433 vapi_to_be_freed_validate ();
435 ctx->connected = false;
440 vapi_get_fd (vapi_ctx_t ctx, int *fd)
446 vapi_send (vapi_ctx_t ctx, void *msg)
448 vapi_error_e rv = VAPI_OK;
449 if (!ctx || !msg || !ctx->connected)
455 svm_queue_t *q = vlibapi_get_main ()->shmem_hdr->vl_input_queue;
457 unsigned msgid = be16toh (*(u16 *) msg);
458 if (msgid <= ctx->vl_msg_id_max)
460 vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[msgid];
461 if (id < __vapi_metadata.count)
463 VAPI_DBG ("send msg@%p:%u[%s]", msg, msgid,
464 __vapi_metadata.msgs[id]->name);
468 VAPI_DBG ("send msg@%p:%u[UNKNOWN]", msg, msgid);
473 VAPI_DBG ("send msg@%p:%u[UNKNOWN]", msg, msgid);
476 tmp = svm_queue_add (q, (u8 *) & msg,
477 VAPI_MODE_BLOCKING == ctx->mode ? 0 : 1);
483 VL_MSG_API_POISON (msg);
485 VAPI_DBG ("vapi_send() rv = %d", rv);
490 vapi_send2 (vapi_ctx_t ctx, void *msg1, void *msg2)
492 vapi_error_e rv = VAPI_OK;
493 if (!ctx || !msg1 || !msg2 || !ctx->connected)
498 svm_queue_t *q = vlibapi_get_main ()->shmem_hdr->vl_input_queue;
500 unsigned msgid1 = be16toh (*(u16 *) msg1);
501 unsigned msgid2 = be16toh (*(u16 *) msg2);
502 const char *name1 = "UNKNOWN";
503 const char *name2 = "UNKNOWN";
504 if (msgid1 <= ctx->vl_msg_id_max)
506 vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[msgid1];
507 if (id < __vapi_metadata.count)
509 name1 = __vapi_metadata.msgs[id]->name;
512 if (msgid2 <= ctx->vl_msg_id_max)
514 vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[msgid2];
515 if (id < __vapi_metadata.count)
517 name2 = __vapi_metadata.msgs[id]->name;
520 VAPI_DBG ("send two: %u[%s], %u[%s]", msgid1, name1, msgid2, name2);
522 int tmp = svm_queue_add2 (q, (u8 *) & msg1, (u8 *) & msg2,
523 VAPI_MODE_BLOCKING == ctx->mode ? 0 : 1);
529 VL_MSG_API_POISON (msg1);
531 VAPI_DBG ("vapi_send() rv = %d", rv);
536 vapi_recv (vapi_ctx_t ctx, void **msg, size_t * msg_size,
537 svm_q_conditional_wait_t cond, u32 time)
539 if (!ctx || !ctx->connected || !msg || !msg_size)
543 vapi_error_e rv = VAPI_OK;
544 api_main_t *am = vlibapi_get_main ();
547 if (am->our_pid == 0)
552 svm_queue_t *q = am->vl_input_queue;
554 VAPI_DBG ("doing shm queue sub");
556 int tmp = svm_queue_sub (q, (u8 *) & data, cond, time);
560 VL_MSG_API_UNPOISON ((void *) data);
562 vapi_add_to_be_freed ((void *) data);
565 (msgbuf_t *) ((u8 *) data - offsetof (msgbuf_t, data));
566 if (!msgbuf->data_len)
568 vapi_msg_free (ctx, (u8 *) data);
572 *msg_size = ntohl (msgbuf->data_len);
574 unsigned msgid = be16toh (*(u16 *) * msg);
575 if (msgid <= ctx->vl_msg_id_max)
577 vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[msgid];
578 if (id < __vapi_metadata.count)
580 VAPI_DBG ("recv msg@%p:%u[%s]", *msg, msgid,
581 __vapi_metadata.msgs[id]->name);
585 VAPI_DBG ("recv msg@%p:%u[UNKNOWN]", *msg, msgid);
590 VAPI_DBG ("recv msg@%p:%u[UNKNOWN]", *msg, msgid);
593 if (ctx->handle_keepalives)
595 unsigned msgid = be16toh (*(u16 *) * msg);
597 vapi_lookup_vl_msg_id (ctx, vapi_msg_id_memclnt_keepalive))
599 vapi_msg_memclnt_keepalive_reply *reply = NULL;
602 reply = vapi_msg_alloc (ctx, sizeof (*reply));
605 reply->header.context = vapi_get_client_index (ctx);
606 reply->header._vl_msg_id =
607 vapi_lookup_vl_msg_id (ctx,
608 vapi_msg_id_memclnt_keepalive_reply);
609 reply->payload.retval = 0;
610 vapi_msg_memclnt_keepalive_reply_hton (reply);
611 while (VAPI_EAGAIN == vapi_send (ctx, reply));
612 vapi_msg_free (ctx, *msg);
613 VAPI_DBG ("autohandled memclnt_keepalive");
626 vapi_wait (vapi_ctx_t ctx, vapi_wait_mode_e mode)
632 vapi_dispatch_response (vapi_ctx_t ctx, vapi_msg_id_t id,
633 u32 context, void *msg)
636 if (0 != (mrv = pthread_mutex_lock (&ctx->requests_mutex)))
638 VAPI_DBG ("pthread_mutex_lock() failed, rv=%d:%s", mrv, strerror (mrv));
639 return VAPI_MUTEX_FAILURE;
641 int tmp = ctx->requests_start;
642 const int requests_end = vapi_requests_end (ctx);
643 while (ctx->requests[tmp].context != context && tmp != requests_end)
646 if (tmp == ctx->requests_size)
651 VAPI_DBG ("dispatch, search from %d, %s at %d", ctx->requests_start,
652 ctx->requests[tmp].context == context ? "matched" : "stopped",
654 vapi_error_e rv = VAPI_OK;
655 if (ctx->requests[tmp].context == context)
657 while (ctx->requests_start != tmp)
659 VAPI_ERR ("No response to req with context=%u",
660 (unsigned) ctx->requests[tmp].context);
661 ctx->requests[ctx->requests_start].callback (ctx, ctx->requests
663 requests_start].callback_ctx,
666 clib_memset (&ctx->requests[ctx->requests_start], 0,
667 sizeof (ctx->requests[ctx->requests_start]));
668 ++ctx->requests_start;
669 --ctx->requests_count;
670 if (ctx->requests_start == ctx->requests_size)
672 ctx->requests_start = 0;
675 // now ctx->requests_start == tmp
676 int payload_offset = vapi_get_payload_offset (id);
677 void *payload = ((u8 *) msg) + payload_offset;
679 if (ctx->requests[tmp].is_dump)
681 if (vapi_msg_id_control_ping_reply == id)
690 if (payload_offset != -1)
693 ctx->requests[tmp].callback (ctx, ctx->requests[tmp].callback_ctx,
694 VAPI_OK, is_last, payload);
698 /* this is a message without payload, so bend the callback a little
701 ((vapi_error_e (*)(vapi_ctx_t, void *, vapi_error_e, bool))
702 ctx->requests[tmp].callback) (ctx,
703 ctx->requests[tmp].callback_ctx,
708 clib_memset (&ctx->requests[ctx->requests_start], 0,
709 sizeof (ctx->requests[ctx->requests_start]));
710 ++ctx->requests_start;
711 --ctx->requests_count;
712 if (ctx->requests_start == ctx->requests_size)
714 ctx->requests_start = 0;
717 VAPI_DBG ("after dispatch, req start = %d, end = %d, count = %d",
718 ctx->requests_start, requests_end, ctx->requests_count);
720 if (0 != (mrv = pthread_mutex_unlock (&ctx->requests_mutex)))
722 VAPI_DBG ("pthread_mutex_unlock() failed, rv=%d:%s", mrv,
724 abort (); /* this really shouldn't happen */
730 vapi_dispatch_event (vapi_ctx_t ctx, vapi_msg_id_t id, void *msg)
732 if (ctx->event_cbs[id].cb)
734 return ctx->event_cbs[id].cb (ctx, ctx->event_cbs[id].ctx, msg);
736 else if (ctx->generic_cb.cb)
738 return ctx->generic_cb.cb (ctx, ctx->generic_cb.ctx, id, msg);
743 ("No handler/generic handler for msg id %u[%s], message ignored",
744 (unsigned) id, __vapi_metadata.msgs[id]->name);
750 vapi_msg_is_with_context (vapi_msg_id_t id)
752 assert (id <= __vapi_metadata.count);
753 return __vapi_metadata.msgs[id]->has_context;
757 vapi_dispatch_one (vapi_ctx_t ctx)
759 VAPI_DBG ("vapi_dispatch_one()");
762 vapi_error_e rv = vapi_recv (ctx, &msg, &size, SVM_Q_WAIT, 0);
765 VAPI_DBG ("vapi_recv failed with rv=%d", rv);
768 u16 vpp_id = be16toh (*(u16 *) msg);
769 if (vpp_id > ctx->vl_msg_id_max)
771 VAPI_ERR ("Unknown msg ID received, id `%u', out of range <0,%u>",
772 (unsigned) vpp_id, (unsigned) ctx->vl_msg_id_max);
773 vapi_msg_free (ctx, msg);
776 if (VAPI_INVALID_MSG_ID == (unsigned) ctx->vl_msg_id_to_vapi_msg_t[vpp_id])
778 VAPI_ERR ("Unknown msg ID received, id `%u' marked as not supported",
780 vapi_msg_free (ctx, msg);
783 const vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[vpp_id];
784 const size_t expect_size = vapi_get_message_size (id);
785 if (size < expect_size)
788 ("Invalid msg received, unexpected size `%zu' < expected min `%zu'",
790 vapi_msg_free (ctx, msg);
794 vapi_get_swap_to_host_func (id) (msg);
795 if (vapi_msg_is_with_context (id))
797 context = *(u32 *) (((u8 *) msg) + vapi_get_context_offset (id));
798 /* is this a message originating from VAPI? */
799 VAPI_DBG ("dispatch, context is %x", context);
800 if (context & context_counter_mask)
802 rv = vapi_dispatch_response (ctx, id, context, msg);
806 rv = vapi_dispatch_event (ctx, id, msg);
809 vapi_msg_free (ctx, msg);
814 vapi_dispatch (vapi_ctx_t ctx)
816 vapi_error_e rv = VAPI_OK;
817 while (!vapi_requests_empty (ctx))
819 rv = vapi_dispatch_one (ctx);
829 vapi_set_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id,
830 vapi_event_cb callback, void *callback_ctx)
832 vapi_event_cb_with_ctx *c = &ctx->event_cbs[id];
834 c->ctx = callback_ctx;
838 vapi_clear_event_cb (vapi_ctx_t ctx, vapi_msg_id_t id)
840 vapi_set_event_cb (ctx, id, NULL, NULL);
844 vapi_set_generic_event_cb (vapi_ctx_t ctx, vapi_generic_event_cb callback,
847 ctx->generic_cb.cb = callback;
848 ctx->generic_cb.ctx = callback_ctx;
852 vapi_clear_generic_event_cb (vapi_ctx_t ctx)
854 ctx->generic_cb.cb = NULL;
855 ctx->generic_cb.ctx = NULL;
859 vapi_lookup_vl_msg_id (vapi_ctx_t ctx, vapi_msg_id_t id)
861 assert (id < __vapi_metadata.count);
862 return ctx->vapi_msg_id_t_to_vl_msg_id[id];
866 vapi_get_client_index (vapi_ctx_t ctx)
868 return vlibapi_get_main ()->my_client_index;
872 vapi_is_nonblocking (vapi_ctx_t ctx)
874 return (VAPI_MODE_NONBLOCKING == ctx->mode);
878 vapi_get_max_request_count (vapi_ctx_t ctx)
880 return ctx->requests_size - 1;
884 vapi_get_payload_offset (vapi_msg_id_t id)
886 assert (id < __vapi_metadata.count);
887 return __vapi_metadata.msgs[id]->payload_offset;
890 void (*vapi_get_swap_to_host_func (vapi_msg_id_t id)) (void *msg)
892 assert (id < __vapi_metadata.count);
893 return __vapi_metadata.msgs[id]->swap_to_host;
896 void (*vapi_get_swap_to_be_func (vapi_msg_id_t id)) (void *msg)
898 assert (id < __vapi_metadata.count);
899 return __vapi_metadata.msgs[id]->swap_to_be;
903 vapi_get_message_size (vapi_msg_id_t id)
905 assert (id < __vapi_metadata.count);
906 return __vapi_metadata.msgs[id]->size;
910 vapi_get_context_offset (vapi_msg_id_t id)
912 assert (id < __vapi_metadata.count);
913 return __vapi_metadata.msgs[id]->context_offset;
917 vapi_register_msg (vapi_message_desc_t * msg)
920 for (i = 0; i < __vapi_metadata.count; ++i)
923 (msg->name_with_crc, __vapi_metadata.msgs[i]->name_with_crc))
925 /* this happens if somebody is linking together several objects while
926 * using the static inline headers, just fill in the already
927 * assigned id here so that all the objects are in sync */
928 msg->id = __vapi_metadata.msgs[i]->id;
932 vapi_msg_id_t id = __vapi_metadata.count;
933 ++__vapi_metadata.count;
934 __vapi_metadata.msgs =
935 realloc (__vapi_metadata.msgs,
936 sizeof (*__vapi_metadata.msgs) * __vapi_metadata.count);
937 __vapi_metadata.msgs[id] = msg;
938 size_t s = strlen (msg->name_with_crc);
939 if (s > __vapi_metadata.max_len_name_with_crc)
941 __vapi_metadata.max_len_name_with_crc = s;
948 vapi_producer_lock (vapi_ctx_t ctx)
951 if (0 != (mrv = pthread_mutex_lock (&ctx->requests_mutex)))
953 VAPI_DBG ("pthread_mutex_lock() failed, rv=%d:%s", mrv, strerror (mrv));
954 (void) mrv; /* avoid warning if the above debug is not enabled */
955 return VAPI_MUTEX_FAILURE;
961 vapi_producer_unlock (vapi_ctx_t ctx)
964 if (0 != (mrv = pthread_mutex_unlock (&ctx->requests_mutex)))
966 VAPI_DBG ("pthread_mutex_unlock() failed, rv=%d:%s", mrv,
968 (void) mrv; /* avoid warning if the above debug is not enabled */
969 return VAPI_MUTEX_FAILURE;
975 vapi_get_message_count ()
977 return __vapi_metadata.count;
981 vapi_get_msg_name (vapi_msg_id_t id)
983 return __vapi_metadata.msgs[id]->name;
987 * fd.io coding-style-patch-verification: ON
990 * eval: (c-set-style "gnu")