晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /usr/include/bind9/isc/ |
Upload File : |
/*
* 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 https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*
* 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"
*/
#ifndef ISC_QUEUE_H
#define ISC_QUEUE_H 1
#include <stdbool.h>
#include <isc/assertions.h>
#include <isc/mutex.h>
#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 { \
(void) isc_mutex_init(&(queue).taillock); \
(void) 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)); \
(void) isc_mutex_destroy(&(queue).taillock); \
(void) 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)); \
LOCK(&(queue).taillock); \
if ((queue).tail == NULL) { \
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)
#define ISC_QUEUE_UNLINKIFLINKED(queue, elt, link) \
do { \
LOCK(&(queue).headlock); \
LOCK(&(queue).taillock); \
if (ISC_QLINK_LINKED(elt, link)) { \
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_QUEUE_H */