Changeset 3a58347 in mainline


Ignore:
Timestamp:
2012-08-13T14:15:57Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45cbcaf4
Parents:
43e660c
Message:

The gettimeofday() function now asks for the current time to the real time clock driver, if present.
Add the getuptime() function which returns the system uptime.

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/time.c

    r43e660c r3a58347  
    5050#include <assert.h>
    5151#include <unistd.h>
     52#include <loc.h>
     53#include <device/clock_dev.h>
     54#include <malloc.h>
    5255
    5356#define ASCTIME_BUF_LEN 26
     
    480483 */
    481484int gettimeofday(struct timeval *tv, struct timezone *tz)
     485{
     486        int rc;
     487        struct tm t;
     488        category_id_t cat_id;
     489        size_t svc_cnt;
     490        service_id_t *svc_ids = NULL;
     491        service_id_t svc_id;
     492        char *svc_name = NULL;
     493
     494        static async_sess_t *clock_conn = NULL;
     495
     496        if (tz) {
     497                tz->tz_minuteswest = 0;
     498                tz->tz_dsttime = DST_NONE;
     499        }
     500
     501        if (clock_conn == NULL) {
     502                rc = loc_category_get_id("clock", &cat_id, IPC_FLAG_BLOCKING);
     503                if (rc != EOK)
     504                        goto ret_uptime;
     505
     506                rc = loc_category_get_svcs(cat_id, &svc_ids, &svc_cnt);
     507                if (rc != EOK)
     508                        goto ret_uptime;
     509
     510                if (svc_cnt == 0)
     511                        goto ret_uptime;
     512
     513                rc = loc_service_get_name(svc_ids[0], &svc_name);
     514                if (rc != EOK)
     515                        goto ret_uptime;
     516
     517                rc = loc_service_get_id(svc_name, &svc_id, 0);
     518                if (rc != EOK)
     519                        goto ret_uptime;
     520
     521                clock_conn = loc_service_connect(EXCHANGE_SERIALIZE,
     522                    svc_id, IPC_FLAG_BLOCKING);
     523                if (!clock_conn)
     524                        goto ret_uptime;
     525        }
     526
     527        rc = clock_dev_time_get(clock_conn, &t);
     528        if (rc != EOK)
     529                goto ret_uptime;
     530
     531        tv->tv_usec = 0;
     532        tv->tv_sec = mktime(&t);
     533
     534        free(svc_name);
     535        free(svc_ids);
     536
     537        return EOK;
     538
     539ret_uptime:
     540
     541        free(svc_name);
     542        free(svc_ids);
     543
     544        return getuptime(tv);
     545}
     546
     547int getuptime(struct timeval *tv)
    482548{
    483549        if (ktime == NULL) {
     
    501567        }
    502568       
    503         if (tz) {
    504                 tz->tz_minuteswest = 0;
    505                 tz->tz_dsttime = DST_NONE;
    506         }
    507        
    508569        sysarg_t s2 = ktime->seconds2;
    509570       
     
    519580        } else
    520581                tv->tv_sec = s1;
    521        
     582
    522583        return 0;
    523584}
  • uspace/lib/c/include/sys/time.h

    r43e660c r3a58347  
    7676extern int tv_gteq(struct timeval *tv1, struct timeval *tv2);
    7777extern int gettimeofday(struct timeval *tv, struct timezone *tz);
     78extern int getuptime(struct timeval *tv);
    7879
    7980extern void udelay(useconds_t);
Note: See TracChangeset for help on using the changeset viewer.