From 3690074a486cfada568975e287d9cbb9e687501f Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Fri, 2 Sep 2011 00:53:59 +0100 Subject: Merging of euro_ix branch into pipework. Bring in fixes for bgp dumping with pthreaded BGP Engine. Bring in new "show nexus xxx" command. Fix removal of '~' prompt. --- lib/qpthreads.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 6 deletions(-) (limited to 'lib/qpthreads.h') diff --git a/lib/qpthreads.h b/lib/qpthreads.h index d05f7e34..6b9c5741 100644 --- a/lib/qpthreads.h +++ b/lib/qpthreads.h @@ -106,16 +106,18 @@ enum { qpthreads_debug = QPTHREADS_DEBUG } ; /*============================================================================== * Data types */ -typedef pthread_t qpt_thread_t ; +typedef pthread_t qpt_thread_t ; -typedef pthread_mutex_t qpt_mutex_t[1] ; -typedef pthread_mutex_t* qpt_mutex ; +typedef pthread_mutex_t qpt_mutex_t[1] ; +typedef pthread_mutex_t* qpt_mutex ; -typedef pthread_cond_t qpt_cond_t[1] ; -typedef pthread_cond_t* qpt_cond ; +typedef pthread_cond_t qpt_cond_t[1] ; +typedef pthread_cond_t* qpt_cond ; -typedef pthread_attr_t qpt_thread_attr_t ; +typedef pthread_attr_t qpt_thread_attr_t ; +typedef pthread_spinlock_t qpt_spin_t ; +typedef qpt_spin_t* qpt_spin ; /*============================================================================== * Thread Creation -- see qpthreads.c for further discussion. @@ -324,6 +326,30 @@ qpt_cond_signal(qpt_cond cv) ; Inline void /* do nothing if !qpthreads_enabled */ qpt_cond_broadcast(qpt_cond cv) ; +/*============================================================================== + * Spinlock handling + * + * Spinlocks are pretty trivial -- requiring only to be initialised, locked, + * unlocked and, finally, destroyed. + * + * NB: recursive spinlocks are not supported ! + * + * NB: if NOT qpthreads_enabled, locking and unlocking always succeed. This + * allows code to be made thread-safe for when pthreads is running, but to + * work perfectly well without pthreads. + */ +extern void /* freezes qpthreads_enabled */ +qpt_spin_init(qpt_spin slk) ; + +extern void /* do nothing if !qpthreads_enabled */ +qpt_spin_destroy(qpt_spin slk) ; + +Inline void /* do nothing if !qpthreads_enabled */ +qpt_spin_lock(qpt_spin slk) ; + +Inline void /* do nothing if !qpthreads_enabled */ +qpt_spin_unlock(qpt_spin slk) ; + /*============================================================================== * Mutex inline functions */ @@ -442,6 +468,50 @@ qpt_cond_broadcast(qpt_cond cv) } ; } ; +/*============================================================================== + * Spinlock inline functions + */ + +/* Lock spinlock -- do nothing if !qpthreads_enabled + * + * Unless both NCHECK_QPTHREADS and NDEBUG are defined, checks that the + * return value is valid -- zabort_errno if it isn't. + */ +Inline void +qpt_spin_lock(qpt_spin slk) +{ + if (qpthreads_enabled) + { +#if defined(NDEBUG) && defined(NDEBUG_QPTHREADS) + pthread_spin_lock(slk) ; +#else + int err = pthread_spin_lock(slk) ; + if (err != 0) + zabort_err("pthread_spin_lock failed", err) ; +#endif + } ; +} ; + +/* Unlock spinlock -- do nothing if !qpthreads_enabled + * + * Unless both NCHECK_QPTHREADS and NDEBUG are defined, checks that the + * return value is valid -- zabort_errno if it isn't. + */ +Inline void +qpt_spin_unlock(qpt_spin slk) +{ + if (qpthreads_enabled) + { +#if defined(NDEBUG) && defined(NDEBUG_QPTHREADS) + pthread_spin_unlock(slk) ; +#else + int err = pthread_spin_unlock(slk) ; + if (err != 0) + zabort_err("pthread_spin_unlock failed", err) ; +#endif + } ; +} ; + /*============================================================================== * Signal Handling. */ -- cgit v1.2.3