Ignore:
Timestamp:
Feb 15, 2018, 10:52:35 AM (6 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:
d27e340
Parents:
ff2d1139
Message:

Updated alarm to use bits/cfatime and fixed preemption for coroutines

File:
1 edited

Legend:

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

    rff2d1139 rb69ea6b  
    1818#include <stdio.h>
    1919#include <string.h>
    20 #include <time.h>
    2120#include <unistd.h>
    2221#include <sys/time.h>
     
    2726#include "preemption.h"
    2827
    29 //=============================================================================================
    30 // time type
    31 //=============================================================================================
    3228
    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 
    40 void ?{}( __cfa_time_t & this ) { this.val = 0; }
    41 void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
    42 
    43 void ?{}( 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
     29static 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
    4632        it_interval.tv_sec = 0;
    4733        it_interval.tv_usec = 0;
    4834}
    4935
    50 
    51 void ?{}( __cfa_time_t & this, timespec * curr ) {
     36static inline void ?{}( __cfa_time_t & this, timespec * curr ) {
    5237        uint64_t secs  = curr->tv_sec;
    5338        uint64_t nsecs = curr->tv_nsec;
    54         this.val = (secs * one_second) + nsecs;
     39        this.val = from_s(secs).val + nsecs;
    5540}
    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; }
    6641
    6742//=============================================================================================
     
    8459//=============================================================================================
    8560
    86 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) with( this ) {
     61void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s ) with( this ) {
    8762        this.thrd = thrd;
    8863        this.alarm = alarm;
     
    9368}
    9469
    95 void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) with( this ) {
     70void ?{}( alarm_node_t & this, processor   * proc, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s ) with( this ) {
    9671        this.proc = proc;
    9772        this.alarm = alarm;
Note: See TracChangeset for help on using the changeset viewer.