Changeset bd41ac52 in mainline for uspace/lib/c/include


Ignore:
Timestamp:
2018-08-25T22:21:25Z (7 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.

Location:
uspace/lib/c/include
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/async.h

    re2625b1a rbd41ac52  
    4242#include <ipc/common.h>
    4343#include <fibril.h>
    44 #include <sys/time.h>
     44#include <time.h>
    4545#include <stdbool.h>
    4646#include <abi/proc/task.h>
     
    112112        async_get_call_timeout(data, 0)
    113113
    114 extern bool async_get_call_timeout(ipc_call_t *, suseconds_t);
     114extern bool async_get_call_timeout(ipc_call_t *, usec_t);
    115115
    116116/*
     
    140140
    141141extern void async_wait_for(aid_t, errno_t *);
    142 extern errno_t async_wait_timeout(aid_t, errno_t *, suseconds_t);
     142extern errno_t async_wait_timeout(aid_t, errno_t *, usec_t);
    143143extern void async_forget(aid_t);
    144144
  • uspace/lib/c/include/ddi.h

    re2625b1a rbd41ac52  
    3939#include <stddef.h>
    4040#include <stdint.h>
    41 #include <sys/time.h>
     41#include <time.h>
    4242#include <byteorder.h>
    4343#include <abi/ddi/irq.h>
     
    138138
    139139static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask,
    140     useconds_t delay)
     140    usec_t delay)
    141141{
    142142        uint8_t v = pio_read_8(reg);
     
    147147
    148148static inline uint16_t pio_change_16(ioport16_t *reg, uint16_t val,
    149     uint16_t mask, useconds_t delay)
     149    uint16_t mask, usec_t delay)
    150150{
    151151        uint16_t v = pio_read_16(reg);
     
    156156
    157157static inline uint32_t pio_change_32(ioport32_t *reg, uint32_t val,
    158     uint32_t mask, useconds_t delay)
     158    uint32_t mask, usec_t delay)
    159159{
    160160        uint32_t v = pio_read_32(reg);
     
    165165
    166166static inline uint64_t pio_change_64(ioport64_t *reg, uint64_t val,
    167     uint64_t mask, useconds_t delay)
     167    uint64_t mask, usec_t delay)
    168168{
    169169        uint64_t v = pio_read_64(reg);
     
    173173}
    174174
    175 static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, useconds_t d)
     175static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, usec_t d)
    176176{
    177177        return pio_change_8(r, v, 0, d);
    178178}
    179 static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, useconds_t d)
     179static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, usec_t d)
    180180{
    181181        return pio_change_16(r, v, 0, d);
    182182}
    183 static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, useconds_t d)
     183static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, usec_t d)
    184184{
    185185        return pio_change_32(r, v, 0, d);
    186186}
    187 static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, useconds_t d)
     187static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, usec_t d)
    188188{
    189189        return pio_change_64(r, v, 0, d);
    190190}
    191191
    192 static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, useconds_t d)
     192static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, usec_t d)
    193193{
    194194        return pio_change_8(r, 0, v, d);
    195195}
    196 static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, useconds_t d)
     196static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, usec_t d)
    197197{
    198198        return pio_change_16(r, 0, v, d);
    199199}
    200 static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, useconds_t d)
     200static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, usec_t d)
    201201{
    202202        return pio_change_32(r, 0, v, d);
    203203}
    204 static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, useconds_t d)
     204static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, usec_t d)
    205205{
    206206        return pio_change_64(r, 0, v, d);
  • uspace/lib/c/include/fibril.h

    re2625b1a rbd41ac52  
    6060extern void fibril_yield(void);
    6161
    62 extern void fibril_usleep(suseconds_t);
    63 extern void fibril_sleep(unsigned int);
     62extern void fibril_usleep(usec_t);
     63extern void fibril_sleep(sec_t);
    6464
    6565extern void fibril_enable_multithreaded(void);
  • uspace/lib/c/include/fibril_synch.h

    re2625b1a rbd41ac52  
    3939#include <adt/list.h>
    4040#include <tls.h>
    41 #include <sys/time.h>
     41#include <time.h>
    4242#include <stdbool.h>
    4343
     
    138138        fid_t handler_fid;
    139139
    140         suseconds_t delay;
     140        usec_t delay;
    141141        fibril_timer_fun_t fun;
    142142        void *arg;
     
    181181extern void fibril_condvar_initialize(fibril_condvar_t *);
    182182extern errno_t fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
    183     suseconds_t);
     183    usec_t);
    184184extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
    185185extern void fibril_condvar_signal(fibril_condvar_t *);
     
    188188extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *);
    189189extern void fibril_timer_destroy(fibril_timer_t *);
    190 extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,
     190extern void fibril_timer_set(fibril_timer_t *, usec_t, fibril_timer_fun_t,
    191191    void *);
    192 extern void fibril_timer_set_locked(fibril_timer_t *, suseconds_t,
     192extern void fibril_timer_set_locked(fibril_timer_t *, usec_t,
    193193    fibril_timer_fun_t, void *);
    194194extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
     
    198198extern void fibril_semaphore_up(fibril_semaphore_t *);
    199199extern void fibril_semaphore_down(fibril_semaphore_t *);
    200 extern errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *, suseconds_t);
     200extern errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *, usec_t);
    201201extern void fibril_semaphore_close(fibril_semaphore_t *);
    202202
     
    205205extern void mpsc_destroy(mpsc_t *);
    206206extern errno_t mpsc_send(mpsc_t *, const void *);
    207 extern errno_t mpsc_receive(mpsc_t *, void *, const struct timeval *);
     207extern errno_t mpsc_receive(mpsc_t *, void *, const struct timespec *);
    208208extern void mpsc_close(mpsc_t *);
    209209
  • uspace/lib/c/include/io/con_srv.h

    re2625b1a rbd41ac52  
    4545#include <io/style.h>
    4646#include <stdbool.h>
    47 #include <sys/time.h>
     47#include <time.h>
    4848#include <stddef.h>
    4949
     
    5555        void *sarg;
    5656        /** Period to check for abort */
    57         suseconds_t abort_timeout;
     57        usec_t abort_timeout;
    5858        bool aborted;
    5959} con_srvs_t;
  • uspace/lib/c/include/io/console.h

    re2625b1a rbd41ac52  
    3636#define LIBC_IO_CONSOLE_H_
    3737
    38 #include <sys/time.h>
     38#include <time.h>
    3939#include <io/concaps.h>
    4040#include <io/kbd_event.h>
     
    8585extern bool console_get_event(console_ctrl_t *, cons_event_t *);
    8686extern bool console_get_event_timeout(console_ctrl_t *, cons_event_t *,
    87     suseconds_t *);
     87    usec_t *);
    8888
    8989#endif
  • uspace/lib/c/include/time.h

    re2625b1a rbd41ac52  
    11/*
    2  * Copyright (c) 2007 Jakub Jermar
     2 * Copyright (c) 2018 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    4040#endif
    4141
    42 #include <sys/time.h>
    4342
     43/* ISO/IEC 9899:2011 7.27.1 (2) */
     44
     45#include <_bits/NULL.h>
     46
     47#define CLOCKS_PER_SEC  ((clock_t) 1000000)
     48
     49#define TIME_UTC        1
     50
     51
     52/* ISO/IEC 9899:2011 7.27.1 (3) */
     53
     54#include <_bits/size_t.h>
     55
     56/* ISO/IEC 9899:2011 7.27.1 (3), (4) */
     57
     58typedef long long time_t;
     59typedef long long clock_t;
     60
     61struct timespec {
     62        time_t tv_sec;
     63        long tv_nsec;
     64};
     65
     66struct tm {
     67        int tm_sec;
     68        int tm_nsec;
     69        int tm_min;
     70        int tm_hour;
     71        int tm_mday;
     72        int tm_mon;
     73        int tm_year;
     74        int tm_wday;
     75        int tm_yday;
     76        int tm_isdst;
     77};
     78
     79/* ISO/IEC 9899:2011 7.27.2.1 (1) */
     80extern clock_t clock(void);
     81
     82/* ISO/IEC 9899:2011 7.27.2.2 (1) */
     83extern double difftime(time_t, time_t);
     84
     85/* ISO/IEC 9899:2011 7.27.2.3 (1) */
     86extern time_t mktime(struct tm *);
     87
     88/* ISO/IEC 9899:2011 7.27.2.4 (1) */
    4489extern time_t time(time_t *);
     90
     91/* ISO/IEC 9899:2011 7.27.2.5 (1) */
     92extern int timespec_get(struct timespec *, int);
     93
     94/* ISO/IEC 9899:2011 7.27.3.1 (1) */
     95extern char *asctime(const struct tm *);
     96
     97/* ISO/IEC 9899:2011 7.27.3.2 (1) */
     98extern char *ctime(const time_t *);
     99
     100/* ISO/IEC 9899:2011 7.27.3.3 (1) */
     101extern struct tm *gmtime(const time_t *);
     102
     103/* ISO/IEC 9899:2011 7.27.3.4 (1) */
     104extern struct tm *localtime(const time_t *);
     105
     106/* ISO/IEC 9899:2011 7.27.3.5 (1) */
     107extern size_t strftime(char *, size_t, const char *, const struct tm *);
     108
     109/*
     110 * HelenOS specific extensions
     111 */
     112
     113#include <stdbool.h>
     114#include <_bits/errno.h>
     115
     116typedef long long sec_t;
     117typedef long long msec_t;
     118typedef long long usec_t;
     119typedef long long nsec_t;       /* good for +/- 292 years */
     120
     121#define SEC2MSEC(s)     ((s) * 1000ll)
     122#define SEC2USEC(s)     ((s) * 1000000ll)
     123#define SEC2NSEC(s)     ((s) * 1000000000ll)
     124
     125#define MSEC2SEC(ms)    ((ms) / 1000ll)
     126#define MSEC2USEC(ms)   ((ms) * 1000ll)
     127#define MSEC2NSEC(ms)   ((ms) * 1000000ll)
     128
     129#define USEC2SEC(us)    ((us) / 1000000ll)
     130#define USEC2MSEC(us)   ((us) / 1000ll)
     131#define USEC2NSEC(us)   ((us) * 1000ll)
     132
     133#define NSEC2SEC(ns)    ((ns) / 1000000000ll)
     134#define NSEC2MSEC(ns)   ((ns) / 1000000ll)
     135#define NSEC2USEC(ns)   ((ns) / 1000ll)
     136
     137extern void getuptime(struct timespec *);
     138extern void getrealtime(struct timespec *);
     139
     140extern void ts_add_diff(struct timespec *, nsec_t);
     141extern void ts_add(struct timespec *, const struct timespec *);
     142extern void ts_sub(struct timespec *, const struct timespec *);
     143extern nsec_t ts_sub_diff(const struct timespec *, const struct timespec *);
     144extern bool ts_gt(const struct timespec *, const struct timespec *);
     145extern bool ts_gteq(const struct timespec *, const struct timespec *);
     146
     147extern errno_t time_utc2tm(const time_t, struct tm *);
     148extern errno_t time_utc2str(const time_t, char *);
     149extern void time_tm2str(const struct tm *, char *);
     150extern errno_t time_ts2tm(const struct timespec *, struct tm *);
     151extern errno_t time_local2tm(const time_t, struct tm *);
     152extern errno_t time_local2str(const time_t, char *);
     153
     154extern void udelay(sysarg_t);
    45155
    46156#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.