Changeset da6bcc0 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:20Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d350175
Parents:
771d162
git-author:
Dzejrou <dzejrou@…> (2018-03-29 16:04:30)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

cpp: added shared_mutex into the fibril threading wrapper

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/thread.hpp

    r771d162 rda6bcc0  
    5454    struct threading_policy<fibril_tag>
    5555    {
    56         using mutex_type   = fibril_mutex_t;
    57         using thread_type  = fid_t;
    58         using condvar_type = fibril_condvar_t;
    59         using time_unit    = suseconds_t;
     56        using mutex_type        = fibril_mutex_t;
     57        using thread_type       = fid_t;
     58        using condvar_type      = fibril_condvar_t;
     59        using time_unit         = suseconds_t;
     60        using shared_mutex_type = fibril_rwlock_t;
    6061
    6162        struct thread
     
    159160            }
    160161        };
     162
     163        struct shared_mutex
     164        {
     165            static void init(shared_mutex_type& mtx)
     166            {
     167                fibril_rwlock_initialize(&mtx);
     168            }
     169
     170            static void lock(shared_mutex_type& mtx)
     171            {
     172                fibril_rwlock_write_lock(&mtx);
     173            }
     174
     175            static void unlock(shared_mutex_type& mtx)
     176            {
     177                fibril_rwlock_write_unlock(&mtx);
     178            }
     179
     180            static void lock_shared(shared_mutex_type& mtx)
     181            {
     182                fibril_rwlock_read_lock(&mtx);
     183            }
     184
     185            static void unlock_shared(shared_mutex_type& mtx)
     186            {
     187                fibril_rwlock_read_unlock(&mtx);
     188            }
     189
     190            static bool try_lock(shared_mutex_type& mtx)
     191            {
     192                // TODO: rwlocks don't have try locking capabilities
     193                lock(mtx);
     194
     195                return true;
     196            }
     197
     198            static bool try_lock_shared(shared_mutex_type& mtx)
     199            {
     200                lock(mtx);
     201
     202                return true;
     203            }
     204
     205            static bool try_lock_for(shared_mutex_type& mtx, time_unit timeout)
     206            {
     207                return try_lock(mtx);
     208            }
     209
     210            static bool try_lock_shared_for(shared_mutex_type& mtx, time_unit timeout)
     211            {
     212                return try_lock(mtx);
     213            }
     214        };
    161215    };
    162216
     
    170224    using threading = threading_policy<default_tag>;
    171225
    172     using thread_t    = typename threading::thread_type;
    173     using mutex_t     = typename threading::mutex_type;
    174     using condvar_t   = typename threading::condvar_type;
    175     using time_unit_t = typename threading::time_unit;
     226    using thread_t       = typename threading::thread_type;
     227    using mutex_t        = typename threading::mutex_type;
     228    using condvar_t      = typename threading::condvar_type;
     229    using time_unit_t    = typename threading::time_unit;
     230    using shared_mutex_t = typename threading::shared_mutex_type;
    176231}
    177232
Note: See TracChangeset for help on using the changeset viewer.