1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _SIMPLE_Q_H_
18 #define _SIMPLE_Q_H_
19 
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 
24 
25 #define SIMPLE_QUEUE_MAX_ELEMENTS 0x0FFFFFFE
26 
27 typedef bool (*SimpleQueueForciblyDiscardCbkF)(void *data, bool onDelete); //return false to reject
28 
29 //SINGLE producer, SINGLE consumer queue. data is copied INTO/OUT of the queue by simpleQueueEnqueue/simpleQueueDequeue
30 
31 struct SimpleQueue* simpleQueueAlloc(uint32_t numEntries, uint32_t entrySz, SimpleQueueForciblyDiscardCbkF forceDiscardCbk);
32 void simpleQueueDestroy(struct SimpleQueue* sq); //will call discard, but in no particular order!
33 bool simpleQueueEnqueue(struct SimpleQueue* sq, const void *data, int length, bool possiblyDiscardable);
34 bool simpleQueueDequeue(struct SimpleQueue* sq, void *dataVal);
35 
36 
37 #endif
38 
39