Ignore:
Timestamp:
Jul 12, 2017, 9:50:58 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
1a6e855
Parents:
8b47e50 (diff), acb89ed (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r8b47e50 ref6851a  
    1616
    1717extern "C" {
     18#include <errno.h>
     19#include <stdio.h>
     20#include <string.h>
    1821#include <time.h>
     22#include <unistd.h>
    1923#include <sys/time.h>
    2024}
     25
     26#include "libhdr.h"
    2127
    2228#include "alarm.h"
     
    3137        timespec curr;
    3238        clock_gettime( CLOCK_REALTIME, &curr );
    33         return ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
     39        __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
     40        // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );
     41        return curr_time;
    3442}
    3543
    3644void __kernel_set_timer( __cfa_time_t alarm ) {
     45        LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );
    3746        itimerval val;
    3847        val.it_value.tv_sec = alarm / TIMEGRAN;                 // seconds
     
    7180}
    7281
     82LIB_DEBUG_DO( bool validate( alarm_list_t * this ) {
     83        alarm_node_t ** it = &this->head;
     84        while( (*it) ) {
     85                it = &(*it)->next;
     86        }
     87
     88        return it == this->tail;
     89})
     90
    7391static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) {
    74         assert( !n->next );
     92        verify( !n->next );
    7593        if( p == this->tail ) {
    7694                this->tail = &n->next;
     
    8098        }
    8199        *p = n;
     100
     101        verify( validate( this ) );
    82102}
    83103
     
    89109
    90110        insert_at( this, n, it );
     111
     112        verify( validate( this ) );
    91113}
    92114
     
    100122                head->next = NULL;
    101123        }
     124        verify( validate( this ) );
    102125        return head;
    103126}
     
    105128static inline void remove_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t it ) {
    106129        verify( it );
    107         verify( (*it)->next == n );
     130        verify( (*it) == n );
    108131
    109         (*it)->next = n->next;
     132        (*it) = n->next;
    110133        if( !n-> next ) {
    111134                this->tail = it;
    112135        }
    113136        n->next = NULL;
     137
     138        verify( validate( this ) );
    114139}
    115140
    116141static inline void remove( alarm_list_t * this, alarm_node_t * n ) {
    117142        alarm_node_t ** it = &this->head;
    118         while( (*it) && (*it)->next != n ) {
     143        while( (*it) && (*it) != n ) {
    119144                it = &(*it)->next;
    120145        }
    121146
     147        verify( validate( this ) );
     148
    122149        if( *it ) { remove_at( this, n, it ); }
     150
     151        verify( validate( this ) );
    123152}
    124153
    125154void register_self( alarm_node_t * this ) {
    126155        disable_interrupts();
    127         assert( !systemProcessor->pending_alarm );
    128         lock( &systemProcessor->alarm_lock );
     156        verify( !systemProcessor->pending_alarm );
     157        lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
    129158        {
     159                verify( validate( &systemProcessor->alarms ) );
     160                bool first = !systemProcessor->alarms.head;
     161
    130162                insert( &systemProcessor->alarms, this );
    131163                if( systemProcessor->pending_alarm ) {
    132164                        tick_preemption();
    133165                }
     166                if( first ) {
     167                        __kernel_set_timer( systemProcessor->alarms.head->alarm - __kernel_get_time() );
     168                }
    134169        }
    135170        unlock( &systemProcessor->alarm_lock );
    136171        this->set = true;
    137         enable_interrupts();
     172        enable_interrupts( DEBUG_CTX );
    138173}
    139174
    140175void unregister_self( alarm_node_t * this ) {
     176        // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : unregister %p start\n", this );
    141177        disable_interrupts();
    142         lock( &systemProcessor->alarm_lock );
    143         remove( &systemProcessor->alarms, this );
     178        lock( &systemProcessor->alarm_lock DEBUG_CTX2 );
     179        {
     180                verify( validate( &systemProcessor->alarms ) );
     181                remove( &systemProcessor->alarms, this );
     182        }
    144183        unlock( &systemProcessor->alarm_lock );
    145         disable_interrupts();
     184        enable_interrupts( DEBUG_CTX );
    146185        this->set = false;
     186        // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Kernel : unregister %p end\n", this );
    147187}
Note: See TracChangeset for help on using the changeset viewer.