source: src/libcfa/concurrency/monitor @ 4aa2fb2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4aa2fb2 was 4aa2fb2, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Added verify macro for asserts only present in debug

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[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
[690f13c]20#include <stddef.h>
21
[f07e037]22#include "assert"
23#include "invoke.h"
[2781e65]24#include "stdlib"
[f07e037]25
[84c52a8]26static inline void ?{}(monitor_desc * this) {
[690f13c]27        this->owner = NULL;
[4aa2fb2]28        this->stack_owner = NULL;
[cc7f4b1]29        this->recursion = 0;
30}
31
32struct monitor_guard_t {
[84c52a8]33        monitor_desc ** m;
[2781e65]34        int count;
[4aa2fb2]35        monitor_desc ** prev_mntrs;
36        unsigned short  prev_count;
[51f3798]37};
38
[84c52a8]39static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
[2781e65]40        return ((intptr_t)lhs) < ((intptr_t)rhs);
41}
42
[5ea06d6]43void ?{}( monitor_guard_t * this, monitor_desc ** m, int count );
44void ^?{}( monitor_guard_t * this );
[51f3798]45
[5ea06d6]46//-----------------------------------------------------------------------------
47// Internal scheduling
[0c78741]48
49struct __condition_criterion_t {
50        bool ready;                                             //Whether or not the criterion is met (True if met)
51        monitor_desc * target;                          //The monitor this criterion concerns
52        struct __condition_node_t * owner;              //The parent node to which this criterion belongs
53        __condition_criterion_t * next;         //Intrusive linked list Next field
54};
55
56struct __condition_node_t {
57        thread_desc * waiting_thread;                   //Thread that needs to be woken when all criteria are met
58        __condition_criterion_t * criteria;     //Array of criteria (Criterions are contiguous in memory)
59        unsigned short count;                           //Number of criterions in the criteria
60        __condition_node_t * next;                      //Intrusive linked list Next field
[be3d020]61        uintptr_t user_info;                            //Custom user info accessible before signalling
[0c78741]62};
63
64struct __condition_blocked_queue_t {
65        __condition_node_t * head;
66        __condition_node_t ** tail;
67};
68
69void ?{}( __condition_blocked_queue_t * );
70void append( __condition_blocked_queue_t *, __condition_node_t * );
71__condition_node_t * pop_head( __condition_blocked_queue_t * );
72
[5ea06d6]73struct condition {
[0c78741]74        __condition_blocked_queue_t blocked;    //Link list which contains the blocked threads as-well as the information needed to unblock them
75        monitor_desc ** monitors;                       //Array of monitor pointers (Monitors are NOT contiguous in memory)
76        unsigned short monitor_count;                   //Number of monitors in the array
[5ea06d6]77};
[51f3798]78
[5ea06d6]79static inline void ?{}( condition * this ) {
80        this->monitors = NULL;
81        this->monitor_count = 0;
82}
[2781e65]83
[1167cd4]84static inline void ^?{}( condition * this ) {
85        free( this->monitors );
86}
87
[be3d020]88void wait( condition * this, uintptr_t user_info = 0 );
89bool signal( condition * this );
90bool signal_block( condition * this );
91static inline bool is_empty( condition * this ) { return !this->blocked.head; }
92uintptr_t front( condition * this );
93
[c81ebf9]94struct __acceptable_t {
95        void (*func)(void);
96        unsigned short count;
97        monitor_desc * monitors[1];
98};
99
100void __accept_internal( unsigned short count, __acceptable_t * acceptables, void (*func)(void) );
101
[4aa2fb2]102#endif //MONITOR_H
Note: See TracBrowser for help on using the repository browser.