Changeset bd41ac52 in mainline for uspace/lib/posix


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/posix
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/include/posix/sys/time.h

    re2625b1a rbd41ac52  
    3434#define POSIX_SYS_TIME_H_
    3535
    36 #include "libc/sys/time.h"
     36#include "libc/time.h"
     37
     38struct timeval {
     39        time_t tv_sec;        /* seconds */
     40        suseconds_t tv_usec;  /* microseconds */
     41};
     42
     43extern int gettimeofday(struct timeval *, void *);
    3744
    3845#endif
  • uspace/lib/posix/include/posix/sys/types.h

    re2625b1a rbd41ac52  
    3838
    3939#include "libc/offset.h"
    40 #include "libc/sys/time.h"
    4140#include "libc/types/common.h"
    4241
     
    5655
    5756/* Clock Types */
    58 typedef long clock_t;
    5957typedef int clockid_t;
    6058
     59typedef long suseconds_t;
    6160
    6261#endif /* POSIX_SYS_TYPES_H_ */
  • uspace/lib/posix/include/posix/time.h

    re2625b1a rbd41ac52  
    4141#include <_bits/NULL.h>
    4242
    43 #ifndef CLOCKS_PER_SEC
    44 #define CLOCKS_PER_SEC (1000000L)
    45 #endif
     43#include "libc/time.h"
    4644
    4745#ifndef __locale_t_defined
     
    5755#define CLOCK_REALTIME ((clockid_t) 0)
    5856
    59 struct timespec {
    60         time_t tv_sec; /* Seconds. */
    61         long tv_nsec; /* Nanoseconds. */
    62 };
     57#define ASCTIME_BUF_LEN  26
    6358
    6459struct itimerspec {
     
    10499    const struct timespec *rqtp, struct timespec *rmtp);
    105100
    106 /* CPU Time */
    107 extern clock_t clock(void);
    108 
    109 
    110101#endif  // POSIX_TIME_H_
    111102
  • uspace/lib/posix/src/internal/common.h

    re2625b1a rbd41ac52  
    3838#include <stdio.h>
    3939#include <stdlib.h>
     40#include <errno.h>
    4041#include <offset.h>
    4142#include <vfs/vfs.h>
  • uspace/lib/posix/src/time.c

    re2625b1a rbd41ac52  
    3535
    3636#include "internal/common.h"
     37#include "posix/sys/types.h"
     38#include "posix/sys/time.h"
    3739#include "posix/time.h"
    3840
     
    4749#include "libc/malloc.h"
    4850#include "libc/task.h"
    49 #include "libc/stats.h"
    5051#include "libc/stddef.h"
    51 #include "libc/sys/time.h"
     52#include "libc/time.h"
    5253
    5354// TODO: test everything in this file
     
    219220        case CLOCK_REALTIME:
    220221                res->tv_sec = 0;
    221                 res->tv_nsec = 1000; /* Microsecond resolution. */
     222                res->tv_nsec = USEC2NSEC(1); /* Microsecond resolution. */
    222223                return 0;
    223224        default:
     
    244245                gettimeofday(&tv, NULL);
    245246                tp->tv_sec = tv.tv_sec;
    246                 tp->tv_nsec = tv.tv_usec * 1000;
     247                tp->tv_nsec = USEC2NSEC(tv.tv_usec);
    247248                return 0;
    248249        default:
     
    300301                }
    301302                if (rqtp->tv_nsec != 0) {
    302                         fibril_usleep(rqtp->tv_nsec / 1000);
     303                        fibril_usleep(NSEC2USEC(rqtp->tv_nsec));
    303304                }
    304305                return 0;
     
    309310}
    310311
    311 /**
    312  * Get CPU time used since the process invocation.
    313  *
    314  * @return Consumed CPU cycles by this process or -1 if not available.
    315  */
    316 clock_t clock(void)
    317 {
    318         clock_t total_cycles = -1;
    319         stats_task_t *task_stats = stats_get_task(task_get_id());
    320         if (task_stats) {
    321                 total_cycles = (clock_t) (task_stats->kcycles +
    322                     task_stats->ucycles);
    323                 free(task_stats);
    324                 task_stats = 0;
    325         }
    326 
    327         return total_cycles;
     312int gettimeofday(struct timeval *tv, void *tz)
     313{
     314        struct timespec ts;
     315
     316        getrealtime(&ts);
     317        tv->tv_sec = ts.tv_sec;
     318        tv->tv_usec = NSEC2USEC(ts.tv_nsec);
     319
     320        return 0;
    328321}
    329322
Note: See TracChangeset for help on using the changeset viewer.