summaryrefslogtreecommitdiffstats
path: root/lib/qpnexus.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/qpnexus.h')
-rw-r--r--lib/qpnexus.h64
1 files changed, 37 insertions, 27 deletions
diff --git a/lib/qpnexus.h b/lib/qpnexus.h
index 0cf5a824..38dcbebc 100644
--- a/lib/qpnexus.h
+++ b/lib/qpnexus.h
@@ -22,11 +22,11 @@
#ifndef _ZEBRA_QPNEXUS_H
#define _ZEBRA_QPNEXUS_H
-#include <stdint.h>
+#include "misc.h"
#include <time.h>
-#include <pthread.h>
#include <unistd.h>
#include <errno.h>
+#include <signal.h>
#include "zassert.h"
#include "qpthreads.h"
@@ -34,10 +34,6 @@
#include "mqueue.h"
#include "qpselect.h"
-#ifndef Inline
-#define Inline static inline
-#endif
-
/*==============================================================================
* Quagga Nexus Interface -- qpn_xxxx
*
@@ -46,20 +42,21 @@
* action routines.
*
*/
+enum
+{
+ /* maximum time in seconds to sit in a pselect */
+ MAX_PSELECT_WAIT = 10,
-/* maximum time in seconds to sit in a pselect */
-#define MAX_PSELECT_WAIT 10
-
-/* signal for message queues */
-#define SIGMQUEUE SIGUSR2
+ /* signal for message queues */
+ SIG_INTERRUPT = SIGUSR2,
-/* number of hooks per hook list */
-enum { qpn_hooks_max = 4 } ;
+ /* number of hooks per hook list */
+ qpn_hooks_max = 4,
+} ;
/*==============================================================================
* Data Structures.
*/
-
typedef int qpn_hook_function(void) ; /* dispatch of tasks */
typedef int qpn_init_function(void) ; /* start/stop work */
@@ -74,26 +71,30 @@ typedef struct qpn_nexus* qpn_nexus ;
struct qpn_nexus
{
- /* set true to terminate the thread (eventually) */
+ /* set true to terminate the thread (eventually) */
bool terminate;
- /* true if this is the main thread */
+ /* true if this is the main thread */
bool main_thread;
- /* thread ID */
- qpt_thread_t thread_id;
+ /* thread ID */
+ qpt_thread_t thread_id;
+
+ /* Signal mask for pselect */
+ sigset_t pselect_mask[1] ;
+ int pselect_signal ;
- /* pselect handler */
+ /* pselect handler */
qps_selection selection;
- /* timer pile */
+ /* timer pile */
qtimer_pile pile;
- /* message queue */
+ /* message queue */
mqueue_queue queue;
mqueue_thread_signal mts;
- /* qpthread routine, can override */
+ /* qpthread routine, can override */
void* (*start)(void*);
/* in-thread initialise, can override. Called within the thread after all
@@ -142,17 +143,26 @@ struct qpn_nexus
struct qpn_hook_list background ;
};
+/*------------------------------------------------------------------------------
+ * Each thread that has a qpnexus uses this piece of thread specific data in
+ * order to be able to find its own nexus.
+ */
+qpt_data_t qpn_self ; /* thread specific data */
+
+Inline qpn_nexus
+qpn_find_self(void)
+{
+ return qpt_data_get_value(qpn_self) ;
+} ;
+
/*==============================================================================
* Functions
*/
-
+extern void qpn_init(void) ;
extern qpn_nexus qpn_init_new(qpn_nexus qpn, bool main_thread);
extern void qpn_add_hook_function(qpn_hook_list list, void* hook) ;
extern void qpn_exec(qpn_nexus qpn);
extern void qpn_terminate(qpn_nexus qpn);
-extern qpn_nexus qpn_reset(qpn_nexus qpn, bool free_structure);
-
-#define qpn_reset_free(qpn) qpn_reset(qpn, 1)
-#define qpn_reset_keep(qpn) qpn_reset(qpn, 0)
+extern qpn_nexus qpn_reset(qpn_nexus qpn, free_keep_b free_structure);
#endif /* _ZEBRA_QPNEXUS_H */