Ignore:
Timestamp:
2018-08-25T22:21:25Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cca80a2
Parents:
e2625b1a
Message:

Get rid of sys/time.h

This commit moves the POSIX-like time functionality from libc's
sys/time.h to libposix and introduces C11-like or HelenOS-specific
interfaces to libc.

Specifically, use of sys/time.h, struct timeval, suseconds_t and
gettimeofday is replaced by time.h (C11), struct timespec (C11), usec_t
(HelenOS) and getuptime / getrealtime (HelenOS).

Also attempt to fix the implementation of clock() to return microseconds
(clocks) rather than processor cycles and move it to libc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/thread/fibril.c

    re2625b1a rbd41ac52  
    6060typedef struct {
    6161        link_t link;
    62         struct timeval expires;
     62        struct timespec expires;
    6363        fibril_event_t *event;
    6464} _timeout_t;
     
    142142}
    143143
    144 static inline errno_t _ready_down(const struct timeval *expires)
     144static inline errno_t _ready_down(const struct timespec *expires)
    145145{
    146146        if (multithreaded)
     
    253253}
    254254
    255 static errno_t _ipc_wait(ipc_call_t *call, const struct timeval *expires)
     255static errno_t _ipc_wait(ipc_call_t *call, const struct timespec *expires)
    256256{
    257257        if (!expires)
     
    261261                return ipc_wait(call, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING);
    262262
    263         struct timeval now;
     263        struct timespec now;
    264264        getuptime(&now);
    265265
    266         if (tv_gteq(&now, expires))
     266        if (ts_gteq(&now, expires))
    267267                return ipc_wait(call, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING);
    268268
    269         return ipc_wait(call, tv_sub_diff(expires, &now), SYNCH_FLAGS_NONE);
     269        return ipc_wait(call, NSEC2USEC(ts_sub_diff(expires, &now)),
     270            SYNCH_FLAGS_NONE);
    270271}
    271272
     
    275276 * wait after new ready fibrils are added.
    276277 */
    277 static fibril_t *_ready_list_pop(const struct timeval *expires, bool locked)
     278static fibril_t *_ready_list_pop(const struct timespec *expires, bool locked)
    278279{
    279280        if (locked) {
     
    370371static fibril_t *_ready_list_pop_nonblocking(bool locked)
    371372{
    372         struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
     373        struct timespec tv = { .tv_sec = 0, .tv_nsec = 0 };
    373374        return _ready_list_pop(&tv, locked);
    374375}
     
    393394
    394395/* Blocks the current fibril until an IPC call arrives. */
    395 static errno_t _wait_ipc(ipc_call_t *call, const struct timeval *expires)
     396static errno_t _wait_ipc(ipc_call_t *call, const struct timespec *expires)
    396397{
    397398        futex_assert_is_not_locked(&fibril_futex);
     
    430431
    431432/** Fire all timeouts that expired. */
    432 static struct timeval *_handle_expired_timeouts(struct timeval *next_timeout)
    433 {
    434         struct timeval tv;
    435         getuptime(&tv);
     433static struct timespec *_handle_expired_timeouts(struct timespec *next_timeout)
     434{
     435        struct timespec ts;
     436        getuptime(&ts);
    436437
    437438        futex_lock(&fibril_futex);
     
    441442                _timeout_t *to = list_get_instance(cur, _timeout_t, link);
    442443
    443                 if (tv_gt(&to->expires, &tv)) {
     444                if (ts_gt(&to->expires, &ts)) {
    444445                        *next_timeout = to->expires;
    445446                        futex_unlock(&fibril_futex);
     
    535536        (void) arg;
    536537
    537         struct timeval next_timeout;
     538        struct timespec next_timeout;
    538539        while (true) {
    539                 struct timeval *to = _handle_expired_timeouts(&next_timeout);
     540                struct timespec *to = _handle_expired_timeouts(&next_timeout);
    540541                fibril_t *f = _ready_list_pop(to, false);
    541542                if (f) {
     
    615616                _timeout_t *cur = list_get_instance(tmp, _timeout_t, link);
    616617
    617                 if (tv_gteq(&cur->expires, &timeout->expires))
     618                if (ts_gteq(&cur->expires, &timeout->expires))
    618619                        break;
    619620
     
    634635 * @return ETIMEOUT if timed out. EOK otherwise.
    635636 */
    636 errno_t fibril_wait_timeout(fibril_event_t *event, const struct timeval *expires)
     637errno_t fibril_wait_timeout(fibril_event_t *event,
     638    const struct timespec *expires)
    637639{
    638640        assert(fibril_self()->rmutex_locks == 0);
     
    889891}
    890892
    891 void fibril_usleep(suseconds_t timeout)
    892 {
    893         struct timeval expires;
     893void fibril_usleep(usec_t timeout)
     894{
     895        struct timespec expires;
    894896        getuptime(&expires);
    895         tv_add_diff(&expires, timeout);
     897        ts_add_diff(&expires, USEC2NSEC(timeout));
    896898
    897899        fibril_event_t event = FIBRIL_EVENT_INIT;
     
    899901}
    900902
    901 void fibril_sleep(unsigned int sec)
    902 {
    903         struct timeval expires;
     903void fibril_sleep(sec_t sec)
     904{
     905        struct timespec expires;
    904906        getuptime(&expires);
    905907        expires.tv_sec += sec;
     
    916918}
    917919
    918 errno_t fibril_ipc_wait(ipc_call_t *call, const struct timeval *expires)
     920errno_t fibril_ipc_wait(ipc_call_t *call, const struct timespec *expires)
    919921{
    920922        return _wait_ipc(call, expires);
Note: See TracChangeset for help on using the changeset viewer.