source: libcfa/src/concurrency/barrier.hfa @ 93b8cf4

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 93b8cf4 was 93b8cf4, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Added a simple barrier and accompagnying tests.

  • Property mode set to 100644
File size: 795 bytes
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// barrier.hfa -- simple barrier implemented from monitors
8//
9// Author           : Thierry Delisle
10// Created On       : Thu Mar 31 16:51:35 2022
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#pragma once
17
18#include <monitor.hfa>
19
20monitor barrier {
21        int max;
22        int count;
23
24        condition c;
25};
26
27void ?{}( barrier & this, int max ) {
28        this.max = max;
29        this.count = max;
30}
31
32static inline int block(barrier & mutex this ) {
33        this.count -= 1;
34        int arrival = this.count;
35        if(arrival != 0) {
36                wait(this.c);
37        } else {
38                signal_all(this.c);
39                this.count = this.max;
40        }
41        return arrival;
42}
Note: See TracBrowser for help on using the repository browser.