summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/plist.c45
-rw-r--r--lib/qpnexus.c18
-rw-r--r--lib/qpnexus.h6
3 files changed, 44 insertions, 25 deletions
diff --git a/lib/plist.c b/lib/plist.c
index 41868e96..85ff35f8 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -700,18 +700,24 @@ prefix_list_entry_lookup_seq(struct prefix_list *plist, int seq, int* result)
*
* Returns index of an entry in the prefix_list or the dup_cache, and sets:
*
- * cache -- NULL if not using dup_cache for this prefix_list.
- * The index and result values refer to the main prefix_list.
+ * cache -- NULL if not using dup_cache for this prefix_list.
+ * The index and result values refer to the main prefix_list.
*
- * -- address of the cache (a vector).
- * The index and result values refer to the cache. << NB
+ * result < 0 -- not found. prefix list is empty, index == 0
+ * result == 0 -- found. index is of the prefix list entry
+ * result > 0 -- not found. prefix is not empty, index == last
*
- * result < 0 -- not found. index returned is of first entry in the
- * prefix list, and this sequence number comes
- * before it. (Or list is empty.)
- * result == 0 -- found. index is of the entry found.
- * result > 0 -- not found. index returned is of the entry with the largest
- * sequence number smaller than the given one.
+ * -- address of the cache (a vector).
+ * The index and result values refer to the *cache*. << NB
+ *
+ * result < 0 -- not found. index == 0, prefix value given is
+ * less than first entry in the *cache*
+ * result == 0 -- found. index is of the *cache* entry
+ * result > 0 -- not found. index is of entry in the *cache*
+ * with the largest prefix value less
+ * than the given prefix value.
+ *
+ * Note that the cache is never empty.
*/
static vector_index
prefix_list_entry_lookup_val(struct prefix_list *plist,
@@ -749,7 +755,9 @@ prefix_list_entry_lookup_val(struct prefix_list *plist,
if (plist->cmp(&pe, &temp) == 0)
return i ; /* Found ! */
} ;
- *result = 1 ; /* Not found. */
+
+ *result = (vector_end(&plist->list) == 0) ? -1 : +1 ;
+ /* Not found. */
return i ;
} ;
} ;
@@ -855,16 +863,21 @@ prefix_list_entry_insert(struct prefix_list *plist,
i = prefix_list_entry_lookup_seq(plist, temp->seq, &ret) ;
else
{
- int last_seq = 0 ;
+ int last_seq ;
i = vector_end(&plist->list) ;
- if (i != 0)
+ if (i == 0)
+ {
+ last_seq = 0 ; /* initial value for empty list */
+ ret = -1 ; /* insert before first item of empty list */
+ }
+ else
{
- --i ; /* step back to last entry */
+ --i ; /* step back to last entry */
pe = vector_get_item(&plist->list, i) ;
- last_seq = pe->seq ;
+ last_seq = pe->seq ;
+ ret = 1 ; /* insert after last entry */
} ;
temp->seq = (((last_seq + 5 - 1) / 5) * 5) + 5 ;
- ret = 1 ; /* insert after last entry (if any) */
} ;
/* If we found it with same sequence number, then replace entry,
diff --git a/lib/qpnexus.c b/lib/qpnexus.c
index 59dcc535..3b014be2 100644
--- a/lib/qpnexus.c
+++ b/lib/qpnexus.c
@@ -53,7 +53,7 @@ static void qpn_in_thread_init(qpn_nexus qpn);
* Returns the qpn_nexus.
*/
extern qpn_nexus
-qpn_init_new(qpn_nexus qpn, int main_thread)
+qpn_init_new(qpn_nexus qpn, bool main_thread)
{
if (qpn == NULL)
qpn = XCALLOC(MTYPE_QPN_NEXUS, sizeof(struct qpn_nexus)) ;
@@ -309,13 +309,19 @@ qpn_in_thread_init(qpn_nexus qpn)
}
/*------------------------------------------------------------------------------
- * Ask the thread to terminate itself quickly and cleanly
+ * Ask the thread to terminate itself quickly and cleanly.
+ *
+ * Does nothing if terminate already set.
*/
void
qpn_terminate(qpn_nexus qpn)
{
- qpn->terminate = 1;
- /* wake up any pselect */
- if (qpthreads_enabled)
- qpt_thread_signal(qpn->thread_id, SIGMQUEUE);
+ if (!qpn->terminate)
+ {
+ qpn->terminate = true ;
+
+ /* wake up any pselect */
+ if (qpthreads_enabled)
+ qpt_thread_signal(qpn->thread_id, SIGMQUEUE);
+ } ;
}
diff --git a/lib/qpnexus.h b/lib/qpnexus.h
index f4195a4d..0cf5a824 100644
--- a/lib/qpnexus.h
+++ b/lib/qpnexus.h
@@ -75,10 +75,10 @@ typedef struct qpn_nexus* qpn_nexus ;
struct qpn_nexus
{
/* set true to terminate the thread (eventually) */
- int terminate;
+ bool terminate;
/* true if this is the main thread */
- int main_thread;
+ bool main_thread;
/* thread ID */
qpt_thread_t thread_id;
@@ -146,7 +146,7 @@ struct qpn_nexus
* Functions
*/
-extern qpn_nexus qpn_init_new(qpn_nexus qpn, int main_thread);
+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);