Changes in src/libcfa/concurrency/alarm.c [b69ea6b:c40e7c5]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/alarm.c
rb69ea6b rc40e7c5 18 18 #include <stdio.h> 19 19 #include <string.h> 20 #include <time.h> 20 21 #include <unistd.h> 21 22 #include <sys/time.h> … … 26 27 #include "preemption.h" 27 28 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 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 32 46 it_interval.tv_sec = 0; 33 47 it_interval.tv_usec = 0; 34 48 } 35 49 36 static inline void ?{}( __cfa_time_t & this, timespec * curr ) { 50 51 void ?{}( __cfa_time_t & this, timespec * curr ) { 37 52 uint64_t secs = curr->tv_sec; 38 53 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; } 41 66 42 67 //============================================================================================= … … 59 84 //============================================================================================= 60 85 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 ) {86 void ?{}( alarm_node_t & this, thread_desc * thrd, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) with( this ) { 62 87 this.thrd = thrd; 63 88 this.alarm = alarm; … … 68 93 } 69 94 70 void ?{}( alarm_node_t & this, processor * proc, __cfa_time_t alarm = 0`cfa_s, __cfa_time_t period = 0`cfa_s) with( this ) {95 void ?{}( alarm_node_t & this, processor * proc, __cfa_time_t alarm = zero_time, __cfa_time_t period = zero_time ) with( this ) { 71 96 this.proc = proc; 72 97 this.alarm = alarm;
Note:
See TracChangeset
for help on using the changeset viewer.