Ignore:
File:
1 edited

Legend:

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

    r1c273d0 r4aa2fb2  
    1616
    1717extern "C" {
    18 #include <errno.h>
    19 #include <stdio.h>
    20 #include <string.h>
    2118#include <time.h>
    22 #include <unistd.h>
    2319#include <sys/time.h>
    2420}
     
    2622#include "alarm.h"
    2723#include "kernel_private.h"
    28 #include "libhdr.h"
    2924#include "preemption.h"
    3025
     
    3631        timespec curr;
    3732        clock_gettime( CLOCK_REALTIME, &curr );
    38         __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
    39         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );
    40         return curr_time;
     33        return ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
    4134}
    4235
    4336void __kernel_set_timer( __cfa_time_t alarm ) {
    44         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );
    4537        itimerval val;
    4638        val.it_value.tv_sec = alarm / TIMEGRAN;                 // seconds
     
    7971}
    8072
    81 LIB_DEBUG_DO( bool validate( alarm_list_t * this ) {
    82         alarm_node_t ** it = &this->head;
    83         while( (*it) ) {
    84                 it = &(*it)->next;
    85         }
    86 
    87         return it == this->tail;
    88 })
    89 
    9073static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) {
    91         verify( !n->next );
     74        assert( !n->next );
    9275        if( p == this->tail ) {
    9376                this->tail = &n->next;
     
    9780        }
    9881        *p = n;
    99 
    100         verify( validate( this ) );
    10182}
    10283
     
    10889
    10990        insert_at( this, n, it );
    110 
    111         verify( validate( this ) );
    11291}
    11392
     
    121100                head->next = NULL;
    122101        }
    123         verify( validate( this ) );
    124102        return head;
    125103}
     
    127105static inline void remove_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t it ) {
    128106        verify( it );
    129         verify( (*it) == n );
     107        verify( (*it)->next == n );
    130108
    131         (*it) = n->next;
     109        (*it)->next = n->next;
    132110        if( !n-> next ) {
    133111                this->tail = it;
    134112        }
    135113        n->next = NULL;
    136 
    137         verify( validate( this ) );
    138114}
    139115
    140116static inline void remove( alarm_list_t * this, alarm_node_t * n ) {
    141117        alarm_node_t ** it = &this->head;
    142         while( (*it) && (*it) != n ) {
     118        while( (*it) && (*it)->next != n ) {
    143119                it = &(*it)->next;
    144120        }
    145121
    146         verify( validate( this ) );
    147 
    148122        if( *it ) { remove_at( this, n, it ); }
    149 
    150         verify( validate( this ) );
    151123}
    152124
    153125void register_self( alarm_node_t * this ) {
    154126        disable_interrupts();
    155         verify( !systemProcessor->pending_alarm );
    156         lock( &systemProcessor->alarm_lock, __PRETTY_FUNCTION__ );
     127        assert( !systemProcessor->pending_alarm );
     128        lock( &systemProcessor->alarm_lock );
    157129        {
    158                 verify( validate( &systemProcessor->alarms ) );
    159                 bool first = !systemProcessor->alarms.head;
    160 
    161130                insert( &systemProcessor->alarms, this );
    162131                if( systemProcessor->pending_alarm ) {
    163132                        tick_preemption();
    164133                }
    165                 if( first ) {
    166                         __kernel_set_timer( systemProcessor->alarms.head->alarm - __kernel_get_time() );
    167                 }
    168134        }
    169135        unlock( &systemProcessor->alarm_lock );
    170136        this->set = true;
    171         enable_interrupts( __PRETTY_FUNCTION__ );
     137        enable_interrupts();
    172138}
    173139
    174140void unregister_self( alarm_node_t * this ) {
    175         // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : unregister %p start\n", this );
    176141        disable_interrupts();
    177         lock( &systemProcessor->alarm_lock, __PRETTY_FUNCTION__ );
    178         {
    179                 verify( validate( &systemProcessor->alarms ) );
    180                 remove( &systemProcessor->alarms, this );
    181         }
     142        lock( &systemProcessor->alarm_lock );
     143        remove( &systemProcessor->alarms, this );
    182144        unlock( &systemProcessor->alarm_lock );
    183145        disable_interrupts();
    184146        this->set = false;
    185         // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Kernel : unregister %p end\n", this );
    186147}
Note: See TracChangeset for help on using the changeset viewer.