1 | /* |
---|
2 | * swift_deque.h |
---|
3 | * |
---|
4 | * (c) 2009 Ionut Rosoiu <ionut.rosoiu@gmail.com> |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef SWIFT_DEQUE_H_ |
---|
9 | #define SWIFT_DEQUE_H_ |
---|
10 | |
---|
11 | #include "swift_atomic.h" |
---|
12 | #include "swift_common.h" |
---|
13 | #include "swift_dfg.h" |
---|
14 | #include "swift_declarations.h" |
---|
15 | #include "swift_memory.h" |
---|
16 | |
---|
17 | #define SWIFT_DEQUE_EMPTY (SWIFT_LAST_STATUS_NO - 1) |
---|
18 | #define SWIFT_DEQUE_FULL (SWIFT_DEQUE_EMPTY - 1) |
---|
19 | #define SWIFT_DEQUE_ABORT (SWIFT_DEQUE_EMPTY - 2) |
---|
20 | |
---|
21 | #define SWIFT_DEQUE_SIZE 30000 |
---|
22 | //9128 |
---|
23 | |
---|
24 | struct swift_deque { |
---|
25 | swift_size_t size; /*< the real size */ |
---|
26 | char _pad1[SWIFT_CACHE_LINE_SIZE - sizeof(swift_size_t)]; |
---|
27 | |
---|
28 | swift_size_t size_mask; /*< size-1 used for calculating faster the modulo size */ |
---|
29 | char _pad2[SWIFT_CACHE_LINE_SIZE - sizeof(swift_size_t)]; |
---|
30 | |
---|
31 | volatile swift_dword_t top; /*< top index (only incremented; written only by the owner) */ |
---|
32 | char _pad3[SWIFT_CACHE_LINE_SIZE - sizeof(swift_dword_t)]; |
---|
33 | |
---|
34 | volatile swift_dword_t top_cached; /*< cached value for the top (top bound) */ |
---|
35 | char _pad4[SWIFT_CACHE_LINE_SIZE - sizeof(swift_dword_t)]; |
---|
36 | |
---|
37 | volatile swift_dword_t bottom; /*< bottom index */ |
---|
38 | char _pad5[SWIFT_CACHE_LINE_SIZE - sizeof(swift_dword_t)]; |
---|
39 | |
---|
40 | swift_frame_t **elements; /*< the circular array of frames */ |
---|
41 | char _pad6[SWIFT_CACHE_LINE_SIZE - sizeof(swift_frame_t **)]; |
---|
42 | }; |
---|
43 | |
---|
44 | #include "swift_allocator.h" |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | * Initializes the deque |
---|
49 | */ |
---|
50 | void swift_deque_init(swift_thread_t *thread, |
---|
51 | swift_deque_t *q, |
---|
52 | swift_size_t size); |
---|
53 | |
---|
54 | /** |
---|
55 | * Push a frame at the bottom of the deque |
---|
56 | * @returns status == FULL when queue is full |
---|
57 | */ |
---|
58 | void swift_deque_push(swift_deque_t *q, |
---|
59 | swift_frame_t *frame, |
---|
60 | swift_status_t *status); |
---|
61 | |
---|
62 | /** |
---|
63 | * Pop a frame from the bottom of the deque |
---|
64 | * @returns The pushed frame or NULL in case of failure (status == EMPTY) |
---|
65 | */ |
---|
66 | swift_frame_t* swift_deque_pop(swift_deque_t *q, |
---|
67 | swift_status_t *status); |
---|
68 | |
---|
69 | /** |
---|
70 | * Steal a frame from the top of the deque |
---|
71 | * @returns The frame stolen or NULL in case of failure (status == (EMPTY || ABORT)) |
---|
72 | */ |
---|
73 | swift_frame_t* swift_deque_steal(swift_deque_t *q, |
---|
74 | swift_status_t *status); |
---|
75 | |
---|
76 | void swift_deque_destroy(swift_thread_t *thread, |
---|
77 | swift_deque_t *q); |
---|
78 | |
---|
79 | #endif /* SWIFT_DEQUE_H_ */ |
---|