ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since 4868be4 was 51f3798, checked in by Thierry Delisle <tdelisle@…>, 9 years ago |
Added raii guard for monitors
|
-
Property mode
set to
100644
|
File size:
879 bytes
|
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"
|
---|
| 22 |
|
---|
| 23 | struct monitor {
|
---|
| 24 | spinlock lock;
|
---|
| 25 | thread * holder;
|
---|
| 26 | simple_thread_list entry_queue;
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | void enter(monitor *);
|
---|
| 30 | void leave(monitor *);
|
---|
| 31 |
|
---|
[51f3798] | 32 | struct monitor_guard {
|
---|
| 33 | monitor * m;
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | static inline void ?{}( monitor_guard * this, monitor * m ) {
|
---|
| 37 | this->m = m;
|
---|
| 38 | enter( this->m );
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | static inline void ^?{}( monitor_guard * this ) {
|
---|
| 42 | leave( this->m );
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[f07e037] | 45 | #endif //MONITOR_H
|
---|
Note:
See
TracBrowser
for help on using the repository browser.