source:
src/libcfa/concurrency/monitor
@
026bb82
Last change on this file since 026bb82 was 2781e65, checked in by , 7 years ago | |
---|---|
|
|
File size: 1.5 KB |
Rev | Line | |
---|---|---|
[f07e037] | 1 | // -*- Mode: CFA -*- |
2 | // | |
3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo | |
4 | // | |
5 | // The contents of this file are covered under the licence agreement in the | |
6 | // file "LICENCE" distributed with Cforall. | |
7 | // | |
8 | // monitor -- | |
9 | // | |
10 | // Author : Thierry Delisle | |
11 | // Created On : Thd Feb 23 12:27:26 2017 | |
12 | // Last Modified By : Thierry Delisle | |
13 | // Last Modified On : -- | |
14 | // Update Count : 0 | |
15 | // | |
16 | ||
17 | #ifndef MONITOR_H | |
18 | #define MONITOR_H | |
19 | ||
20 | #include "assert" | |
21 | #include "invoke.h" | |
[2781e65] | 22 | #include "stdlib" |
[f07e037] | 23 | |
[cc7f4b1] | 24 | struct __monitor_t { |
[f07e037] | 25 | spinlock lock; |
[cc7f4b1] | 26 | thread * owner; |
[f07e037] | 27 | simple_thread_list entry_queue; |
[cc7f4b1] | 28 | unsigned int recursion; |
[f07e037] | 29 | }; |
30 | ||
[cc7f4b1] | 31 | static inline void ?{}(__monitor_t * this) { |
32 | this->owner = 0; | |
33 | this->recursion = 0; | |
34 | } | |
35 | ||
[2781e65] | 36 | //Basic entering routine |
[cc7f4b1] | 37 | void enter(__monitor_t *); |
38 | void leave(__monitor_t *); | |
[f07e037] | 39 | |
[2781e65] | 40 | //Array entering routine |
41 | void enter(__monitor_t **, int count); | |
42 | void leave(__monitor_t **, int count); | |
43 | ||
[cc7f4b1] | 44 | struct monitor_guard_t { |
[2781e65] | 45 | __monitor_t ** m; |
46 | int count; | |
[51f3798] | 47 | }; |
48 | ||
[2781e65] | 49 | static inline int ?<?(__monitor_t* lhs, __monitor_t* rhs) { |
50 | return ((intptr_t)lhs) < ((intptr_t)rhs); | |
51 | } | |
52 | ||
53 | static inline void ?{}( monitor_guard_t * this, __monitor_t ** m ) { | |
[51f3798] | 54 | this->m = m; |
[2781e65] | 55 | this->count = 1; |
56 | enter( *this->m ); | |
57 | } | |
58 | ||
59 | static inline void ?{}( monitor_guard_t * this, __monitor_t ** m, int count ) { | |
60 | this->m = m; | |
61 | this->count = count; | |
62 | qsort(this->m, count); | |
63 | enter( this->m, this->count ); | |
[51f3798] | 64 | } |
65 | ||
[cc7f4b1] | 66 | static inline void ^?{}( monitor_guard_t * this ) { |
[2781e65] | 67 | leave( this->m, this->count ); |
[51f3798] | 68 | } |
69 | ||
[2781e65] | 70 | |
[f07e037] | 71 | #endif //MONITOR_H |
Note: See TracBrowser
for help on using the repository browser.