pinebuds/utils/lockcqueue/lockcqueue.c

48 lines
1.4 KiB
C
Raw Permalink Normal View History

2022-08-15 04:20:27 -05:00
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
/***
* lock cqueue
* YuLongWang @2015
*/
2022-08-15 04:20:27 -05:00
#include "lockcqueue.h"
#include "cmsis_os.h"
#include "stdio.h"
2022-08-15 04:20:27 -05:00
int lockcqueue_init(struct lockcqueue *q, uint32_t size, uint8_t *buf) {
InitCQueue(&q->cqueue, size, buf);
q->os_mutex_def_name.mutex = q->os_mutex_cb_name;
q->queue_mutex_id = osMutexCreate(&q->os_mutex_def_name);
2022-08-15 04:20:27 -05:00
}
int lockcqueue_enqueue(struct lockcqueue *q, uint8_t *buf, uint32_t size) {
int ret = 0;
osMutexWait(q->queue_mutex_id, osWaitForever);
ret = EnCQueue(&q->cqueue, buf, size);
osMutexRelease(q->queue_mutex_id);
2022-08-15 04:20:27 -05:00
return ret;
2022-08-15 04:20:27 -05:00
}
int lockcqueue_dequeue(struct lockcqueue *q, uint8_t *buf, uint32_t size) {
int ret = 0;
osMutexWait(q->queue_mutex_id, osWaitForever);
ret = DeCQueue(&q->cqueue, buf, size);
osMutexRelease(q->queue_mutex_id);
2022-08-15 04:20:27 -05:00
return ret;
2022-08-15 04:20:27 -05:00
}