5 Star 25 Fork 16

YorkJia / cQueue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

License

MIT License,all the people can use it for free, and thanks for uC/OS.

Usage

cQueue is message queue, is written in ANSI C in order to support as many platforms and compilers as possible.

Data Structure

cQueue using the cQueue struct data type:
/*---------------The cQueue structure ------------------------------------------------------------*/
typedef struct cQueue{          
    void            **QMemory;  /* pointer to message queue storage area                          */                                   
    void            **QStart;   /* pointer to start of queue data                                 */
    void            **QEnd;     /* pointer to end   of queue data                                 */
    void            **QIn;      /* pointer to where next message will be inserted in the queue    */
    void            **QOut;     /* pointer to where next message will be extracted from the queue */
    int             QSize;      /* size of queue -- max number of entries                         */
    int             QEntries;   /* current number of entries in the queue                         */
} cQueue_t;

API function

/*
 * Description  :   create and init the queue.
 *
 * @para[in]    :   start   is a pointer to the base address of the message queue 
 *                          storage area,the stroage area MUST be declare as an array
 *                          of pointers to 'void' as follows
 * 
 *                          void *messageStroage[size]
 *                            
 * @para[in]    :   size    is the number of elements in the storage area
 * 
 * @return      :   the pointer to the new queue
 */
cQueue_t *cQcreate(int size);

/*
 * Description  :   delete the queue, and free the stroage area
 *
 * @para[in]    :   pq      is the pointer to the queue
 *
 * @return      :   NULL
 */
void cQDelete(cQueue_t *pq);

/*
 * Description  :   flush the queue, the queue is like the new create state
 *
 * @para[in]    :   pq      is the pointer to the queue
 *
 * @return      :   NULL
 */
void cQFlush(cQueue_t *pq);

/*
 * Description  :   receive msg from queue, if queue is empty,return NULL
 *
 * @para[in]    :   pq      is the pointer to the queue
 *
 * @para[out]   :   perr    is the pointer to error return
 * 
 * @return      : the pointer to the receive msg.
 */
void *cQRcv(cQueue_t *pq, char *perr);

/*
 * Description  :   send a message to the queue
 *
 * @para[in]    :   pq      is the pointer to the queue
 *
 * @para[in]    :   pmsg    is the pointer to new message to send
 * 
 * @return      :   ERR_Q_NONE      The call was successful and the message was sent
 *                  ERR_Q_FULL      If the queue cannot accept any more messages because it is full.
 */
int cQPost(cQueue_t *pq, void *pmsg);
/*
 * Description  :   send a message to the queue,the message is posted at the FRONT instead of
 *                  the end of the queue. Using cQPostFront() alllows you to send 'priority'
 *                  message.
 *
 * @para[in]    :   pq      is the pointer to the queue
 *
 * @para[in]    :   pmsg    is the pointer to new message to send
 * 
 * @return      :   ERR_Q_NONE      The call was successful and the message was sent
 *                  ERR_Q_FULL      If the queue cannot accept any more messages because it is full.
 */
int cQPostFront(cQueue_t *pq, void *pmsg);

Example

the example.c show the cQueue'function.

Attention

because the type of element in the cQueue struct is (void ), so the message's type can be custom by youself.
MIT License Copyright (c) 2020 YorkJia Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用ANSI C 编写的 消息队列 功能函数。 展开 收起
C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/yorkjia/cQueue.git
git@gitee.com:yorkjia/cQueue.git
yorkjia
cQueue
cQueue
master

搜索帮助