• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SOFTBUS_CONN_FAIR_PRIORITY_QUEUE_H
17 #define SOFTBUS_CONN_FAIR_PRIORITY_QUEUE_H
18 
19 #include <stdint.h>
20 
21 #include "softbus_error_code.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef enum {
28     CONN_PRIORITY_HIGH = 0,
29     CONN_PRIORITY_MIDDLE,
30     CONN_PRIORITY_LOW,
31     CONN_PRIORITY_BUTT,
32 } ConnPriority;
33 
34 // 'CONN_QUEUE_ITEM_BASE' MUST be declared in first place of concrete queue message
35 #define CONN_QUEUE_ITEM_BASE \
36     int32_t id;              \
37     ConnPriority priority
38 
39 struct ConnQueueItem {
40     CONN_QUEUE_ITEM_BASE;
41 };
42 void ConnQueueItemConstruct(struct ConnQueueItem *item, int32_t id, ConnPriority priority);
43 void ConnQueueItemDestruct(struct ConnQueueItem *item);
44 
45 struct ConnFairPriorityQueue;
46 typedef struct ConnFairPriorityQueue ConnFairPriorityQueue;
47 
48 ConnFairPriorityQueue *ConnCreateQueue(uint32_t size);
49 void ConnDestroyQueue(ConnFairPriorityQueue *queue);
50 int32_t ConnEnqueue(ConnFairPriorityQueue *queue, struct ConnQueueItem *msg, int32_t timeoutMs);
51 int32_t ConnDequeue(ConnFairPriorityQueue *queue, struct ConnQueueItem **out, int32_t timeoutMs);
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 #endif // SOFTBUS_CONN_FAIR_PRIORITY_QUEUE_H
58