Ignore:
File:
1 edited

Legend:

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

    rab1b971 r454f478  
    1 //
    2 // Cforall Version 1.0.0 Copyright (C) 2021 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 // locks.hfa -- PUBLIC
    8 // Runtime locks that used with the runtime thread system.
    9 //
    10 // Author           : Colby Alexander Parsons
    11 // Created On       : Thu Jan 21 19:46:50 2021
    12 // Last Modified By :
    13 // Last Modified On :
    14 // Update Count     :
    15 //
    16 
    171#pragma once
    182
    193#include <stdbool.h>
    204
    21 #include "bits/weakso_locks.hfa"
     5#include "bits/locks.hfa"
     6#include "bits/sequence.hfa"
     7
     8#include "invoke.h"
    229
    2310#include "time_t.hfa"
    2411#include "time.hfa"
    25 
    26 //----------
    27 struct single_acquisition_lock {
    28         inline blocking_lock;
    29 };
    30 
    31 static inline void  ?{}( single_acquisition_lock & this ) {((blocking_lock &)this){ false, false };}
    32 static inline void ^?{}( single_acquisition_lock & this ) {}
    33 static inline void   lock      ( single_acquisition_lock & this ) { lock   ( (blocking_lock &)this ); }
    34 static inline void   unlock    ( single_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); }
    35 static inline void   on_wait   ( single_acquisition_lock & this ) { on_wait( (blocking_lock &)this ); }
    36 static inline void   on_notify ( single_acquisition_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }
    37 static inline void   set_recursion_count( single_acquisition_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); }
    38 static inline size_t get_recursion_count( single_acquisition_lock & this ) { return get_recursion_count( (blocking_lock &)this ); }
    39 
    40 //----------
    41 struct owner_lock {
    42         inline blocking_lock;
    43 };
    44 
    45 static inline void  ?{}( owner_lock & this ) {((blocking_lock &)this){ true, true };}
    46 static inline void ^?{}( owner_lock & this ) {}
    47 static inline void   lock     ( owner_lock & this ) { lock   ( (blocking_lock &)this ); }
    48 static inline void   unlock   ( owner_lock & this ) { unlock ( (blocking_lock &)this ); }
    49 static inline void   on_wait  ( owner_lock & this ) { on_wait( (blocking_lock &)this ); }
    50 static inline void   on_notify( owner_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }
    51 static inline void   set_recursion_count( owner_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); }
    52 static inline size_t get_recursion_count( owner_lock & this ) { return get_recursion_count( (blocking_lock &)this ); }
    5312
    5413//-----------------------------------------------------------------------------
     
    7938        info_thread(L) *& Next( info_thread(L) * this );
    8039}
     40
     41//-----------------------------------------------------------------------------
     42// Blocking Locks
     43struct blocking_lock {
     44        // Spin lock used for mutual exclusion
     45        __spinlock_t lock;
     46
     47        // List of blocked threads
     48        Sequence( $thread ) blocked_threads;
     49
     50        // Count of current blocked threads
     51        size_t wait_count;
     52
     53        // Flag if the lock allows multiple acquisition
     54        bool multi_acquisition;
     55
     56        // Flag if lock can be released by non owner
     57        bool strict_owner;
     58
     59        // Current thread owning the lock
     60        struct $thread * owner;
     61
     62        // Number of recursion level
     63        size_t recursion_count;
     64};
     65
     66struct single_acquisition_lock {
     67        inline blocking_lock;
     68};
     69
     70struct owner_lock {
     71        inline blocking_lock;
     72};
     73
     74struct multiple_acquisition_lock {
     75        inline blocking_lock;
     76};
     77
     78void  ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );
     79void ^?{}( blocking_lock & this );
     80
     81void  ?{}( single_acquisition_lock & this );
     82void ^?{}( single_acquisition_lock & this );
     83
     84void  ?{}( owner_lock & this );
     85void ^?{}( owner_lock & this );
     86
     87void  ?{}( multiple_acquisition_lock & this );
     88void ^?{}( multiple_acquisition_lock & this );
     89
     90void lock( blocking_lock & this );
     91bool try_lock( blocking_lock & this );
     92void unlock( blocking_lock & this );
     93void on_notify( blocking_lock & this, struct $thread * t );
     94void on_wait( blocking_lock & this );
     95size_t wait_count( blocking_lock & this );
     96void set_recursion_count( blocking_lock & this, size_t recursion );
     97size_t get_recursion_count( blocking_lock & this );
     98
     99void lock( single_acquisition_lock & this );
     100void unlock( single_acquisition_lock & this );
     101void on_notify( single_acquisition_lock & this, struct $thread * t );
     102void on_wait( single_acquisition_lock & this );
     103void set_recursion_count( single_acquisition_lock & this, size_t recursion );
     104size_t get_recursion_count( single_acquisition_lock & this );
     105
     106void lock( owner_lock & this );
     107void unlock( owner_lock & this );
     108void on_notify( owner_lock & this, struct $thread * t );
     109void on_wait( owner_lock & this );
     110void set_recursion_count( owner_lock & this, size_t recursion );
     111size_t get_recursion_count( owner_lock & this );
     112
     113void lock( multiple_acquisition_lock & this );
     114void unlock( multiple_acquisition_lock & this );
     115void on_notify( multiple_acquisition_lock & this, struct $thread * t );
     116void on_wait( multiple_acquisition_lock & this );
     117void set_recursion_count( multiple_acquisition_lock & this, size_t recursion );
     118size_t get_recursion_count( multiple_acquisition_lock & this );
    81119
    82120//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.