1 | /* |
2 | * Copyright 2008-2018 Aerospike, Inc. |
3 | * |
4 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
5 | * license agreements. |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
8 | * use this file except in compliance with the License. You may obtain a copy of |
9 | * the License at http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
14 | * License for the specific language governing permissions and limitations under |
15 | * the License. |
16 | */ |
17 | #pragma once |
18 | |
19 | /* |
20 | * A simple priority queue implementation, which is simply a set of queues underneath. |
21 | * This currently doesn't support 'delete' and 'reduce' functionality |
22 | */ |
23 | #include <aerospike/as_std.h> |
24 | #include "cf_queue.h" |
25 | |
26 | #ifdef __cplusplus |
27 | extern "C" { |
28 | #endif |
29 | |
30 | /****************************************************************************** |
31 | * CONSTANTS |
32 | ******************************************************************************/ |
33 | |
34 | #define CF_QUEUE_PRIORITY_LOW 1 |
35 | #define CF_QUEUE_PRIORITY_MEDIUM 2 |
36 | #define CF_QUEUE_PRIORITY_HIGH 3 |
37 | |
38 | /****************************************************************************** |
39 | * TYPES |
40 | ******************************************************************************/ |
41 | |
42 | typedef struct cf_queue_priority_s { |
43 | bool threadsafe; |
44 | cf_queue * low_q; |
45 | cf_queue * medium_q; |
46 | cf_queue * high_q; |
47 | pthread_mutex_t LOCK; |
48 | pthread_cond_t CV; |
49 | } cf_queue_priority; |
50 | |
51 | /****************************************************************************** |
52 | * FUNCTIONS |
53 | ******************************************************************************/ |
54 | |
55 | cf_queue_priority *cf_queue_priority_create(size_t element_sz, bool threadsafe); |
56 | void cf_queue_priority_destroy(cf_queue_priority *q); |
57 | int cf_queue_priority_sz(cf_queue_priority *q); |
58 | int cf_queue_priority_push(cf_queue_priority *q, const void *ptr, int pri); |
59 | int cf_queue_priority_pop(cf_queue_priority *q, void *buf, int mswait); |
60 | int cf_queue_priority_reduce_pop(cf_queue_priority *priority_q, void *buf, cf_queue_reduce_fn cb, void *udata); |
61 | int cf_queue_priority_change(cf_queue_priority *priority_q, const void *ptr, int new_pri); |
62 | int cf_queue_priority_reduce_change(cf_queue_priority *priority_q, int new_pri, cf_queue_reduce_fn cb, void *udata); |
63 | |
64 | /****************************************************************************** |
65 | * MACROS |
66 | ******************************************************************************/ |
67 | |
68 | #define CF_Q_PRI_EMPTY(__q) (CF_Q_EMPTY(__q->low_q) && CF_Q_EMPTY(__q->medium_q) && CF_Q_EMPTY(__q->high_q)) |
69 | |
70 | /******************************************************************************/ |
71 | |
72 | #ifdef __cplusplus |
73 | } // end extern "C" |
74 | #endif |
75 | |