summaryrefslogtreecommitdiffstats
path: root/src/vcl/vcl_event.c
diff options
context:
space:
mode:
authorDave Wallace <dwallacelf@gmail.com>2018-06-18 18:41:32 -0400
committerFlorin Coras <florin.coras@gmail.com>2018-06-19 19:35:44 +0000
commit7e607a73898b81c21a24038a2350fdda3b1c67ff (patch)
tree9e9c179327729a46560c5e21e6d5feb1544130ee /src/vcl/vcl_event.c
parentc6215d902f02d08a59567f3f788caa0e03508c0d (diff)
VCL: refactor async & spinlocks
- Consolidate async code. - Add macros for spinlocks to improve readability. Change-Id: I2e0fd2b82ea76987aaf298a183d816c7d2ee0867 Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Diffstat (limited to 'src/vcl/vcl_event.c')
-rw-r--r--src/vcl/vcl_event.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/vcl/vcl_event.c b/src/vcl/vcl_event.c
index dafa2500d1d..e72b864e944 100644
--- a/src/vcl/vcl_event.c
+++ b/src/vcl/vcl_event.c
@@ -18,7 +18,9 @@
#include <vppinfra/hash.h>
#include <vnet/api_errno.h>
+#include <vcl/vppcom.h>
#include <vcl/vcl_event.h>
+
/**
* @file
* @brief VPP Communications Library (VCL) event handler.
@@ -36,7 +38,7 @@ vce_generate_event (vce_event_thread_t *evt, u32 ev_idx)
/* Check there is event data for this event */
- clib_spinlock_lock (&(evt->events_lockp));
+ VCE_EVENTS_LOCK();
p = pool_elt_at_index (evt->vce_events, ev_idx);
ASSERT(p);
@@ -52,7 +54,7 @@ vce_generate_event (vce_event_thread_t *evt, u32 ev_idx)
rv = VNET_API_ERROR_QUEUE_FULL;
}
- clib_spinlock_unlock (&(evt->events_lockp));
+ VCE_EVENTS_UNLOCK ();
pthread_mutex_unlock (&(evt->generator_lock));
return rv;
@@ -61,9 +63,9 @@ vce_generate_event (vce_event_thread_t *evt, u32 ev_idx)
void
vce_clear_event (vce_event_thread_t *evt, u32 ev_idx)
{
- clib_spinlock_lock (&(evt->events_lockp));
+ VCE_EVENTS_LOCK ();
pool_put_index (evt->vce_events, ev_idx);
- clib_spinlock_unlock (&(evt->events_lockp));
+ VCE_EVENTS_UNLOCK ();
}
vce_event_t *
@@ -84,11 +86,11 @@ vce_get_event_handler (vce_event_thread_t *evt, vce_event_key_t *evk)
vce_event_handler_reg_t *handler = 0;
uword *p;
- clib_spinlock_lock (&evt->handlers_lockp);
+ VCE_HANDLERS_LOCK ();
p = hash_get (evt->handlers_index_by_event_key, evk->as_u64);
if (p)
handler = pool_elt_at_index (evt->vce_event_handlers, p[0]);
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_HANDLERS_UNLOCK ();
return handler;
}
@@ -105,7 +107,7 @@ vce_register_handler (vce_event_thread_t *evt, vce_event_key_t *evk,
/* TODO - multiple handler support. For now we can replace
* and re-instate, which is useful for event recycling */
- clib_spinlock_lock (&evt->handlers_lockp);
+ VCE_HANDLERS_LOCK ();
p = hash_get (evt->handlers_index_by_event_key, evk->as_u64);
if (p)
@@ -116,7 +118,7 @@ vce_register_handler (vce_event_thread_t *evt, vce_event_key_t *evk,
if (old_handler->handler_fn == cb)
{
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_HANDLERS_UNLOCK ();
/* Signal event thread that a handler exists in case any
* recycled events requiring this handler are pending */
@@ -141,7 +143,7 @@ vce_register_handler (vce_event_thread_t *evt, vce_event_key_t *evk,
pthread_cond_init (&(handler->handler_cond), NULL);
pthread_mutex_init (&(handler->handler_lock), NULL);
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_HANDLERS_UNLOCK ();
/* Signal event thread that a new handler exists in case any
* recycled events requiring this handler are pending */
@@ -160,12 +162,12 @@ vce_unregister_handler (vce_event_thread_t *evt,
u64 evk = handler->evk;
u8 generate_signal = 0;
- clib_spinlock_lock (&evt->handlers_lockp);
+ VCE_HANDLERS_LOCK ();
p = hash_get (evt->handlers_index_by_event_key, evk);
if (!p)
{
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_HANDLERS_UNLOCK ();
return VNET_API_ERROR_NO_SUCH_ENTRY;
}
@@ -187,7 +189,7 @@ vce_unregister_handler (vce_event_thread_t *evt,
pthread_cond_destroy (&(handler->handler_cond));
pool_put (evt->vce_event_handlers, handler);
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_HANDLERS_UNLOCK ();
if (generate_signal)
{
@@ -223,17 +225,17 @@ vce_event_thread_fn (void *arg)
}
/* Remove event */
- clib_spinlock_lock (&(evt->events_lockp));
+ VCE_EVENTS_LOCK ();
clib_fifo_sub1 (evt->event_index_fifo, ev_idx);
ev = vce_get_event_from_index (evt, ev_idx);
ASSERT(ev);
if (recycle_count && ev->recycle)
{
clib_fifo_add1 (evt->event_index_fifo, ev_idx);
- clib_spinlock_unlock (&(evt->events_lockp));
+ VCE_EVENTS_UNLOCK ();
continue;
}
- clib_spinlock_lock (&evt->handlers_lockp);
+ VCE_HANDLERS_LOCK ();
p = hash_get (evt->handlers_index_by_event_key, ev->evk.as_u64);
if (!p)
@@ -242,8 +244,8 @@ vce_event_thread_fn (void *arg)
* does it make any sound?
* I don't know either, so lets biff the event */
pool_put(evt->vce_events, ev);
- clib_spinlock_unlock (&(evt->events_lockp));
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_EVENTS_UNLOCK ();
+ VCE_HANDLERS_UNLOCK ();
pthread_mutex_unlock (&(evt->generator_lock));
}
else
@@ -253,16 +255,16 @@ vce_event_thread_fn (void *arg)
handler->ev_idx = ev_idx;
ev->recycle = 0;
- clib_spinlock_unlock (&(evt->events_lockp));
- clib_spinlock_unlock (&evt->handlers_lockp);
+ VCE_EVENTS_UNLOCK ();
+ VCE_HANDLERS_UNLOCK ();
pthread_mutex_unlock (&(evt->generator_lock));
(handler->handler_fn)(handler);
- clib_spinlock_lock (&(evt->events_lockp));
+ VCE_EVENTS_LOCK ();
ev = vce_get_event_from_index (evt, ev_idx);
recycle_count += (!evt_recycle && ev && ev->recycle) ? 1 : 0;
- clib_spinlock_unlock(&(evt->events_lockp));
+ VCE_EVENTS_UNLOCK ();
}
pthread_mutex_lock (&(evt->generator_lock));