aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2009-04-18 16:15:42 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2009-04-18 16:15:42 -0400
commitcfca2b1dc8d5d9e195e29ae4e62df7a09ab2d579 (patch)
tree93d1793b4e9246cfadf1df5c1e62781d267d4f5b /include
parentc7b59d1e59d066c5b7f1b950b85b4e0314cc19b6 (diff)
litmus core: add concurrent heap impl.
Diffstat (limited to 'include')
-rw-r--r--include/litmus/cheap.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/litmus/cheap.h b/include/litmus/cheap.h
new file mode 100644
index 0000000000..39c29fb0ab
--- /dev/null
+++ b/include/litmus/cheap.h
@@ -0,0 +1,62 @@
1/* cheap.h -- A concurrent heap implementation.
2 *
3 * (c) 2009 Bjoern B. Brandenburg, <bbb@cs.unc.edu>
4 *
5 * Based on:
6 *
7 * G. Hunt, M. Micheal, S. Parthasarath, and M. Scott
8 * "An efficient algorithm for concurrent priority queue heaps."
9 * Information Processing Letters, 60(3): 151-157, November 1996
10 */
11
12#ifndef CHEAP_H
13
14#include "linux/spinlock.h"
15
16#define CHEAP_EMPTY 0xffffffff
17#define CHEAP_READY 0xffffff00
18#define CHEAP_ROOT 0
19
20struct cheap_node {
21 spinlock_t lock;
22
23 unsigned int tag;
24 void* value;
25};
26
27struct cheap {
28 spinlock_t lock;
29
30 unsigned int next;
31 unsigned int size;
32
33 struct cheap_node* heap;
34};
35
36typedef int (*cheap_prio_t)(void* a, void* b);
37
38void cheap_init(struct cheap* ch,
39 unsigned int size,
40 struct cheap_node* nodes);
41
42int cheap_insert(cheap_prio_t higher_prio,
43 struct cheap* ch,
44 void* item,
45 int pid);
46
47void* cheap_peek(struct cheap* ch);
48
49typedef int (*cheap_take_predicate_t)(void* ctx, void* value);
50
51void* cheap_take_if(cheap_take_predicate_t pred,
52 void* pred_ctx,
53 cheap_prio_t higher_prio,
54 struct cheap* ch);
55
56static inline void* cheap_take(cheap_prio_t higher_prio,
57 struct cheap* ch)
58{
59 return cheap_take_if(NULL, NULL, higher_prio, ch);
60}
61
62#endif