1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef PLATFORM_QUEUE_H 10 #define PLATFORM_QUEUE_H 11 12 #include "hdf_dlist.h" 13 #include "osal_thread.h" 14 #include "osal_sem.h" 15 #include "osal_spinlock.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif /* __cplusplus */ 20 21 struct PlatformMsg; 22 struct PlatformQueue; 23 24 struct PlatformMsg { 25 struct DListHead node; 26 int32_t code; 27 int32_t error; 28 void *data; 29 }; 30 31 typedef int32_t (*PlatformMsgHandle)(struct PlatformQueue *queue, struct PlatformMsg *msg); 32 33 struct PlatformQueue { 34 const char *name; 35 OsalSpinlock spin; 36 bool start; 37 bool exited; 38 struct OsalSem sem; 39 struct DListHead msgs; 40 struct OsalThread thread; /* the worker thread of this queue */ 41 PlatformMsgHandle handle; 42 uint32_t depth; 43 uint32_t depthMax; 44 void *data; 45 }; 46 47 struct PlatformQueue *PlatformQueueCreate(PlatformMsgHandle handle, const char *name, void *data); 48 49 void PlatformQueueDestroy(struct PlatformQueue *queue); 50 51 int32_t PlatformQueueStart(struct PlatformQueue *queue); 52 53 int32_t PlatformQueueAddMsg(struct PlatformQueue *queue, struct PlatformMsg *msg); 54 55 int32_t PlatformQueueGetMsg(struct PlatformQueue *queue, struct PlatformMsg **msg, uint32_t tms); 56 57 #ifdef __cplusplus 58 } 59 #endif /* __cplusplus */ 60 61 #endif /* PLATFORM_QUEUE_H */ 62