Changeset 2781e65


Ignore:
Timestamp:
Feb 28, 2017, 4:21:15 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
20221d4
Parents:
cc7f4b1
Message:

added support for acquiring multiple monitors at once

Location:
src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor

    rcc7f4b1 r2781e65  
    2020#include "assert"
    2121#include "invoke.h"
     22#include "stdlib"
    2223
    2324struct __monitor_t {
     
    3334}
    3435
     36//Basic entering routine
    3537void enter(__monitor_t *);
    3638void leave(__monitor_t *);
    3739
     40//Array entering routine
     41void enter(__monitor_t **, int count);
     42void leave(__monitor_t **, int count);
     43
    3844struct monitor_guard_t {
    39         __monitor_t * m;
     45        __monitor_t ** m;
     46        int count;
    4047};
    4148
    42 static inline void ?{}( monitor_guard_t * this, __monitor_t * m ) {
     49static inline int ?<?(__monitor_t* lhs, __monitor_t* rhs) {
     50        return ((intptr_t)lhs) < ((intptr_t)rhs);
     51}
     52
     53static inline void ?{}( monitor_guard_t * this, __monitor_t ** m ) {
    4354        this->m = m;
    44         enter( this->m );
     55        this->count = 1;
     56        enter( *this->m );
     57}
     58
     59static inline void ?{}( monitor_guard_t * this, __monitor_t ** m, int count ) {
     60        this->m = m;
     61        this->count = count;
     62        qsort(this->m, count);
     63        enter( this->m, this->count );
    4564}
    4665
    4766static inline void ^?{}( monitor_guard_t * this ) {
    48         leave( this->m );
     67        leave( this->m, this->count );
    4968}
    5069
     70
    5171#endif //MONITOR_H
  • src/libcfa/concurrency/monitor.c

    rcc7f4b1 r2781e65  
    7171        }
    7272}
     73
     74void enter(__monitor_t ** monitors, int count) {
     75        for(int i = 0; i < count; i++) {
     76                // printf("%d\n", i);
     77                enter( monitors[i] );
     78        }
     79}
     80
     81void leave(__monitor_t ** monitors, int count) {
     82        for(int i = count - 1; i >= 0; i--) {
     83                // printf("%d\n", i);
     84                leave( monitors[i] );
     85        }
     86}
  • src/tests/monitor.c

    rcc7f4b1 r2781e65  
    1616
    1717void increment( /*mutex*/ global_t * this ) {
    18         monitor_guard_t g1 = { &this->m };
     18        __monitor_t * mon = &this->m;
     19        monitor_guard_t g1 = { &mon };
    1920        {
    20                 monitor_guard_t g2 = { &this->m };
     21                monitor_guard_t g2 = { &mon };
    2122                {
    22                         monitor_guard_t g3 = { &this->m };
     23                        monitor_guard_t g3 = { &mon };
    2324                        this->value += 1;
    2425                }
Note: See TracChangeset for help on using the changeset viewer.