Ignore:
Timestamp:
Nov 5, 2020, 7:25:33 PM (13 months ago)
Author:
Fangren Yu <f37yu@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
16ba4a6, 3959595
Parents:
7d651a6 (diff), f4e35326 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/locks.hfa

    r7d651a6 r3febb2d  
     1#pragma once
     2
    13#include <stdbool.h>
    24
     
    1012#include "time.hfa"
    1113#include <sys/time.h>
     14#include "alarm.hfa"
    1215
    1316///////////////////////////////////////////////////////////////////
     
    3235                info_thread(L) * next;
    3336                L * lock;
     37                bool listed;                                    // true if info_thread is on queue, false otherwise;
    3438        };
    3539
     
    119123///////////////////////////////////////////////////////////////////
    120124forall(dtype L | is_blocking_lock(L)) {
    121         struct synchronization_lock {
     125        struct condition_variable {
    122126                // Spin lock used for mutual exclusion
    123127                __spinlock_t lock;
     
    128132                // Count of current blocked threads
    129133                int count;
    130 
    131                 // If true threads will reacquire the lock they block on upon waking
    132                 bool reacquire_after_signal;
    133134        };
    134 
    135         struct condition_variable {
    136                 inline synchronization_lock(L);
    137         };
    138 
    139         struct thread_queue {
    140                 inline synchronization_lock(L);
    141         };
    142 
    143 
    144         void ?{}( synchronization_lock(L) & this, bool multi_acquisition, bool strict_owner );
    145         void ^?{}( synchronization_lock(L) & this );
    146135
    147136        void ?{}( condition_variable(L) & this );
    148137        void ^?{}( condition_variable(L) & this );
    149138
    150         void ?{}( thread_queue(L) & this );
    151         void ^?{}( thread_queue(L) & this );
     139        struct alarm_node_wrap {
     140                alarm_node_t alarm_node;
    152141
    153         bool notify_one( synchronization_lock(L) & this );
    154         bool notify_all( synchronization_lock(L) & this );
     142                condition_variable(L) * cond;
    155143
    156         uintptr_t front( synchronization_lock(L) & this );
    157 
    158         bool empty( synchronization_lock(L) & this );
    159         int counter( synchronization_lock(L) & this );
    160 
    161         // wait functions that are not passed a mutex lock
    162         void wait( synchronization_lock(L) & this );
    163         void wait( synchronization_lock(L) & this, uintptr_t info );
    164         bool wait( synchronization_lock(L) & this, Duration duration );
    165         bool wait( synchronization_lock(L) & this, uintptr_t info, Duration duration );
    166         bool wait( synchronization_lock(L) & this, Time time );
    167         bool wait( synchronization_lock(L) & this, uintptr_t info, Time time );
    168 
    169         // wait functions that are passed a lock
    170         bool notify_one( synchronization_lock(L) & this, L & l );
    171         bool notify_all( synchronization_lock(L) & this, L & l );
    172 
    173         void wait( synchronization_lock(L) & this, L & l );
    174         void wait( synchronization_lock(L) & this, L & l, uintptr_t info );
    175         bool wait( synchronization_lock(L) & this, L & l, Duration duration );
    176         bool wait( synchronization_lock(L) & this, L & l, uintptr_t info, Duration duration );
    177         bool wait( synchronization_lock(L) & this, L & l, Time time );
    178         bool wait( synchronization_lock(L) & this, L & l, uintptr_t info, Time time );
    179 }
    180 
    181 ///////////////////////////////////////////////////////////////////
    182 //// condition lock alternative approach
    183 ///////////////////////////////////////////////////////////////////
    184 
    185 
    186 ///////////////////////////////////////////////////////////////////
    187 //// is_simple_lock
    188 ///////////////////////////////////////////////////////////////////
    189 
    190 trait is_simple_lock(dtype L | sized(L)) {
    191         void lock( L & );               // For synchronization locks to use when acquiring
    192         void unlock( L & );    // For synchronization locks to use when releasing
    193         size_t get_recursion_count( L & ); // to get recursion count for cond lock to reset after waking
    194         void set_recursion_count( L &, size_t recursion ); // to set recursion count after getting signalled;
    195 };
    196 
    197 forall(dtype L | is_simple_lock(L)) {
    198         struct condition_lock {
    199                 // Spin lock used for mutual exclusion
    200                 mutex_lock m_lock;
    201 
    202                 condition_variable( mutex_lock ) c_var;
     144                info_thread(L) ** i;
    203145        };
    204146
    205         void ?{}( condition_lock(L) & this );
    206         void ^?{}( condition_lock(L) & this );
     147        void ?{}( alarm_node_wrap(L) & this, $thread * thrd, Time alarm, Duration period, Alarm_Callback callback );
     148        void ^?{}( alarm_node_wrap(L) & this );
    207149
    208         bool notify_one( condition_lock(L) & this );
    209         bool notify_all( condition_lock(L) & this );
    210         void wait( condition_lock(L) & this, L & l );
     150        void alarm_node_callback( alarm_node_wrap(L) & this );
     151
     152        void alarm_node_wrap_cast( alarm_node_t & a );
     153
     154        bool notify_one( condition_variable(L) & this );
     155        bool notify_all( condition_variable(L) & this );
     156
     157        uintptr_t front( condition_variable(L) & this );
     158
     159        bool empty( condition_variable(L) & this );
     160        int counter( condition_variable(L) & this );
     161
     162        // TODO: look into changing timout routines to return bool showing if signalled or woken by kernel
     163        void wait( condition_variable(L) & this );
     164        void wait( condition_variable(L) & this, uintptr_t info );
     165        void wait( condition_variable(L) & this, Duration duration );
     166        void wait( condition_variable(L) & this, uintptr_t info, Duration duration );
     167        void wait( condition_variable(L) & this, Time time );
     168        void wait( condition_variable(L) & this, uintptr_t info, Time time );
     169
     170        void wait( condition_variable(L) & this, L & l );
     171        void wait( condition_variable(L) & this, L & l, uintptr_t info );
     172        void wait( condition_variable(L) & this, L & l, Duration duration );
     173        void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );
     174        void wait( condition_variable(L) & this, L & l, Time time );
     175        void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time );
    211176}
Note: See TracChangeset for help on using the changeset viewer.