source: src/libcfa/concurrency/monitor @ 90c4df0

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 90c4df0 was 90c4df0, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Implemented search for external scheduling

  • Property mode set to 100644
File size: 3.3 KB
Line 
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
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:59:01 2017
13// Update Count     : 3
14//
15
16#pragma once
17
18#include <stddef.h>
19
20#include <assert.h>
21#include "invoke.h"
22#include "stdlib"
23
24static inline void ?{}(monitor_desc * this) {
25        (&this->lock){};
26        this->owner = NULL;
27        (&this->entry_queue){};
28        (&this->signal_stack){};
29        this->recursion = 0;
30        this->acceptables = NULL;
31        this->acceptable_count = 0;
32        this->accepted_index = -1;
33        this->pre_accept = 0;
34}
35
36struct monitor_guard_t {
37        monitor_desc ** m;
38        int count;
39        monitor_desc ** prev_mntrs;
40        unsigned short  prev_count;
41        fptr_t          prev_func;
42};
43
44static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
45        return ((intptr_t)lhs) < ((intptr_t)rhs);
46}
47
48void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() );
49void ^?{}( monitor_guard_t * this );
50
51//-----------------------------------------------------------------------------
52// Internal scheduling
53
54struct __condition_criterion_t {
55        bool ready;                                             //Whether or not the criterion is met (True if met)
56        monitor_desc * target;                          //The monitor this criterion concerns
57        struct __condition_node_t * owner;              //The parent node to which this criterion belongs
58        __condition_criterion_t * next;         //Intrusive linked list Next field
59};
60
61struct __condition_node_t {
62        thread_desc * waiting_thread;                   //Thread that needs to be woken when all criteria are met
63        __condition_criterion_t * criteria;     //Array of criteria (Criterions are contiguous in memory)
64        unsigned short count;                           //Number of criterions in the criteria
65        __condition_node_t * next;                      //Intrusive linked list Next field
66        uintptr_t user_info;                            //Custom user info accessible before signalling
67};
68
69struct __condition_blocked_queue_t {
70        __condition_node_t * head;
71        __condition_node_t ** tail;
72};
73
74void ?{}( __condition_blocked_queue_t * );
75void append( __condition_blocked_queue_t *, __condition_node_t * );
76__condition_node_t * pop_head( __condition_blocked_queue_t * );
77
78struct condition {
79        __condition_blocked_queue_t blocked;    //Link list which contains the blocked threads as-well as the information needed to unblock them
80        monitor_desc ** monitors;                       //Array of monitor pointers (Monitors are NOT contiguous in memory)
81        unsigned short monitor_count;                   //Number of monitors in the array
82};
83
84static inline void ?{}( condition * this ) {
85        this->monitors = NULL;
86        this->monitor_count = 0;
87}
88
89static inline void ^?{}( condition * this ) {
90        free( this->monitors );
91}
92
93void wait( condition * this, uintptr_t user_info = 0 );
94bool signal( condition * this );
95bool signal_block( condition * this );
96static inline bool is_empty( condition * this ) { return !this->blocked.head; }
97uintptr_t front( condition * this );
98
99//-----------------------------------------------------------------------------
100// External scheduling
101
102struct __acceptable_t {
103        fptr_t func;
104        unsigned short count;
105        monitor_desc ** monitors;
106        bool run_preaccept;
107};
108
109int __accept_internal( unsigned short count, __acceptable_t * acceptables );
110
111// Local Variables: //
112// mode: c //
113// tab-width: 4 //
114// End: //
Note: See TracBrowser for help on using the repository browser.