summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/ccommon_api.md4
-rw-r--r--include/stc/algo/coroutine.h10
-rw-r--r--include/stc/algo/sort.h10
3 files changed, 12 insertions, 12 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index de421f2c..7aa94c50 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -389,7 +389,7 @@ To resume the coroutine from where it was suspended with *cco_yield()*, simply c
| | `cco_timer` | Timer type |
| | `cco_timer_await(tm)` | Await for timer to expire |
| | `cco_timer_await(tm, ret)` | Await with ret for timer to expire |
-| | `cco_timer_start(tm, double sec)` | Start timer for sec seconds |
+| | `cco_timer_start(tm, double sec)` | Start timer for sec seconds (usec prec.)|
| | `cco_timer_restart(tm)` | Restart timer with same duration |
| `bool` | `cco_timer_expired(tm)` | Return true if timer is expired |
| `double` | `cco_timer_remaining(tm)` | Return seconds remaining |
@@ -399,7 +399,7 @@ To resume the coroutine from where it was suspended with *cco_yield()*, simply c
| `void` | `cco_run(co, corocall) { }` | Run blocking until coro is done |
| | Time functions: | |
| `double` | `cco_time(void)` | Return secs with usec prec. since Epoch |
-| | `cco_sleep(double sec)` | Sleep for seconds |
+| | `cco_sleep(double sec)` | Sleep for seconds (msec or usec prec.) |
---
## RAII scope macros
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index 79819c55..1ac30fff 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -139,11 +139,11 @@ typedef struct {
_c_LINKC void GetSystemTimePreciseAsFileTime(struct _FILETIME*);
_c_LINKC void Sleep(unsigned long);
- static inline double cco_time(void) {
+ static inline double cco_time(void) { /* seconds since epoch */
static const unsigned long long epoch_offset = 116444736000000000ULL; /* 1/10th usecs betweeen Jan 1,1601 - Jan 1,1970 */
unsigned long long quad; /* 64-bit value, 100-nanosecond intervals since January 1, 1601 00:00 UTC */
GetSystemTimePreciseAsFileTime((struct _FILETIME*)&quad);
- return (double)(quad - epoch_offset)*1e-7; /* usecs since epoch */
+ return (double)(quad - epoch_offset)*1e-7;
}
static inline void cco_sleep(double sec) {
@@ -151,16 +151,16 @@ typedef struct {
}
#else
#include <sys/time.h>
- static inline double cco_time(void) {
+ static inline double cco_time(void) { /* seconds since epoch */
struct timeval tv;
gettimeofday(&tv, NULL);
- return tv.tv_sec + tv.tv_usec*1e-6;
+ return (double)tv.tv_sec + (double)tv.tv_usec*1e-6;
}
static inline void cco_sleep(double sec) {
struct timeval tv;
tv.tv_sec = (time_t)sec;
- tv.tv_usec = (suseconds_t)(1e6*(sec - tv.tv_sec));
+ tv.tv_usec = (suseconds_t)((sec - (double)(long)sec)*1e6);
select(0, NULL, NULL, NULL, &tv);
}
#endif
diff --git a/include/stc/algo/sort.h b/include/stc/algo/sort.h
index 20b7e1b3..bbd58427 100644
--- a/include/stc/algo/sort.h
+++ b/include/stc/algo/sort.h
@@ -24,7 +24,7 @@
template params:
#define i_val - value type [required]
#define i_less - less function. default: *x < *y
-#define i_tag name - define namearray_qsort(). i_tag defaults {i_val}
+#define i_type name - define {{name}}_sort_n(), else {{i_val}}array_sort_n().
// test:
#include <stdio.h>
@@ -32,12 +32,12 @@ template params:
#include <stc/algo/sort.h>
int main() {
- int arr[] = {23, 321, 5434, 25, 245, 1, 654, 33, 543, 21};
+ int nums[] = {23, 321, 5434, 25, 245, 1, 654, 33, 543, 21};
- intarray_qsort(arr, c_arraylen(arr));
+ intarray_sort_n(nums, c_arraylen(arr));
- for (int i = 0; i < c_arraylen(arr); i++)
- printf(" %d", arr[i]);
+ for (int i = 0; i < c_arraylen(nums); i++)
+ printf(" %d", nums[i]);
puts("");
}
*/