Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor

    r9f5ecf5 r59a0bde  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:59:01 2017
    13 // Update Count     : 3
     12// Last Modified On : Sat Oct  7 18:06:45 2017
     13// Update Count     : 10
    1414//
    1515
     
    2222#include "stdlib"
    2323
     24trait is_monitor(dtype T) {
     25        monitor_desc * get_monitor( T & );
     26        void ^?{}( T & mutex );
     27};
     28
    2429static inline void ?{}(monitor_desc & this) {
    2530        (this.lock){};
    26         this.owner = NULL;
    2731        (this.entry_queue){};
    2832        (this.signal_stack){};
    29         this.recursion = 0;
    30         this.acceptables = NULL;
    31         this.acceptable_count = 0;
    32         this.accepted_index = -1;
     33        this.owner         = NULL;
     34        this.recursion     = 0;
     35        this.mask.accepted = NULL;
     36        this.mask.clauses  = NULL;
     37        this.mask.size     = 0;
     38        this.dtor_node     = NULL;
    3339}
    3440
    3541struct monitor_guard_t {
    3642        monitor_desc ** m;
    37         int count;
     43        __lock_size_t  count;
    3844        monitor_desc ** prev_mntrs;
    39         unsigned short  prev_count;
     45        __lock_size_t   prev_count;
    4046        fptr_t          prev_func;
    4147};
    4248
    43 static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
    44         return ((intptr_t)lhs) < ((intptr_t)rhs);
     49void ?{}( monitor_guard_t & this, monitor_desc ** m, __lock_size_t count, void (*func)() );
     50void ^?{}( monitor_guard_t & this );
     51
     52struct monitor_dtor_guard_t {
     53        monitor_desc * m;
     54        monitor_desc ** prev_mntrs;
     55        __lock_size_t   prev_count;
     56        fptr_t          prev_func;
     57};
     58
     59void ?{}( monitor_dtor_guard_t & this, monitor_desc ** m, void (*func)() );
     60void ^?{}( monitor_dtor_guard_t & this );
     61
     62static inline forall( dtype T | sized(T) | { void ^?{}( T & mutex ); } )
     63void delete( T * th ) {
     64        ^(*th){};
     65        free( th );
    4566}
    46 
    47 void ?{}( monitor_guard_t & this, monitor_desc ** m, int count, void (*func)() );
    48 void ^?{}( monitor_guard_t & this );
    4967
    5068//-----------------------------------------------------------------------------
     
    5270
    5371struct __condition_criterion_t {
    54         bool ready;                                             //Whether or not the criterion is met (True if met)
    55         monitor_desc * target;                          //The monitor this criterion concerns
    56         struct __condition_node_t * owner;              //The parent node to which this criterion belongs
    57         __condition_criterion_t * next;         //Intrusive linked list Next field
     72        // Whether or not the criterion is met (True if met)
     73        bool ready;
     74
     75        // The monitor this criterion concerns
     76        monitor_desc * target;
     77
     78        // The parent node to which this criterion belongs
     79        struct __condition_node_t * owner;
     80
     81        // Intrusive linked list Next field
     82        __condition_criterion_t * next;
    5883};
    5984
    6085struct __condition_node_t {
    61         thread_desc * waiting_thread;                   //Thread that needs to be woken when all criteria are met
    62         __condition_criterion_t * criteria;     //Array of criteria (Criterions are contiguous in memory)
    63         unsigned short count;                           //Number of criterions in the criteria
    64         __condition_node_t * next;                      //Intrusive linked list Next field
    65         uintptr_t user_info;                            //Custom user info accessible before signalling
     86        // Thread that needs to be woken when all criteria are met
     87        thread_desc * waiting_thread;
     88
     89        // Array of criteria (Criterions are contiguous in memory)
     90        __condition_criterion_t * criteria;
     91
     92        // Number of criterions in the criteria
     93        __lock_size_t count;
     94
     95        // Intrusive linked list Next field
     96        __condition_node_t * next;
     97
     98        // Custom user info accessible before signalling
     99        uintptr_t user_info;
    66100};
    67101
     
    71105};
    72106
     107void ?{}(__condition_node_t & this, thread_desc * waiting_thread, __lock_size_t count, uintptr_t user_info );
     108void ?{}(__condition_criterion_t & this );
     109void ?{}(__condition_criterion_t & this, monitor_desc * target, __condition_node_t * owner );
     110
    73111void ?{}( __condition_blocked_queue_t & );
    74 void append( __condition_blocked_queue_t *, __condition_node_t * );
    75 __condition_node_t * pop_head( __condition_blocked_queue_t * );
     112void append( __condition_blocked_queue_t &, __condition_node_t * );
     113__condition_node_t * pop_head( __condition_blocked_queue_t & );
    76114
    77115struct condition {
    78         __condition_blocked_queue_t blocked;    //Link list which contains the blocked threads as-well as the information needed to unblock them
    79         monitor_desc ** monitors;                       //Array of monitor pointers (Monitors are NOT contiguous in memory)
    80         unsigned short monitor_count;                   //Number of monitors in the array
     116        // Link list which contains the blocked threads as-well as the information needed to unblock them
     117        __condition_blocked_queue_t blocked;
     118
     119        // Array of monitor pointers (Monitors are NOT contiguous in memory)
     120        monitor_desc ** monitors;
     121
     122        // Number of monitors in the array
     123        __lock_size_t monitor_count;
    81124};
    82125
     
    90133}
    91134
    92 void wait( condition * this, uintptr_t user_info = 0 );
    93 bool signal( condition * this );
    94 bool signal_block( condition * this );
    95 static inline bool is_empty( condition * this ) { return !this->blocked.head; }
    96 uintptr_t front( condition * this );
     135              void wait        ( condition & this, uintptr_t user_info = 0 );
     136              bool signal      ( condition & this );
     137              bool signal_block( condition & this );
     138static inline bool is_empty    ( condition & this ) { return !this.blocked.head; }
     139         uintptr_t front       ( condition & this );
    97140
    98141//-----------------------------------------------------------------------------
     
    100143
    101144struct __acceptable_t {
    102         fptr_t func;
    103         unsigned short count;
    104         monitor_desc ** monitors;
     145        __monitor_group_t;
    105146        bool is_dtor;
    106147};
    107148
    108 int __accept_internal( unsigned short count, __acceptable_t * acceptables );
     149void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
    109150
    110151// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.