Changeset f07e037 for src


Ignore:
Timestamp:
Feb 23, 2017, 4:24:35 PM (8 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:
3bb51e1
Parents:
485fdcf
Message:

Basic monitor implementation

Location:
src/libcfa/concurrency
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel.c

    r485fdcf rf07e037  
    457457void append( simple_thread_list * this, thread * t ) {
    458458        assert( t->next == NULL );
     459        assert(this->tail != NULL);
    459460        *this->tail = t;
    460461        this->tail = &t->next;
     462        assert(this->tail != NULL);
    461463}
    462464
    463465thread * pop_head( simple_thread_list * this ) {
     466        assert(this->tail != NULL);
    464467        thread * head = this->head;
    465468        if( head ) {
     
    470473                head->next = NULL;
    471474        }       
    472        
     475        assert(this->tail != NULL);
    473476        return head;
    474477}
  • src/libcfa/concurrency/monitor

    r485fdcf rf07e037  
     1//                              -*- Mode: CFA -*-
     2//
     3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     4//
     5// The contents of this file are covered under the licence agreement in the
     6// file "LICENCE" distributed with Cforall.
     7//
     8// monitor --
     9//
     10// Author           : Thierry Delisle
     11// Created On       : Thd Feb 23 12:27:26 2017
     12// Last Modified By : Thierry Delisle
     13// Last Modified On : --
     14// Update Count     : 0
     15//
     16
     17#ifndef MONITOR_H
     18#define MONITOR_H
     19
     20#include "assert"
     21#include "invoke.h"
     22
     23struct monitor {
     24        spinlock lock;
     25        thread * holder;
     26        simple_thread_list entry_queue;
     27};
     28
     29void enter(monitor *);
     30void leave(monitor *);
     31
     32#endif //MONITOR_H
  • src/libcfa/concurrency/monitor.c

    r485fdcf rf07e037  
     1//                              -*- Mode: CFA -*-
     2//
     3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     4//
     5// The contents of this file are covered under the licence agreement in the
     6// file "LICENCE" distributed with Cforall.
     7//
     8// monitor.c --
     9//
     10// Author           : Thierry Delisle
     11// Created On       : Thd Feb 23 12:27:26 2017
     12// Last Modified By : Thierry Delisle
     13// Last Modified On : --
     14// Update Count     : 0
     15//
     16
     17#include "monitor"
     18
     19#include "kernel_private.h"
     20
     21void enter(monitor * this) {
     22        lock( &this->lock );
     23        thread * thrd = this_thread();
     24
     25        assert( this->entry_queue.tail != NULL );
     26
     27        if( this->holder ) {
     28                append( &this->entry_queue, thrd );
     29                ScheduleInternal( &this->lock );
     30                return;
     31        }
     32        else {
     33                this->holder = thrd;
     34        }
     35
     36        assert( this->entry_queue.tail != NULL );       
     37
     38        unlock( &this->lock );
     39}
     40
     41void leave(monitor * this) {
     42        lock( &this->lock );
     43
     44        assert( this->entry_queue.tail != NULL );       
     45
     46        thread * thrd = this_thread();
     47        assert( thrd == this->holder );
     48
     49        this->holder = pop_head( &this->entry_queue );
     50
     51        assert( this->entry_queue.tail != NULL );       
     52
     53        unlock( &this->lock );
     54        if( this->holder ) ScheduleThread( this->holder );
     55}
  • src/libcfa/concurrency/threads

    r485fdcf rf07e037  
    99//
    1010// Author           : Thierry Delisle
    11 // Created On       : Tue Jan 17 12:27:26 2016
     11// Created On       : Tue Jan 17 12:27:26 2017
    1212// Last Modified By : Thierry Delisle
    1313// Last Modified On : --
  • src/libcfa/concurrency/threads.c

    r485fdcf rf07e037  
    99//
    1010// Author           : Thierry Delisle
    11 // Created On       : Tue Jan 17 12:27:26 2016
     11// Created On       : Tue Jan 17 12:27:26 2017
    1212// Last Modified By : Thierry Delisle
    1313// Last Modified On : --
Note: See TracChangeset for help on using the changeset viewer.