Changes in / [e50e9ff:b3d413b]


Ignore:
Location:
src
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    re50e9ff rb3d413b  
    200200                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
    201201                void validate( DeclarationWithType * );
    202                 void addStatments( FunctionDecl* func, CompoundStmt *, const std::list<DeclarationWithType * > &);
     202                void addStatments( CompoundStmt *, const std::list<DeclarationWithType * > &);
    203203
    204204                static void implement( std::list< Declaration * > & translationUnit ) {
     
    210210                StructDecl* monitor_decl = nullptr;
    211211                StructDecl* guard_decl = nullptr;
    212 
    213                 static std::unique_ptr< Type > generic_func;
    214212        };
    215 
    216         std::unique_ptr< Type > MutexKeyword::generic_func = std::unique_ptr< Type >(
    217                 new FunctionType(
    218                         noQualifiers,
    219                         true
    220                 )
    221         );
    222213
    223214        //-----------------------------------------------------------------------------
     
    403394        // Mutex keyword implementation
    404395        //=============================================================================================
    405 
    406396        void MutexKeyword::visit(FunctionDecl* decl) {
    407397                Visitor::visit(decl);
     
    420410                if( !guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
    421411
    422                 addStatments( decl, body, mutexArgs );
     412                addStatments( body, mutexArgs );
    423413        }
    424414
     
    466456        }
    467457
    468         void MutexKeyword::addStatments( FunctionDecl* func, CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
     458        void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
    469459                ObjectDecl * monitors = new ObjectDecl(
    470460                        "__monitors",
     
    497487                );
    498488
    499                 assert(generic_func);
    500 
    501489                //in reverse order :
    502                 // monitor_guard_t __guard = { __monitors, #, func };
     490                // monitor_guard_t __guard = { __monitors, # };
    503491                body->push_front(
    504492                        new DeclStmt( noLabels, new ObjectDecl(
     
    514502                                        {
    515503                                                new SingleInit( new VariableExpr( monitors ) ),
    516                                                 new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) ),
    517                                                 new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone() ) )
     504                                                new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) )
    518505                                        },
    519506                                        noDesignators,
  • src/libcfa/concurrency/invoke.h

    re50e9ff rb3d413b  
    8787            struct __condition_stack_t signal_stack;  // stack of conditions to run next once we exit the monitor
    8888            unsigned int recursion;                   // monitor routines can be called recursively, we need to keep track of that
    89 
    90             struct __acceptable_t * acceptables;      // list of acceptable functions, null if any
    91             unsigned short acceptable_count;          // number of acceptable functions
    92             short accepted_index;                     // the index of the accepted function, -1 if none
    93             void (*pre_accept)(void);                 // function to run before an accept
    94        };
     89      };
    9590
    9691      struct thread_desc {
     
    10095            struct monitor_desc ** current_monitors;  // currently held monitors
    10196            unsigned short current_monitor_count;     // number of currently held monitors
    102      };
     97      };
    10398
    10499#endif //_INVOKE_H_
  • src/libcfa/concurrency/kernel.c

    re50e9ff rb3d413b  
    366366
    367367void BlockInternal( thread_desc * thrd ) {
    368         assert(thrd);
    369368        disable_interrupts();
    370369        assert( thrd->cor.state != Halted );
     
    380379
    381380void BlockInternal( spinlock * lock, thread_desc * thrd ) {
    382         assert(thrd);
    383381        disable_interrupts();
    384382        this_processor->finish.action_code = Release_Schedule;
  • src/libcfa/concurrency/monitor

    re50e9ff rb3d413b  
    2323
    2424static inline void ?{}(monitor_desc * this) {
    25         (&this->lock){};
    2625        this->owner = NULL;
    27         (&this->entry_queue){};
    28         (&this->signal_stack){};
    2926        this->recursion = 0;
    30         this->acceptables = NULL;
    31         this->acceptable_count = 0;
    32         this->accepted_index = -1;
    33         this->pre_accept = 0;
    3427}
    3528
     
    4538}
    4639
    47 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() );
     40void ?{}( monitor_guard_t * this, monitor_desc ** m, int count );
    4841void ^?{}( monitor_guard_t * this );
    4942
     
    9689uintptr_t front( condition * this );
    9790
    98 //-----------------------------------------------------------------------------
    99 // External scheduling
    100 
    101 typedef void (*void_fptr_t)(void);
    102 
    10391struct __acceptable_t {
    104         void_fptr_t func;
     92        void (*func)(void);
    10593        unsigned short count;
    106         monitor_desc ** monitors;
    107         bool run_preaccept;
     94        monitor_desc * monitors[1];
    10895};
    10996
    110 int __accept_internal( unsigned short count, __acceptable_t * acceptables );
     97void __accept_internal( unsigned short count, __acceptable_t * acceptables, void (*func)(void) );
    11198
    11299// Local Variables: //
  • src/libcfa/concurrency/monitor.c

    re50e9ff rb3d413b  
    2525static inline void set_owner( monitor_desc * this, thread_desc * owner );
    2626static inline thread_desc * next_thread( monitor_desc * this );
    27 static inline int is_accepted( thread_desc * owner, monitor_desc * this, monitor_desc ** group, int group_cnt, void (*func)() );
    2827
    2928static inline void lock_all( spinlock ** locks, unsigned short count );
     
    3534static inline void restore_recursion( monitor_desc ** ctx, unsigned int * /*in */ recursions, unsigned short count );
    3635
    37 static inline void init     ( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria );
    38 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria );
    39 
    4036static inline thread_desc * check_condition( __condition_criterion_t * );
    4137static inline void brand_condition( condition * );
    4238static inline unsigned short insert_unique( thread_desc ** thrds, unsigned short end, thread_desc * val );
    4339
    44 static inline thread_desc * search_entry_queue( __acceptable_t * acceptables, int acc_count, monitor_desc ** monitors, int count );
    45 
    46 //-----------------------------------------------------------------------------
    47 // Useful defines
    48 #define wait_ctx(thrd, user_info)                               /* Create the necessary information to use the signaller stack       */ \
    49         __condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                   */ \
    50         __condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up          */ \
    51         init( count, monitors, &waiter, criteria );               /* Link everything together                                          */ \
    52 
    53 #define wait_ctx_primed(thrd, user_info)                        /* Create the necessary information to use the signaller stack       */ \
    54         __condition_node_t waiter = { thrd, count, user_info };   /* Create the node specific to this wait operation                   */ \
    55         __condition_criterion_t criteria[count];                  /* Create the creteria this wait operation needs to wake up          */ \
    56         init_push( count, monitors, &waiter, criteria );          /* Link everything together and push it to the AS-Stack              */ \
    57 
    58 #define monitor_ctx( mons, cnt )              /* Define that create the necessary struct for internal/external scheduling operations */ \
    59         monitor_desc ** monitors = mons;        /* Save the targeted monitors                                                          */ \
    60         unsigned short count = cnt;             /* Save the count to a local variable                                                  */ \
    61         unsigned int recursions[ count ];       /* Save the current recursion levels to restore them later                             */ \
    62         spinlock *   locks     [ count ];       /* We need to pass-in an array of locks to BlockInternal                               */ \
    63 
    6440//-----------------------------------------------------------------------------
    6541// Enter/Leave routines
     
    6743
    6844extern "C" {
    69         // Enter single monitor
    70         static void __enter_monitor_desc( monitor_desc * this, monitor_desc ** group, int group_cnt, void (*func)() ) {
    71                 // Lock the monitor spinlock, lock_yield to reduce contention
     45        void __enter_monitor_desc( monitor_desc * this ) {
    7246                lock_yield( &this->lock DEBUG_CTX2 );
    7347                thread_desc * thrd = this_thread;
    7448
    75                 this->accepted_index = -1;
     49                // LIB_DEBUG_PRINT_SAFE("%p Entering %p (o: %p, r: %i)\n", thrd, this, this->owner, this->recursion);
     50
    7651                if( !this->owner ) {
    77                         // No one has the monitor, just take it
     52                        //No one has the monitor, just take it
    7853                        set_owner( this, thrd );
    7954                }
    8055                else if( this->owner == thrd) {
    81                         // We already have the monitor, just not how many times we took it
     56                        //We already have the monitor, just not how many times we took it
    8257                        verify( this->recursion > 0 );
    8358                        this->recursion += 1;
    8459                }
    85                 else if( (this->accepted_index = is_accepted( thrd, this, group, group_cnt, func)) >= 0 ) {
    86                         // Some one was waiting for us, enter
    87                         set_owner( this, thrd );
    88                 }
    8960                else {
    90                         // Some one else has the monitor, wait in line for it
     61                        //Some one else has the monitor, wait in line for it
    9162                        append( &this->entry_queue, thrd );
     63                        // LIB_DEBUG_PRINT_SAFE("%p Blocking on entry\n", thrd);
    9264                        BlockInternal( &this->lock );
    9365
    94                         // BlockInternal will unlock spinlock, no need to unlock ourselves
     66                        //BlockInternal will unlock spinlock, no need to unlock ourselves
    9567                        return;
    9668                }
    9769
    98                 // Release the lock and leave
    9970                unlock( &this->lock );
    10071                return;
    10172        }
    10273
    103         // Leave single monitor
     74        // leave pseudo code :
     75        //      TODO
    10476        void __leave_monitor_desc( monitor_desc * this ) {
    105                 // Lock the monitor spinlock, lock_yield to reduce contention
    10677                lock_yield( &this->lock DEBUG_CTX2 );
    10778
     79                // LIB_DEBUG_PRINT_SAFE("%p Leaving %p (o: %p, r: %i). ", this_thread, this, this->owner, this->recursion);
    10880                verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i)", this_thread, this->owner, this->recursion );
    10981
    110                 // Leaving a recursion level, decrement the counter
     82                //Leaving a recursion level, decrement the counter
    11183                this->recursion -= 1;
    11284
    113                 // If we haven't left the last level of recursion
    114                 // it means we don't need to do anything
     85                //If we haven't left the last level of recursion
     86                //it means we don't need to do anything
    11587                if( this->recursion != 0) {
    11688                        unlock( &this->lock );
     
    11890                }
    11991
    120                 // Get the next thread, will be null on low contention monitor
    12192                thread_desc * new_owner = next_thread( this );
    12293
    123                 // We can now let other threads in safely
     94                //We can now let other threads in safely
    12495                unlock( &this->lock );
     96
     97                // LIB_DEBUG_PRINT_SAFE("Next owner is %p\n", new_owner);
    12598
    12699                //We need to wake-up the thread
     
    128101        }
    129102
    130         // Leave the thread monitor
    131         // last routine called by a thread.
    132         // Should never return
    133103        void __leave_thread_monitor( thread_desc * thrd ) {
    134104                monitor_desc * this = &thrd->mon;
    135 
    136                 // Lock the monitor now
    137105                lock_yield( &this->lock DEBUG_CTX2 );
    138106
     
    143111                verifyf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i)", thrd, this->owner, this->recursion );
    144112
    145                 // Leaving a recursion level, decrement the counter
     113                //Leaving a recursion level, decrement the counter
    146114                this->recursion -= 1;
    147115
    148                 // If we haven't left the last level of recursion
    149                 // it must mean there is an error
    150                 if( this->recursion != 0) { abortf("Thread internal monitor has unbalanced recursion"); }
    151 
    152                 // Fetch the next thread, can be null
     116                //If we haven't left the last level of recursion
     117                //it means we don't need to do anything
     118                if( this->recursion != 0) {
     119                        unlock( &this->lock );
     120                        return;
     121                }
     122
    153123                thread_desc * new_owner = next_thread( this );
    154124
    155                 // Leave the thread, this will unlock the spinlock
    156                 // Use leave thread instead of BlockInternal which is
    157                 // specialized for this case and supports null new_owner
    158125                LeaveThread( &this->lock, new_owner );
    159 
    160                 // Control flow should never reach here!
    161         }
    162 }
    163 
    164 // Enter multiple monitor
    165 // relies on the monitor array being sorted
    166 static inline void enter(monitor_desc ** monitors, int count, void (*func)() ) {
     126        }
     127}
     128
     129static inline void enter(monitor_desc ** monitors, int count) {
    167130        for(int i = 0; i < count; i++) {
    168                 __enter_monitor_desc( monitors[i], monitors, count, func );
    169         }
    170 
    171         int acc_idx = monitors[0]->accepted_index;
    172         if( acc_idx >= 0 && monitors[0]->acceptables[ acc_idx ].run_preaccept ) {
    173                 assert( monitors[0]->pre_accept );
    174                 monitors[0]->pre_accept();
    175         }
    176 }
    177 
    178 // Leave multiple monitor
    179 // relies on the monitor array being sorted
     131                __enter_monitor_desc( monitors[i] );
     132        }
     133}
     134
    180135static inline void leave(monitor_desc ** monitors, int count) {
    181136        for(int i = count - 1; i >= 0; i--) {
     
    184139}
    185140
    186 // Ctor for monitor guard
    187 // Sorts monitors before entering
    188 void ?{}( monitor_guard_t * this, monitor_desc ** m, int count, void (*func)() ) {
    189         // Store current array
     141void ?{}( monitor_guard_t * this, monitor_desc ** m, int count ) {
    190142        this->m = m;
    191143        this->count = count;
    192 
    193         // Sort monitors based on address -> TODO use a sort specialized for small numbers
    194144        qsort(this->m, count);
    195 
    196         // Enter the monitors in order
    197         enter( this->m, this->count, func );
    198 
    199         // Save previous thread context
     145        enter( this->m, this->count );
     146
    200147        this->prev_mntrs = this_thread->current_monitors;
    201148        this->prev_count = this_thread->current_monitor_count;
    202149
    203         // Update thread context (needed for conditions)
    204150        this_thread->current_monitors      = m;
    205151        this_thread->current_monitor_count = count;
    206152}
    207153
    208 // Dtor for monitor guard
    209154void ^?{}( monitor_guard_t * this ) {
    210         // Leave the monitors in order
    211155        leave( this->m, this->count );
    212156
    213         // Restore thread context
    214157        this_thread->current_monitors      = this->prev_mntrs;
    215158        this_thread->current_monitor_count = this->prev_count;
    216159}
    217 
    218 //-----------------------------------------------------------------------------
    219 // Internal scheduling types
    220160
    221161void ?{}(__condition_node_t * this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) {
     
    243183// Internal scheduling
    244184void wait( condition * this, uintptr_t user_info = 0 ) {
     185        // LIB_DEBUG_PRINT_SAFE("Waiting\n");
     186
    245187        brand_condition( this );
    246188
    247         // Check that everything is as expected
     189        //Check that everything is as expected
    248190        assertf( this->monitors != NULL, "Waiting with no monitors (%p)", this->monitors );
    249191        verifyf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );
    250192        verifyf( this->monitor_count < 32u, "Excessive monitor count (%i)", this->monitor_count );
    251193
    252         // Create storage for monitor context
    253         monitor_ctx( this->monitors, this->monitor_count );
    254 
    255         // Create the node specific to this wait operation
    256         wait_ctx( this_thread, user_info );
    257 
    258         // Append the current wait operation to the ones already queued on the condition
    259         // We don't need locks for that since conditions must always be waited on inside monitor mutual exclusion
     194        unsigned short count = this->monitor_count;
     195        unsigned int recursions[ count ];               //Save the current recursion levels to restore them later
     196        spinlock *   locks     [ count ];               //We need to pass-in an array of locks to BlockInternal
     197
     198        // LIB_DEBUG_PRINT_SAFE("count %i\n", count);
     199
     200        __condition_node_t waiter = { (thread_desc*)this_thread, count, user_info };
     201
     202        __condition_criterion_t criteria[count];
     203        for(int i = 0; i < count; i++) {
     204                (&criteria[i]){ this->monitors[i], &waiter };
     205                // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     206        }
     207
     208        waiter.criteria = criteria;
    260209        append( &this->blocked, &waiter );
    261210
    262         // Lock all monitors (aggregates the lock them as well)
    263         lock_all( monitors, locks, count );
    264 
    265         // DON'T unlock, ask the kernel to do it
    266 
    267         // Save monitor state
    268         save_recursion( monitors, recursions, count );
    269 
    270         // Find the next thread(s) to run
     211        lock_all( this->monitors, locks, count );
     212        save_recursion( this->monitors, recursions, count );
     213        //DON'T unlock, ask the kernel to do it
     214
     215        //Find the next thread(s) to run
    271216        unsigned short thread_count = 0;
    272217        thread_desc * threads[ count ];
     
    275220        }
    276221
    277         // Remove any duplicate threads
    278222        for( int i = 0; i < count; i++) {
    279                 thread_desc * new_owner = next_thread( monitors[i] );
     223                thread_desc * new_owner = next_thread( this->monitors[i] );
    280224                thread_count = insert_unique( threads, thread_count, new_owner );
    281225        }
     226
     227        // LIB_DEBUG_PRINT_SAFE("Will unblock: ");
     228        for(int i = 0; i < thread_count; i++) {
     229                // LIB_DEBUG_PRINT_SAFE("%p ", threads[i]);
     230        }
     231        // LIB_DEBUG_PRINT_SAFE("\n");
    282232
    283233        // Everything is ready to go to sleep
     
    285235
    286236
    287         // WE WOKE UP
    288 
    289 
    290         // We are back, restore the owners and recursions
     237        //WE WOKE UP
     238
     239
     240        //We are back, restore the owners and recursions
    291241        lock_all( locks, count );
    292         restore_recursion( monitors, recursions, count );
     242        restore_recursion( this->monitors, recursions, count );
    293243        unlock_all( locks, count );
    294244}
    295245
    296246bool signal( condition * this ) {
    297         if( is_empty( this ) ) { return false; }
     247        if( is_empty( this ) ) {
     248                // LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
     249                return false;
     250        }
    298251
    299252        //Check that everything is as expected
    300253        verify( this->monitors );
    301254        verify( this->monitor_count != 0 );
     255
     256        unsigned short count = this->monitor_count;
    302257
    303258        //Some more checking in debug
     
    306261                if ( this->monitor_count != this_thrd->current_monitor_count ) {
    307262                        abortf( "Signal on condition %p made with different number of monitor(s), expected %i got %i", this, this->monitor_count, this_thrd->current_monitor_count );
    308                 }
     263                } // if
    309264
    310265                for(int i = 0; i < this->monitor_count; i++) {
    311266                        if ( this->monitors[i] != this_thrd->current_monitors[i] ) {
    312267                                abortf( "Signal on condition %p made with different monitor, expected %p got %i", this, this->monitors[i], this_thrd->current_monitors[i] );
    313                         }
     268                        } // if
    314269                }
    315270        );
    316271
    317         unsigned short count = this->monitor_count;
    318 
    319         // Lock all monitors
     272        //Lock all the monitors
    320273        lock_all( this->monitors, NULL, count );
     274        // LIB_DEBUG_PRINT_SAFE("Signalling");
    321275
    322276        //Pop the head of the waiting queue
     
    326280        for(int i = 0; i < count; i++) {
    327281                __condition_criterion_t * crit = &node->criteria[i];
     282                // LIB_DEBUG_PRINT_SAFE(" %p", crit->target);
    328283                assert( !crit->ready );
    329284                push( &crit->target->signal_stack, crit );
    330285        }
    331286
     287        // LIB_DEBUG_PRINT_SAFE("\n");
     288
    332289        //Release
    333290        unlock_all( this->monitors, count );
     
    337294
    338295bool signal_block( condition * this ) {
    339         if( !this->blocked.head ) { return false; }
     296        if( !this->blocked.head ) {
     297                LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
     298                return false;
     299        }
    340300
    341301        //Check that everything is as expected
     
    343303        verifyf( this->monitor_count != 0, "Waiting with 0 monitors (%i)", this->monitor_count );
    344304
    345         // Create storage for monitor context
    346         monitor_ctx( this->monitors, this->monitor_count );
    347 
    348         // Lock all monitors (aggregates the locks them as well)
    349         lock_all( monitors, locks, count );
    350 
    351         // Create the node specific to this wait operation
    352         wait_ctx_primed( this_thread, 0 )
     305        unsigned short count = this->monitor_count;
     306        unsigned int recursions[ count ];               //Save the current recursion levels to restore them later
     307        spinlock *   locks     [ count ];               //We need to pass-in an array of locks to BlockInternal
     308
     309        lock_all( this->monitors, locks, count );
     310
     311        //create creteria
     312        __condition_node_t waiter = { (thread_desc*)this_thread, count, 0 };
     313
     314        __condition_criterion_t criteria[count];
     315        for(int i = 0; i < count; i++) {
     316                (&criteria[i]){ this->monitors[i], &waiter };
     317                // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     318                push( &criteria[i].target->signal_stack, &criteria[i] );
     319        }
     320
     321        waiter.criteria = criteria;
    353322
    354323        //save contexts
    355         save_recursion( monitors, recursions, count );
     324        save_recursion( this->monitors, recursions, count );
    356325
    357326        //Find the thread to run
    358327        thread_desc * signallee = pop_head( &this->blocked )->waiting_thread;
    359328        for(int i = 0; i < count; i++) {
    360                 set_owner( monitors[i], signallee );
    361         }
     329                set_owner( this->monitors[i], signallee );
     330        }
     331
     332        LIB_DEBUG_PRINT_SAFE( "Waiting on signal block\n" );
    362333
    363334        //Everything is ready to go to sleep
     
    365336
    366337
    367         // WE WOKE UP
    368 
     338
     339
     340        LIB_DEBUG_PRINT_SAFE( "Back from signal block\n" );
    369341
    370342        //We are back, restore the owners and recursions
    371343        lock_all( locks, count );
    372         restore_recursion( monitors, recursions, count );
     344        restore_recursion( this->monitors, recursions, count );
    373345        unlock_all( locks, count );
    374346
     
    376348}
    377349
    378 // Access the user_info of the thread waiting at the front of the queue
    379350uintptr_t front( condition * this ) {
    380351        verifyf( !is_empty(this),
     
    387358//-----------------------------------------------------------------------------
    388359// Internal scheduling
    389 int __accept_internal( unsigned short acc_count, __acceptable_t * acceptables ) {
    390         thread_desc * thrd = this_thread;
    391 
    392         // Create storage for monitor context
    393         monitor_ctx( acceptables->monitors, acceptables->count );
    394 
    395         // Lock all monitors (aggregates the lock them as well)
    396         lock_all( monitors, locks, count );
    397 
    398         // Create the node specific to this wait operation
    399         wait_ctx_primed( thrd, 0 );
    400 
    401         // Check if the entry queue
    402         thread_desc * next = search_entry_queue( acceptables, acc_count, monitors, count );
    403 
    404         if( !next ) {
    405                 // Update acceptables on the current monitors
    406                 for(int i = 0; i < count; i++) {
    407                         monitors[i]->acceptables = acceptables;
    408                         monitors[i]->acceptable_count = acc_count;
    409                 }
    410         }
    411 
    412         save_recursion( monitors, recursions, count );
    413 
    414         // Everything is ready to go to sleep
    415         BlockInternal( locks, count, &next, next ? 1 : 0 );
    416 
    417 
    418         //WE WOKE UP
    419 
    420 
    421         //We are back, restore the owners and recursions
    422         lock_all( locks, count );
    423         restore_recursion( monitors, recursions, count );
    424         int acc_idx = monitors[0]->accepted_index;
    425         unlock_all( locks, count );
    426 
    427         return acc_idx;
     360void __accept_internal( unsigned short count, __acceptable_t * acceptables, void (*func)(void) ) {
     361        // thread_desc * this = this_thread;
     362
     363        // unsigned short count = this->current_monitor_count;
     364        // unsigned int recursions[ count ];            //Save the current recursion levels to restore them later
     365        // spinlock *   locks     [ count ];            //We need to pass-in an array of locks to BlockInternal
     366
     367        // lock_all( this->current_monitors, locks, count );
     368
     369
     370
     371
     372
     373        // // // Everything is ready to go to sleep
     374        // // BlockInternal( locks, count, threads, thread_count );
     375
     376
     377        // //WE WOKE UP
     378
     379
     380        // //We are back, restore the owners and recursions
     381        // lock_all( locks, count );
     382        // restore_recursion( this->monitors, recursions, count );
     383        // unlock_all( locks, count );
    428384}
    429385
     
    459415}
    460416
    461 static inline int is_accepted( thread_desc * owner, monitor_desc * this, monitor_desc ** group, int group_cnt, void (*func)() ) {
    462         __acceptable_t* accs = this->acceptables; // Optim
    463         int acc_cnt = this->acceptable_count;
    464 
    465         // Check if there are any acceptable functions
    466         if( !accs ) return -1;
    467 
    468         // If this isn't the first monitor to test this, there is no reason to repeat the test.
    469         if( this != group[0] ) return group[0]->accepted_index;
    470 
    471         // For all acceptable functions check if this is the current function.
    472         OUT_LOOP:
    473         for( int i = 0; i < acc_cnt; i++ ) {
    474                 __acceptable_t * acc = &accs[i];
    475 
    476                 // if function matches, check the monitors
    477                 if( acc->func == func ) {
    478 
    479                         // If the group count is different then it can't be a match
    480                         if( acc->count != group_cnt ) return -1;
    481 
    482                         // Check that all the monitors match
    483                         for( int j = 0; j < group_cnt; j++ ) {
    484                                 // If not a match, check next function
    485                                 if( acc->monitors[j] != group[j] ) continue OUT_LOOP;
    486                         }
    487 
    488                         // It's a complete match, accept the call
    489                         return i;
    490                 }
    491         }
    492 
    493         // No function matched
    494         return -1;
    495 }
    496 
    497 static inline void init( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
    498         for(int i = 0; i < count; i++) {
    499                 (&criteria[i]){ monitors[i], waiter };
    500         }
    501 
    502         waiter->criteria = criteria;
    503 }
    504 
    505 static inline void init_push( int count, monitor_desc ** monitors, __condition_node_t * waiter, __condition_criterion_t * criteria ) {
    506         for(int i = 0; i < count; i++) {
    507                 (&criteria[i]){ monitors[i], waiter };
    508                 push( &criteria[i].target->signal_stack, &criteria[i] );
    509         }
    510 
    511         waiter->criteria = criteria;
    512 }
    513 
    514417static inline void lock_all( spinlock ** locks, unsigned short count ) {
    515418        for( int i = 0; i < count; i++ ) {
     
    602505}
    603506
    604 static inline thread_desc * search_entry_queue( __acceptable_t * acceptables, int acc_count, monitor_desc ** monitors, int count ) {
    605         return NULL;
    606 }
    607 
    608507void ?{}( __condition_blocked_queue_t * this ) {
    609508        this->head = NULL;
  • src/tests/preempt_longrun/stack.c

    re50e9ff rb3d413b  
    1515
    1616void main(worker_t * this) {
    17         volatile long long p = 5_021_609ul;
    18         volatile long long a = 326_417ul;
    19         volatile long long n = 1l;
    20         for (volatile long long i = 0; i < p; i++) {
     17        volatile long p = 5_021_609ul;
     18        volatile long a = 326_417ul;
     19        volatile long n = 1l;
     20        for (volatile long i = 0; i < p; i++) {
    2121                n *= a;
    2222                n %= p;
  • src/tests/sched-int-disjoint.c

    re50e9ff rb3d413b  
    33#include <monitor>
    44#include <thread>
    5 
    6 #include <time.h>
    75
    86static const unsigned long N = 10_000ul;
     
    109107// Main loop
    110108int main(int argc, char* argv[]) {
    111         rand48seed( time( NULL ) );
    112109        all_done = false;
    113110        processor p;
  • src/tests/sched-int-wait.c

    re50e9ff rb3d413b  
    55#include <thread>
    66
    7 #include <time.h>
    8 
    9 static const unsigned long N = 2_500ul;
     7static const unsigned long N = 10_000ul;
    108
    119#ifndef PREEMPTION_RATE
     
    121119// Main
    122120int main(int argc, char* argv[]) {
    123         rand48seed( time( NULL ) );
    124121        waiter_left = 4;
    125122        processor p[2];
Note: See TracChangeset for help on using the changeset viewer.