ISC_LIST_UNLINK(foolist, foo, link);
-A similar but smaller set of `ISC_QUEUE` macros, including `ISC_QUEUE_PUSH`
-and `ISC_QUEUE_POP`, are provided to implement strict FIFO lists, with
-built-in fine-grained locking.
-
#### <a name="names"></a>Names
The `dns_name` API has facilities for processing DNS names and labels,
#include <isc/buffer.h>
#include <isc/lang.h>
-#include <isc/list.h>
#include <dns/name.h>
#include <isc/atomic.h>
#include <isc/app.h>
#include <isc/condition.h>
-#include <isc/list.h>
#include <isc/mem.h>
#include <isc/mutex.h>
#include <isc/event.h>
#include <isc/assertions.h>
#include <isc/formatcheck.h>
#include <isc/lang.h>
-#include <isc/list.h>
#include <isc/likely.h>
#include <isc/magic.h>
#include <isc/types.h>
/*! \file isc/event.h */
#include <isc/lang.h>
-#include <isc/list.h>
#include <isc/types.h>
/*****
* information regarding copyright ownership.
*/
+
#ifndef ISC_LIST_H
#define ISC_LIST_H 1
-#include <stdbool.h>
-
#include <isc/assertions.h>
-#include <isc/mutex.h>
-#include <isc/types.h>
#ifdef ISC_LIST_CHECKINIT
#define ISC_LINK_INSIST(x) ISC_INSIST(x)
#define ISC_LINK_INSIST(x)
#endif
+#define ISC_LIST(type) struct { type *head, *tail; }
#define ISC_LIST_INIT(list) \
do { (list).head = NULL; (list).tail = NULL; } while (0)
#define __ISC_LIST_DEQUEUEUNSAFE_TYPE(list, elt, link, type) \
__ISC_LIST_UNLINKUNSAFE_TYPE(list, elt, link, type)
-/*
- * This is a generic implementation of a two-lock concurrent queue.
- * There are built-in mutex locks for the head and tail of the queue,
- * allowing elements to be safely added and removed at the same time.
- *
- * NULL is "end of list"
- * -1 is "not linked"
- */
-
-#ifdef ISC_QUEUE_CHECKINIT
-#define ISC_QLINK_INSIST(x) ISC_INSIST(x)
-#else
-#define ISC_QLINK_INSIST(x) (void)0
-#endif
-
-#define ISC_QLINK(type) struct { type *prev, *next; }
-
-#define ISC_QLINK_INIT(elt, link) \
- do { \
- (elt)->link.next = (elt)->link.prev = (void *)(-1); \
- } while(0)
-
-#define ISC_QLINK_LINKED(elt, link) ((void*)(elt)->link.next != (void*)(-1))
-
-#define ISC_QUEUE(type) struct { \
- type *head, *tail; \
- isc_mutex_t headlock, taillock; \
-}
-
-#define ISC_QUEUE_INIT(queue, link) \
- do { \
- isc_mutex_init(&(queue).taillock); \
- isc_mutex_init(&(queue).headlock); \
- (queue).tail = (queue).head = NULL; \
- } while (0)
-
-#define ISC_QUEUE_EMPTY(queue) ((queue).head == NULL)
-
-#define ISC_QUEUE_DESTROY(queue) \
- do { \
- ISC_QLINK_INSIST(ISC_QUEUE_EMPTY(queue)); \
- isc_mutex_destroy(&(queue).taillock); \
- isc_mutex_destroy(&(queue).headlock); \
- } while (0)
-
-/*
- * queues are meant to separate the locks at either end. For best effect, that
- * means keeping the ends separate - i.e. non-empty queues work best.
- *
- * a push to an empty queue has to take the pop lock to update
- * the pop side of the queue.
- * Popping the last entry has to take the push lock to update
- * the push side of the queue.
- *
- * The order is (pop, push), because a pop is presumably in the
- * latency path and a push is when we're done.
- *
- * We do an MT hot test in push to see if we need both locks, so we can
- * acquire them in order. Hopefully that makes the case where we get
- * the push lock and find we need the pop lock (and have to release it) rare.
- *
- * > 1 entry - no collision, push works on one end, pop on the other
- * 0 entry - headlock race
- * pop wins - return(NULL), push adds new as both head/tail
- * push wins - updates head/tail, becomes 1 entry case.
- * 1 entry - taillock race
- * pop wins - return(pop) sets head/tail NULL, becomes 0 entry case
- * push wins - updates {head,tail}->link.next, pop updates head
- * with new ->link.next and doesn't update tail
- *
- */
-#define ISC_QUEUE_PUSH(queue, elt, link) \
- do { \
- bool headlocked = false; \
- ISC_QLINK_INSIST(!ISC_QLINK_LINKED(elt, link)); \
- if ((queue).head == NULL) { \
- LOCK(&(queue).headlock); \
- headlocked = true; \
- } \
- LOCK(&(queue).taillock); \
- if ((queue).tail == NULL && !headlocked) { \
- UNLOCK(&(queue).taillock); \
- LOCK(&(queue).headlock); \
- LOCK(&(queue).taillock); \
- headlocked = true; \
- } \
- (elt)->link.prev = (queue).tail; \
- (elt)->link.next = NULL; \
- if ((queue).tail != NULL) \
- (queue).tail->link.next = (elt); \
- (queue).tail = (elt); \
- UNLOCK(&(queue).taillock); \
- if (headlocked) { \
- if ((queue).head == NULL) \
- (queue).head = (elt); \
- UNLOCK(&(queue).headlock); \
- } \
- } while (0)
-
-#define ISC_QUEUE_POP(queue, link, ret) \
- do { \
- LOCK(&(queue).headlock); \
- ret = (queue).head; \
- while (ret != NULL) { \
- if (ret->link.next == NULL) { \
- LOCK(&(queue).taillock); \
- if (ret->link.next == NULL) { \
- (queue).head = (queue).tail = NULL; \
- UNLOCK(&(queue).taillock); \
- break; \
- }\
- UNLOCK(&(queue).taillock); \
- } \
- (queue).head = ret->link.next; \
- (queue).head->link.prev = NULL; \
- break; \
- } \
- UNLOCK(&(queue).headlock); \
- if (ret != NULL) \
- (ret)->link.next = (ret)->link.prev = (void *)(-1); \
- } while(0)
-
-#define ISC_QUEUE_UNLINK(queue, elt, link) \
- do { \
- ISC_QLINK_INSIST(ISC_QLINK_LINKED(elt, link)); \
- LOCK(&(queue).headlock); \
- LOCK(&(queue).taillock); \
- if ((elt)->link.prev == NULL) \
- (queue).head = (elt)->link.next; \
- else \
- (elt)->link.prev->link.next = (elt)->link.next; \
- if ((elt)->link.next == NULL) \
- (queue).tail = (elt)->link.prev; \
- else \
- (elt)->link.next->link.prev = (elt)->link.prev; \
- UNLOCK(&(queue).taillock); \
- UNLOCK(&(queue).headlock); \
- (elt)->link.next = (elt)->link.prev = (void *)(-1); \
- } while(0)
-
#endif /* ISC_LIST_H */
#include <stdbool.h>
#include <isc/lang.h>
-#include <isc/list.h>
#include <isc/net.h>
#include <isc/types.h>
#ifdef ISC_PLATFORM_HAVESYSUNH
*/
#include <inttypes.h>
#include <stdbool.h>
-
-#include <isc/lang.h>
#include <isc/offset.h>
-/* Core Types. Alphabetized by defined type. */
-
/*
- * Defined here so we don't need to include list.h.
+ * XXXDCL This is just for ISC_LIST and ISC_LINK, but gets all of the other
+ * list macros too.
*/
-#define ISC_LIST(type) struct { type *head, *tail; }
+#include <isc/list.h>
+
+/* Core Types. Alphabetized by defined type. */
typedef struct isc_astack isc_astack_t; /*%< Array-based fast stack */
typedef struct isc_appctx isc_appctx_t; /*%< Application context */
tap_test_program{name='netaddr_test'}
tap_test_program{name='parse_test'}
tap_test_program{name='pool_test'}
-tap_test_program{name='queue_test'}
tap_test_program{name='radix_test'}
tap_test_program{name='regex_test'}
tap_test_program{name='result_test'}
counter_test.c crc64_test.c errno_test.c file_test.c hash_test.c \
heap_test.c hmac_test.c ht_test.c lex_test.c \
mem_test.c md_test.c netaddr_test.c parse_test.c pool_test.c \
- queue_test.c radix_test.c random_test.c \
+ radix_test.c random_test.c \
regex_test.c result_test.c safe_test.c siphash_test.c sockaddr_test.c \
socket_test.c socket_test.c symtab_test.c task_test.c \
taskpool_test.c time_test.c timer_test.c
ht_test@EXEEXT@ \
lex_test@EXEEXT@ mem_test@EXEEXT@ md_test@EXEEXT@ \
netaddr_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
- queue_test@EXEEXT@ radix_test@EXEEXT@ \
+ radix_test@EXEEXT@ \
random_test@EXEEXT@ regex_test@EXEEXT@ result_test@EXEEXT@ \
safe_test@EXEEXT@ siphash_test@EXEEXT@ sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \
socket_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
${LDFLAGS} -o $@ pool_test.@O@ isctest.@O@ \
${ISCLIBS} ${LIBS}
-queue_test@EXEEXT@: queue_test.@O@ isctest.@O@ ${ISCDEPLIBS}
- ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
- ${LDFLAGS} -o $@ queue_test.@O@ isctest.@O@ \
- ${ISCLIBS} ${LIBS}
-
radix_test@EXEEXT@: radix_test.@O@ isctest.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
${LDFLAGS} -o $@ radix_test.@O@ isctest.@O@ \
+++ /dev/null
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * See the COPYRIGHT file distributed with this work for additional
- * information regarding copyright ownership.
- */
-
-#if HAVE_CMOCKA
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-
-#include <sched.h> /* IWYU pragma: keep */
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#define UNIT_TESTING
-#include <cmocka.h>
-
-#include <isc/list.h>
-#include <isc/util.h>
-
-#include "isctest.h"
-
-static int
-_setup(void **state) {
- isc_result_t result;
-
- UNUSED(state);
-
- result = isc_test_begin(NULL, true, 0);
- assert_int_equal(result, ISC_R_SUCCESS);
-
- return (0);
-}
-
-static int
-_teardown(void **state) {
- UNUSED(state);
-
- isc_test_end();
-
- return (0);
-}
-
-typedef struct item item_t;
-struct item {
- int value;
- ISC_QLINK(item_t) qlink;
-};
-
-typedef ISC_QUEUE(item_t) item_queue_t;
-
-static void
-item_init(item_t *item, int value) {
- item->value = value;
- ISC_QLINK_INIT(item, qlink);
-}
-
-/* Test UDP sendto/recv (IPv4) */
-static void
-queue_valid(void **state) {
- item_queue_t queue;
- item_t one, two, three, four, five;
- item_t *p;
-
- UNUSED(state);
-
- ISC_QUEUE_INIT(queue, qlink);
-
- item_init(&one, 1);
- item_init(&two, 2);
- item_init(&three, 3);
- item_init(&four, 4);
- item_init(&five, 5);
-
- assert_true(ISC_QUEUE_EMPTY(queue));
-
- ISC_QUEUE_POP(queue, qlink, p);
- assert_null(p);
-
- assert_false(ISC_QLINK_LINKED(&one, qlink));
- ISC_QUEUE_PUSH(queue, &one, qlink);
- assert_true(ISC_QLINK_LINKED(&one, qlink));
-
- assert_false(ISC_QUEUE_EMPTY(queue));
-
- ISC_QUEUE_POP(queue, qlink, p);
- assert_non_null(p);
- assert_int_equal(p->value, 1);
- assert_true(ISC_QUEUE_EMPTY(queue));
- assert_false(ISC_QLINK_LINKED(p, qlink));
-
- ISC_QUEUE_PUSH(queue, p, qlink);
- assert_false(ISC_QUEUE_EMPTY(queue));
- assert_true(ISC_QLINK_LINKED(p, qlink));
-
- assert_false(ISC_QLINK_LINKED(&two, qlink));
- ISC_QUEUE_PUSH(queue, &two, qlink);
- assert_true(ISC_QLINK_LINKED(&two, qlink));
-
- assert_false(ISC_QLINK_LINKED(&three, qlink));
- ISC_QUEUE_PUSH(queue, &three, qlink);
- assert_true(ISC_QLINK_LINKED(&three, qlink));
-
- assert_false(ISC_QLINK_LINKED(&four, qlink));
- ISC_QUEUE_PUSH(queue, &four, qlink);
- assert_true(ISC_QLINK_LINKED(&four, qlink));
-
- assert_false(ISC_QLINK_LINKED(&five, qlink));
- ISC_QUEUE_PUSH(queue, &five, qlink);
- assert_true(ISC_QLINK_LINKED(&five, qlink));
-
- /* Test unlink by removing one item from the middle */
- ISC_QUEUE_UNLINK(queue, &three, qlink);
-
- ISC_QUEUE_POP(queue, qlink, p);
- assert_non_null(p);
- assert_int_equal(p->value, 1);
-
- ISC_QUEUE_POP(queue, qlink, p);
- assert_non_null(p);
- assert_int_equal(p->value, 2);
-
- ISC_QUEUE_POP(queue, qlink, p);
- assert_non_null(p);
- assert_int_equal(p->value, 4);
-
- ISC_QUEUE_POP(queue, qlink, p);
- assert_non_null(p);
- assert_int_equal(p->value, 5);
-
- assert_null(queue.head);
- assert_null(queue.tail);
- assert_true(ISC_QUEUE_EMPTY(queue));
-
- ISC_QUEUE_DESTROY(queue);
-}
-
-int
-main(void) {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(queue_valid,
- _setup, _teardown),
- };
-
- return (cmocka_run_group_tests(tests, NULL, NULL));
-}
-
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
- printf("1..0 # Skipped: cmocka not available\n");
- return (0);
-}
-
-#endif
#include <isc/formatcheck.h>
#include <isc/fuzz.h>
#include <isc/hmac.h>
-#include <isc/list.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/nonce.h>
#include <stdbool.h>
#include <isc/buffer.h>
-#include <isc/list.h>
#include <isc/magic.h>
#include <isc/netmgr.h>
#include <isc/stdtime.h>
* information regarding copyright ownership.
*/
-#include <isc/list.h>
#include <isc/log.h>
#include <isc/print.h>
./lib/isc/tests/netaddr_test.c C 2016,2018,2019
./lib/isc/tests/parse_test.c C 2012,2013,2016,2018,2019
./lib/isc/tests/pool_test.c C 2013,2016,2018,2019
-./lib/isc/tests/queue_test.c C 2011,2012,2016,2018,2019
./lib/isc/tests/radix_test.c C 2014,2016,2018,2019
./lib/isc/tests/random_test.c C 2014,2015,2016,2017,2018,2019
./lib/isc/tests/regex_test.c C 2013,2015,2016,2018,2019