source: src/libcfa/concurrency/monitor @ 08da53d

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 08da53d was e5c8488, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Forward declare condition constructors for monitor scheduling

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[f07e037]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 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// monitor --
8//
9// Author           : Thierry Delisle
10// Created On       : Thd Feb 23 12:27:26 2017
[91c389a]11// Last Modified By : Peter A. Buhr
[6b0b624]12// Last Modified On : Sat Jul 22 09:59:01 2017
13// Update Count     : 3
[f07e037]14//
15
[6b0b624]16#pragma once
[f07e037]17
[690f13c]18#include <stddef.h>
19
[91c389a]20#include <assert.h>
[f07e037]21#include "invoke.h"
[2781e65]22#include "stdlib"
[f07e037]23
[1dcd9554]24trait is_monitor(dtype T) {
25        monitor_desc * get_monitor( T & );
26        void ^?{}( T & mutex );
27};
28
[242a902]29static inline void ?{}(monitor_desc & this) {
[6b224a52]30        (this.lock){};
31        (this.entry_queue){};
32        (this.signal_stack){};
[549c006]33        this.owner         = NULL;
34        this.recursion     = 0;
[6ae8c92]35        this.mask.accepted = NULL;
36        this.mask.clauses  = NULL;
37        this.mask.size     = 0;
[549c006]38        this.dtor_node     = NULL;
[cc7f4b1]39}
40
[549c006]41// static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
42//      return ((intptr_t)lhs) < ((intptr_t)rhs);
43// }
44
[cc7f4b1]45struct monitor_guard_t {
[84c52a8]46        monitor_desc ** m;
[2781e65]47        int count;
[4aa2fb2]48        monitor_desc ** prev_mntrs;
49        unsigned short  prev_count;
[90c4df0]50        fptr_t          prev_func;
[51f3798]51};
52
[bf7b9da7]53void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() );
[242a902]54void ^?{}( monitor_guard_t & this );
[51f3798]55
[549c006]56
57struct monitor_dtor_guard_t {
58        monitor_desc * m;
59        monitor_desc ** prev_mntrs;
60        unsigned short  prev_count;
61        fptr_t          prev_func;
62};
63
64void ?{}( monitor_dtor_guard_t & this, monitor_desc ** m, void (*func)() );
65void ^?{}( monitor_dtor_guard_t & this );
66
[5ea06d6]67//-----------------------------------------------------------------------------
68// Internal scheduling
[0c78741]69
70struct __condition_criterion_t {
71        bool ready;                                             //Whether or not the criterion is met (True if met)
72        monitor_desc * target;                          //The monitor this criterion concerns
73        struct __condition_node_t * owner;              //The parent node to which this criterion belongs
74        __condition_criterion_t * next;         //Intrusive linked list Next field
75};
76
77struct __condition_node_t {
78        thread_desc * waiting_thread;                   //Thread that needs to be woken when all criteria are met
79        __condition_criterion_t * criteria;     //Array of criteria (Criterions are contiguous in memory)
80        unsigned short count;                           //Number of criterions in the criteria
81        __condition_node_t * next;                      //Intrusive linked list Next field
[be3d020]82        uintptr_t user_info;                            //Custom user info accessible before signalling
[0c78741]83};
84
85struct __condition_blocked_queue_t {
86        __condition_node_t * head;
87        __condition_node_t ** tail;
88};
89
[e5c8488]90void ?{}(__condition_node_t & this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info );
91void ?{}(__condition_criterion_t & this );
92void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner );
93
[242a902]94void ?{}( __condition_blocked_queue_t & );
[0c78741]95void append( __condition_blocked_queue_t *, __condition_node_t * );
96__condition_node_t * pop_head( __condition_blocked_queue_t * );
97
[5ea06d6]98struct condition {
[0c78741]99        __condition_blocked_queue_t blocked;    //Link list which contains the blocked threads as-well as the information needed to unblock them
100        monitor_desc ** monitors;                       //Array of monitor pointers (Monitors are NOT contiguous in memory)
101        unsigned short monitor_count;                   //Number of monitors in the array
[5ea06d6]102};
[51f3798]103
[242a902]104static inline void ?{}( condition & this ) {
105        this.monitors = NULL;
106        this.monitor_count = 0;
[5ea06d6]107}
[2781e65]108
[242a902]109static inline void ^?{}( condition & this ) {
110        free( this.monitors );
[1167cd4]111}
112
[be3d020]113void wait( condition * this, uintptr_t user_info = 0 );
114bool signal( condition * this );
115bool signal_block( condition * this );
116static inline bool is_empty( condition * this ) { return !this->blocked.head; }
117uintptr_t front( condition * this );
118
[97e3296]119//-----------------------------------------------------------------------------
120// External scheduling
121
[c81ebf9]122struct __acceptable_t {
[aaa4f93]123        __monitor_group_t;
[9f5ecf5]124        bool is_dtor;
[c81ebf9]125};
126
[6ae8c92]127void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
[c81ebf9]128
[6b0b624]129// Local Variables: //
130// mode: c //
131// tab-width: 4 //
132// End: //
Note: See TracBrowser for help on using the repository browser.