亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ringq.c

?? 開發板bios源碼 開發板bios源碼
?? C
字號:
/*
 * ringq.c -- Ring queue buffering module
 *
 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
 *
 * See the file "license.txt" for usage and redistribution license requirements
 *
 * $Id: ringq.c,v 1.2 2001/12/06 16:28:24 bporter Exp $
 */

/******************************** Description *********************************/

/*
 *	A ring queue allows maximum utilization of memory for data storage and is
 *	ideal for input/output buffering.  This module provides a highly efficient
 *	implementation and a vehicle for dynamic strings.
 *
 *	WARNING:  This is a public implementation and callers have full access to
 *	the queue structure and pointers.  Change this module very carefully.
 *
 *	This module follows the open/close model.
 *
 *	Operation of a ringq where rq is a pointer to a ringq :
 *
 *		rq->buflen contains the size of the buffer.
 *		rq->buf will point to the start of the buffer.
 *		rq->servp will point to the first (un-consumed) data byte.
 *		rq->endp will point to the next free location to which new data is added
 *		rq->endbuf will point to one past the end of the buffer.
 *
 *	Eg. If the ringq contains the data "abcdef", it might look like :
 *
 *	+-------------------------------------------------------------------+
 *  |   |   |   |   |   |   |   | a | b | c | d | e | f |   |   |   |   |
 *	+-------------------------------------------------------------------+
 *    ^                           ^                       ^               ^
 *    |                           |                       |               |
 *  rq->buf                    rq->servp               rq->endp      rq->enduf
 *     
 *	The queue is empty when servp == endp.  This means that the queue will hold
 *	at most rq->buflen -1 bytes.  It is the filler's responsibility to ensure
 *	the ringq is never filled such that servp == endp.
 *
 *	It is the filler's responsibility to "wrap" the endp back to point to
 *	rq->buf when the pointer steps past the end.  Correspondingly it is the
 *	consumers responsibility to "wrap" the servp when it steps to rq->endbuf.
 *	The ringqPutc and ringqGetc routines will do this automatically.
 */

/********************************* Includes ***********************************/

#ifdef UEMF
	#include	"uemf.h"
#else
	#include	"basic/basicInternal.h"
#endif

/*********************************** Defines **********************************/
/*
 *	Faster than a function call
 */

#define RINGQ_LEN(rq) \
	((rq->servp > rq->endp) ? \
		(rq->buflen + (rq->endp - rq->servp)) : \
		(rq->endp - rq->servp))

/***************************** Forward Declarations ***************************/

static int	ringqGrow(ringq_t *rq);
static int	getBinBlockSize(int size);

int			ringqGrowCalls = 0;

/*********************************** Code *************************************/
/*
 *	Create a new ringq. "increment" is the amount to increase the size of the
 *	ringq should it need to grow to accomodate data being added. "maxsize" is
 *	an upper limit (sanity level) beyond which the q must not grow. Set maxsize
 *	to -1 to imply no upper limit. The buffer for the ringq is always 
 *	dynamically allocated. Set maxsize
 */

int ringqOpen(ringq_t *rq, int initSize, int maxsize)
{
	int	increment;

	a_assert(rq);
	a_assert(initSize >= 0);

	increment = getBinBlockSize(initSize);
	if ((rq->buf = balloc(B_L, (increment))) == NULL) {
		return -1;
	}
	rq->maxsize = maxsize;
	rq->buflen = increment;
	rq->increment = increment;
	rq->endbuf = &rq->buf[rq->buflen];
	rq->servp = rq->buf;
	rq->endp = rq->buf;
	*rq->servp = '\0';
	return 0;
}

/******************************************************************************/
/*
 *	Delete a ringq and free the ringq buffer.
 */

void ringqClose(ringq_t *rq)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (rq == NULL) {
		return;
	}

	ringqFlush(rq);
	bfree(B_L, (char*) rq->buf);
	rq->buf = NULL;
}

/******************************************************************************/
/*
 *	Return the length of the data in the ringq. Users must fill the queue to 
 *	a high water mark of at most one less than the queue size.
 */

int ringqLen(ringq_t *rq)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (rq->servp > rq->endp) {
		return rq->buflen + rq->endp - rq->servp;
	} else {
		return rq->endp - rq->servp;
	}
}

/******************************************************************************/
/*
 *	Get a byte from the queue
 */

int ringqGetc(ringq_t *rq)
{
	char_t	c;
	char_t*	cp;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (rq->servp == rq->endp) {
		return -1;
	}

	cp = (char_t*) rq->servp;
	c = *cp++;
	rq->servp = (unsigned char *) cp;
	if (rq->servp >= rq->endbuf) {
		rq->servp = rq->buf;
	}
	return c;
}

/******************************************************************************/
/*
 *	Add a char to the queue. Note if being used to store wide strings 
 *	this does not add a trailing '\0'. Grow the q as required.
 */

int ringqPutc(ringq_t *rq, char_t c)
{
	char_t *cp;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if ((ringqPutBlkMax(rq) < (int) sizeof(char_t)) && !ringqGrow(rq)) {
		return -1;
	}

	cp = (char_t*) rq->endp;
	*cp++ = (char_t) c;
	rq->endp = (unsigned char *) cp;
	if (rq->endp >= rq->endbuf) {
		rq->endp = rq->buf;
	}
	return 0;
}

/******************************************************************************/
/*
 *	Insert a wide character at the front of the queue
 */

int ringqInsertc(ringq_t *rq, char_t c)
{
	char_t *cp;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (ringqPutBlkMax(rq) < (int) sizeof(char_t) && !ringqGrow(rq)) {
		return -1;
	}
	if (rq->servp <= rq->buf) {
		rq->servp = rq->endbuf;
	}
	cp = (char_t*) rq->servp;
	*--cp = (char_t) c;
	rq->servp = (unsigned char *) cp;
	return 0;
}

/******************************************************************************/
/*
 *	Add a string to the queue. Add a trailing null (maybe two nulls)
 */

int ringqPutStr(ringq_t *rq, char_t *str)
{
	int		rc;

	a_assert(rq);
	a_assert(str);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	rc = ringqPutBlk(rq, (unsigned char*) str, gstrlen(str) * sizeof(char_t));
	*((char_t*) rq->endp) = (char_t) '\0';
	return rc;
}

/******************************************************************************/
/*
 *	Add a null terminator. This does NOT increase the size of the queue
 */

void ringqAddNull(ringq_t *rq)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	*((char_t*) rq->endp) = (char_t) '\0';
}

/******************************************************************************/
#ifdef UNICODE
/*
 *	Get a byte from the queue
 */

int ringqGetcA(ringq_t *rq)
{
	unsigned char	c;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (rq->servp == rq->endp) {
		return -1;
	}

	c = *rq->servp++;
	if (rq->servp >= rq->endbuf) {
		rq->servp = rq->buf;
	}
	return c;
}

/******************************************************************************/
/*
 *	Add a byte to the queue. Note if being used to store strings this does not
 *	add a trailing '\0'. Grow the q as required.
 */

int ringqPutcA(ringq_t *rq, char c)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (ringqPutBlkMax(rq) == 0 && !ringqGrow(rq)) {
		return -1;
	}

	*rq->endp++ = (unsigned char) c;
	if (rq->endp >= rq->endbuf) {
		rq->endp = rq->buf;
	}
	return 0;
}

/******************************************************************************/
/*
 *	Insert a byte at the front of the queue
 */

int ringqInsertcA(ringq_t *rq, char c)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	if (ringqPutBlkMax(rq) == 0 && !ringqGrow(rq)) {
		return -1;
	}
	if (rq->servp <= rq->buf) {
		rq->servp = rq->endbuf;
	}
	*--rq->servp = (unsigned char) c;
	return 0;
}

/******************************************************************************/
/*
 *	Add a string to the queue. Add a trailing null (not really in the q).
 *	ie. beyond the last valid byte.
 */

int ringqPutStrA(ringq_t *rq, char *str)
{
	int		rc;

	a_assert(rq);
	a_assert(str);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	rc = ringqPutBlk(rq, (unsigned char*) str, strlen(str));
	rq->endp[0] = '\0';
	return rc;
}

#endif /* UNICODE */
/******************************************************************************/
/*
 *	Add a block of data to the ringq. Return the number of bytes added.
 *	Grow the q as required.
 */

int ringqPutBlk(ringq_t *rq, unsigned char *buf, int size)
{
	int		this, bytes_put;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));
	a_assert(buf);
	a_assert(0 <= size);

/*
 *	Loop adding the maximum bytes we can add in a single straight line copy
 */
	bytes_put = 0;
	while (size > 0) {
		this = min(ringqPutBlkMax(rq), size);
		if (this <= 0) {
			if (! ringqGrow(rq)) {
				break;
			}
			this = min(ringqPutBlkMax(rq), size);
		}

		memcpy(rq->endp, buf, this);
		buf += this;
		rq->endp += this;
		size -= this;
		bytes_put += this;

		if (rq->endp >= rq->endbuf) {
			rq->endp = rq->buf;
		}
	}
	return bytes_put;
}

/******************************************************************************/
/*
 *	Get a block of data from the ringq. Return the number of bytes returned.
 */

int ringqGetBlk(ringq_t *rq, unsigned char *buf, int size)
{
	int		this, bytes_read;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));
	a_assert(buf);
	a_assert(0 <= size && size < rq->buflen);

/*
 *	Loop getting the maximum bytes we can get in a single straight line copy
 */
	bytes_read = 0;
	while (size > 0) {
		this = ringqGetBlkMax(rq);
		this = min(this, size);
		if (this <= 0) {
			break;
		}

		memcpy(buf, rq->servp, this);
		buf += this;
		rq->servp += this;
		size -= this;
		bytes_read += this;

		if (rq->servp >= rq->endbuf) {
			rq->servp = rq->buf;
		}
	}
	return bytes_read;
}

/******************************************************************************/
/*
 *	Return the maximum number of bytes the ring q can accept via a single 
 *	block copy. Useful if the user is doing their own data insertion.
 */

int ringqPutBlkMax(ringq_t *rq)
{
	int		space, in_a_line;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));
	
	space = rq->buflen - RINGQ_LEN(rq) - 1;
	in_a_line = rq->endbuf - rq->endp;

	return min(in_a_line, space);
}

/******************************************************************************/
/*
 *	Return the maximum number of bytes the ring q can provide via a single 
 *	block copy. Useful if the user is doing their own data retrieval.
 */

int ringqGetBlkMax(ringq_t *rq)
{
	int		len, in_a_line;

	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));

	len = RINGQ_LEN(rq);
	in_a_line = rq->endbuf - rq->servp;

	return min(in_a_line, len);
}

/******************************************************************************/
/*
 *	Adjust the endp pointer after the user has copied data into the queue.
 */

void ringqPutBlkAdj(ringq_t *rq, int size)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));
	a_assert(0 <= size && size < rq->buflen);

	rq->endp += size;
	if (rq->endp >= rq->endbuf) {
		rq->endp -= rq->buflen;
	}
/*
 *	Flush the queue if the endp pointer is corrupted via a bad size
 */
	if (rq->endp >= rq->endbuf) {
		error(E_L, E_LOG, T("Bad end pointer"));
		ringqFlush(rq);
	}
}

/******************************************************************************/
/*
 *	Adjust the servp pointer after the user has copied data from the queue.
 */

void ringqGetBlkAdj(ringq_t *rq, int size)
{
	a_assert(rq);
	a_assert(rq->buflen == (rq->endbuf - rq->buf));
	a_assert(0 < size && size < rq->buflen);

	rq->servp += size;
	if (rq->servp >= rq->endbuf) {
		rq->servp -= rq->buflen;
	}
/*
 *	Flush the queue if the servp pointer is corrupted via a bad size
 */
	if (rq->servp >= rq->endbuf) {
		error(E_L, E_LOG, T("Bad serv pointer"));
		ringqFlush(rq);
	}
}

/******************************************************************************/
/*
 *	Flush all data in a ring q.  Reset the pointers.
 */

void ringqFlush(ringq_t *rq)
{
	a_assert(rq);
	a_assert(rq->servp);

	rq->servp = rq->buf;
	rq->endp = rq->buf;
	if (rq->servp) {
		*rq->servp = '\0';
	}
}

/******************************************************************************/
/*
 *	Grow the buffer. Return true if the buffer can be grown. Grow using
 *	the increment size specified when opening the ringq. Don't grow beyond
 *	the maximum possible size.
 */

static int ringqGrow(ringq_t *rq)
{
	unsigned char	*newbuf;
	int 			len;

	a_assert(rq);

	if (rq->maxsize >= 0 && rq->buflen >= rq->maxsize) {
		return 0;
	}

	len = ringqLen(rq);

	if ((newbuf = balloc(B_L, rq->buflen + rq->increment)) == NULL) {
		return 0;
	}
	ringqGetBlk(rq, newbuf, ringqLen(rq));
	bfree(B_L, (char*) rq->buf);

#ifdef OLD
	rq->endp = &newbuf[endp];
	rq->servp = &newbuf[servp];
	rq->endbuf = &newbuf[rq->buflen];
	rq->buf = newbuf;
#endif

	rq->buflen += rq->increment;
	rq->endp = newbuf;
	rq->servp = newbuf;
	rq->buf = newbuf;
	rq->endbuf = &rq->buf[rq->buflen];

	ringqPutBlk(rq, newbuf, len);

/*
 *	Double the increment so the next grow will line up with balloc'ed memory
 */
	rq->increment = getBinBlockSize(2 * rq->increment);

	return 1;
}

/******************************************************************************/
/*
 *	Find the smallest binary memory size that "size" will fit into.  This
 *	makes the ringq and ringqGrow routines much more efficient.  The balloc
 *	routine likes powers of 2 minus 1.
 */

static int	getBinBlockSize(int size)
{
	int	q;

	size = size >> B_SHIFT;
	for (q = 0; size; size >>= 1) {
		q++;
	}
	return (1 << (B_SHIFT + q));
}

/******************************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
aaa欧美大片| 国产调教视频一区| 日韩三级视频在线看| 日韩欧美电影在线| 欧美一区二区三区免费| 国产三级欧美三级| 夜夜精品视频一区二区| 亚洲综合一二区| 久久超碰97人人做人人爱| www.欧美日韩| 91浏览器在线视频| 日韩女优电影在线观看| 亚洲天天做日日做天天谢日日欢| 亚洲午夜视频在线观看| 国产在线精品一区二区不卡了 | 欧美日韩国产综合一区二区 | 中文字幕中文字幕一区| 亚洲午夜久久久久久久久久久| 精品午夜久久福利影院| 99国产精品久| 欧美成人精品3d动漫h| 一区二区三区在线视频观看58| 精品一区二区三区不卡 | 免费成人在线网站| 91色九色蝌蚪| 久久久亚洲国产美女国产盗摄 | 国产一区二区三区久久久| 日本道精品一区二区三区| 日韩精品一区二区三区在线 | 国产精品一区二区免费不卡| 欧美精品v日韩精品v韩国精品v| 国产精品免费aⅴ片在线观看| 日韩国产高清在线| 欧美做爰猛烈大尺度电影无法无天| 久久久精品影视| 五月天国产精品| 91久久精品网| 亚洲欧洲日韩综合一区二区| 国产精品综合一区二区三区| 日韩美女一区二区三区四区| 亚洲伊人伊色伊影伊综合网| 91蜜桃免费观看视频| 欧美高清在线一区二区| 国产精品一区二区三区四区| 欧美精品一区二区精品网| 日本欧美一区二区| 欧美精品在线视频| 亚洲成人免费在线| 欧美网站大全在线观看| 亚洲一区二区免费视频| 成人激情免费电影网址| 国产精品久久久久久亚洲毛片| 国内成人自拍视频| 精品久久久久久亚洲综合网| 国产在线观看一区二区| 欧美影片第一页| 亚洲一区国产视频| 欧美精品v日韩精品v韩国精品v| 亚洲国产视频在线| 91丨porny丨最新| 亚洲精品v日韩精品| 在线一区二区观看| 日韩高清在线不卡| 精品久久久久久综合日本欧美 | 91精品国产综合久久久久久| 日韩精品久久理论片| 日韩一区二区在线免费观看| 久草热8精品视频在线观看| 91精品国产一区二区三区| 美女网站色91| 国产欧美一二三区| 色婷婷综合五月| 香蕉加勒比综合久久| 日韩一区二区三区视频| 国产伦精一区二区三区| 亚洲图片激情小说| 欧美日韩国产bt| 青青草91视频| 中文字幕一区av| 欧美久久久久久久久| 国产一区二区三区不卡在线观看| 国产精品久久夜| 欧美视频在线不卡| 国产毛片精品视频| 亚洲一区二区三区在线看| 欧美一级欧美三级在线观看| 福利一区福利二区| 一区二区三区高清不卡| 欧美不卡一二三| 91网上在线视频| 久久成人精品无人区| 亚洲美女在线国产| 欧美剧在线免费观看网站| 国产美女精品在线| 五月天国产精品| 成人免费在线视频| 91精品国产综合久久精品麻豆 | 久久99精品网久久| av午夜一区麻豆| 日本va欧美va精品| 性做久久久久久免费观看欧美| 国产精品久久久久久亚洲毛片| 久久久久久久精| 欧美xxx久久| 日韩美女主播在线视频一区二区三区| 欧美日韩一区二区三区在线看| av在线不卡网| 99天天综合性| 成人av动漫在线| 成人激情av网| 99久久精品国产网站| 成人午夜av在线| 成人成人成人在线视频| 成人av在线影院| 不卡一卡二卡三乱码免费网站| 国产精品自拍三区| 国产精品自在欧美一区| 国产精品99久久久久久宅男| 国产成人综合在线观看| 国产精品99久久久久久久女警| 精品系列免费在线观看| 国产精品一线二线三线精华| 国产精品99久久久久| 成人动漫在线一区| 99re免费视频精品全部| 欧美在线一二三四区| 欧美日韩在线电影| 欧美一区二区三区免费大片| 精品日韩欧美在线| 中文在线一区二区| 亚洲色图欧洲色图婷婷| 亚洲一区二区精品视频| 青青草97国产精品免费观看 | 一区2区3区在线看| 亚洲成人激情综合网| 日韩av二区在线播放| 国产精一区二区三区| 91丝袜呻吟高潮美腿白嫩在线观看| 欧美亚州韩日在线看免费版国语版| 欧美色电影在线| 26uuu亚洲综合色欧美| 国产精品国产自产拍高清av| 洋洋av久久久久久久一区| 日韩福利视频导航| 成人丝袜高跟foot| 欧美色中文字幕| 久久久久高清精品| 亚洲自拍偷拍麻豆| 韩国三级中文字幕hd久久精品| 99久久婷婷国产精品综合| 欧美日韩视频在线第一区 | 欧美人xxxx| 国产丝袜欧美中文另类| 一级中文字幕一区二区| 激情丁香综合五月| 91成人国产精品| 国产婷婷色一区二区三区在线| 亚洲激情五月婷婷| 精品亚洲成a人在线观看| 日本高清不卡一区| 久久欧美一区二区| 亚洲高清免费视频| 福利一区二区在线观看| 欧美一区二区性放荡片| 1区2区3区精品视频| 久久国产精品一区二区| 欧美日精品一区视频| 中文字幕精品一区二区精品绿巨人| 午夜精品久久久久久久久| 成人永久看片免费视频天堂| 欧美一区二区三区视频在线观看| 中文字幕在线观看不卡| 国产美女主播视频一区| 91精品国产91久久久久久一区二区 | 色综合欧美在线视频区| 欧美精品一区二区三区蜜臀| 亚洲制服丝袜av| 国产.欧美.日韩| 日韩欧美在线123| 亚洲国产另类av| 色综合中文字幕国产 | 韩国欧美国产1区| 欧美日韩一区久久| 一区二区三区产品免费精品久久75| 福利视频网站一区二区三区| 欧美一区二区日韩| 日韩精品久久理论片| 欧美性生活久久| 一区二区三区欧美在线观看| 丁香激情综合五月| 久久美女高清视频| 国产精品亚洲人在线观看| 久久女同精品一区二区| 国模少妇一区二区三区| 精品播放一区二区| 国产精品一区二区三区99| 久久久久国产精品麻豆| 国产成人日日夜夜| 国产精品久久久爽爽爽麻豆色哟哟| 国产高清精品久久久久|