All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
src/include/citrusleaf/cf_queue_priority.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 /*
25  * A simple priority queue implementation, which is simply a set of queues underneath.
26  * This currently doesn't support 'delete' and 'reduce' functionality
27  */
28 #include "cf_queue.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /******************************************************************************
35  * CONSTANTS
36  ******************************************************************************/
37 
38 #define CF_QUEUE_PRIORITY_HIGH 1
39 #define CF_QUEUE_PRIORITY_MEDIUM 2
40 #define CF_QUEUE_PRIORITY_LOW 3
41 
42 /******************************************************************************
43  * TYPES
44  ******************************************************************************/
45 
46 typedef struct cf_queue_priority_s cf_queue_priority;
47 
49  bool threadsafe;
50  cf_queue * low_q;
51  cf_queue * medium_q;
52  cf_queue * high_q;
53  pthread_mutex_t LOCK;
54  pthread_cond_t CV;
55 };
56 
57 /******************************************************************************
58  * FUNCTIONS
59  ******************************************************************************/
60 
61 cf_queue_priority *cf_queue_priority_create(size_t elementsz, bool threadsafe);
62 void cf_queue_priority_destroy(cf_queue_priority *q);
63 int cf_queue_priority_push(cf_queue_priority *q, void *ptr, int pri);
64 int cf_queue_priority_pop(cf_queue_priority *q, void *buf, int mswait);
65 int cf_queue_priority_sz(cf_queue_priority *q);
66 int cf_queue_priority_reduce_pop(cf_queue_priority *priority_q, void *buf, cf_queue_reduce_fn cb, void *udata);
67 
68 /******************************************************************************
69  * MACROS
70  ******************************************************************************/
71 
72 #define CF_Q_PRI_EMPTY(__q) (CF_Q_EMPTY(__q->low_q) && CF_Q_EMPTY(__q->medium_q) && CF_Q_EMPTY(__q->high_q))
73 
74 /******************************************************************************/
75 
76 #ifdef __cplusplus
77 } // end extern "C"
78 #endif
int cf_queue_priority_sz(cf_queue_priority *q)
cf_queue_priority * cf_queue_priority_create(size_t elementsz, bool threadsafe)
int(* cf_queue_reduce_fn)(void *buf, void *udata)
int cf_queue_priority_pop(cf_queue_priority *q, void *buf, int mswait)
void cf_queue_priority_destroy(cf_queue_priority *q)
int cf_queue_priority_push(cf_queue_priority *q, void *ptr, int pri)
int cf_queue_priority_reduce_pop(cf_queue_priority *priority_q, void *buf, cf_queue_reduce_fn cb, void *udata)