Ignore:
File:
1 edited

Legend:

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

    rb69ea6b rc40e7c5  
    1818#include <stdio.h>
    1919#include <string.h>
     20#include <time.h>
    2021#include <unistd.h>
    2122#include <sys/time.h>
     
    2627#include "preemption.h"
    2728
    28 
    29 static inline void ?{}( itimerval & this, __cfa_time_t * alarm ) with( this ) {
    30         it_value.tv_sec = alarm->val / (1`cfa_s).val;                   // seconds
    31         it_value.tv_usec = max( (alarm->val % (1`cfa_s).val) / (1`cfa_us).val, 1000 ); // microseconds
     29//=============================================================================================
     30// time type
     31//=============================================================================================
     32
     33#define one_second         1_000_000_000ul
     34#define one_milisecond         1_000_000ul
     35#define one_microsecond            1_000ul
     36#define one_nanosecond                 1ul
     37
     38__cfa_time_t zero_time = { 0 };
     39
     40void ?{}( __cfa_time_t & this ) { this.val = 0; }
     41void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
     42
     43void ?{}( itimerval & this, __cfa_time_t * alarm ) with( this ) {
     44        it_value.tv_sec = alarm->val / one_second;                      // seconds
     45        it_value.tv_usec = max( (alarm->val % one_second) / one_microsecond, 1000 ); // microseconds
    3246        it_interval.tv_sec = 0;
    3347        it_interval.tv_usec = 0;
    3448}
    3549
    36 static inline void ?{}( __cfa_time_t & this, timespec * curr ) {
     50
     51void ?{}( __cfa_time_t & this, timespec * curr ) {
    3752        uint64_t secs  = curr->tv_sec;
    3853        uint64_t nsecs = curr->tv_nsec;
    39         this.val = from_s(secs).val + nsecs;
    40 }
     54        this.val = (secs * one_second) + nsecs;
     55}
     56
     57__cfa_time_t ?=?( __cfa_time_t & this, zero_t rhs ) {
     58        this.val = 0;
     59        return this;
     60}
     61
     62__cfa_time_t from_s ( uint64_t val ) { __cfa_time_t ret; ret.val = val * 1_000_000_000ul; return ret; }
     63__cfa_time_t from_ms( uint64_t val ) { __cfa_time_t ret; ret.val = val *     1_000_000ul; return ret; }
     64__cfa_time_t from_us( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
     65__cfa_time_t from_ns( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
    4166
    4267//=============================================================================================
     
    5984//=============================================================================================
    6085
    61 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s ) with( this ) {
     86void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) with( this ) {
    6287        this.thrd = thrd;
    6388        this.alarm = alarm;
     
    6893}
    6994
    70 void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s ) with( this ) {
     95void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) with( this ) {
    7196        this.proc = proc;
    7297        this.alarm = alarm;
Note: See TracChangeset for help on using the changeset viewer.