source:
src/tests/monitor.c@
31ee19ff
| Last change on this file since 31ee19ff was cb0e6de, checked in by , 9 years ago | |
|---|---|
|
|
| File size: 857 bytes | |
| Rev | Line | |
|---|---|---|
| [3bb51e1] | 1 | #include <fstream> |
| 2 | #include <kernel> | |
| 3 | #include <monitor> | |
| [4a3334cf] | 4 | #include <thread> |
| [3bb51e1] | 5 | |
| 6 | struct global_t { | |
| 7 | int value; | |
| [84c52a8] | 8 | monitor_desc m; |
| [3bb51e1] | 9 | }; |
| 10 | ||
| 11 | void ?{}(global_t * this) { | |
| 12 | this->value = 0; | |
| 13 | } | |
| 14 | ||
| [ef42b143] | 15 | monitor_desc * get_monitor( global_t * this ) { |
| 16 | return &this->m; | |
| 17 | } | |
| 18 | ||
| [3bb51e1] | 19 | static global_t global; |
| 20 | ||
| [ef42b143] | 21 | void increment3( global_t * mutex this ) { |
| 22 | this->value += 1; | |
| 23 | } | |
| 24 | ||
| 25 | void increment2( global_t * mutex this ) { | |
| 26 | increment3( this ); | |
| 27 | } | |
| 28 | ||
| 29 | void increment( global_t * mutex this ) { | |
| 30 | increment2( this ); | |
| [3bb51e1] | 31 | } |
| 32 | ||
| [17af7d1] | 33 | struct MyThread { thread_desc __thrd; }; |
| [3bb51e1] | 34 | |
| 35 | DECL_THREAD(MyThread); | |
| 36 | ||
| 37 | void ?{}( MyThread * this ) {} | |
| [cb0e6de] | 38 | void ^?{}( MyThread * mutex this ) {} |
| [3bb51e1] | 39 | |
| 40 | void main( MyThread* this ) { | |
| [cb0e6de] | 41 | for(int i = 0; i < 1_000_000; i++) { |
| [3bb51e1] | 42 | increment( &global ); |
| 43 | } | |
| 44 | } | |
| 45 | ||
| 46 | int main(int argc, char* argv[]) { | |
| 47 | assert( global.m.entry_queue.tail != NULL ); | |
| 48 | processor p; | |
| 49 | { | |
| 50 | scoped(MyThread) f[4]; | |
| 51 | } | |
| 52 | sout | global.value | endl; | |
| 53 | } |
Note:
See TracBrowser
for help on using the repository browser.