From patchwork Mon Mar 14 14:30:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Richardson X-Patchwork-Id: 597055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qP0Xj0JFxz9t0t for ; Tue, 15 Mar 2016 01:30:44 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 61E3910279; Mon, 14 Mar 2016 07:30:35 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 0975710276 for ; Mon, 14 Mar 2016 07:30:34 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 885D34203A6 for ; Mon, 14 Mar 2016 08:30:33 -0600 (MDT) X-ASG-Debug-ID: 1457965833-09eadd060d1e8c70001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id zIAcUnug3UUQhTth (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 14 Mar 2016 08:30:33 -0600 (MDT) X-Barracuda-Envelope-From: lrichard@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 14 Mar 2016 14:30:32 -0000 Received-SPF: pass (mx1-pf1.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id CF84564D22 for ; Mon, 14 Mar 2016 14:30:31 +0000 (UTC) Received: from localhost.localdomain.com (vpn1-5-246.ams2.redhat.com [10.36.5.246]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2EEUPSv025100 for ; Mon, 14 Mar 2016 10:30:30 -0400 X-CudaMail-Envelope-Sender: lrichard@redhat.com From: Lance Richardson To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-313026839 X-CudaMail-DTE: 031416 X-CudaMail-Originating-IP: 209.132.183.28 Date: Mon, 14 Mar 2016 10:30:16 -0400 X-ASG-Orig-Subj: [##CM-E1-313026839##][PATCH 2/5] timeval: Add clock_gettime() for OS X Message-Id: <1457965819-9473-3-git-send-email-lrichard@redhat.com> In-Reply-To: <1457965819-9473-1-git-send-email-lrichard@redhat.com> References: <1457965819-9473-1-git-send-email-lrichard@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 14 Mar 2016 14:30:31 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1457965833 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 2/5] timeval: Add clock_gettime() for OS X X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" OS X does not implement clock_gettime(). Signed-off-by: Lance Richardson --- lib/timeval.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/timeval.c b/lib/timeval.c index d390df1..8190b87 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -41,8 +41,9 @@ VLOG_DEFINE_THIS_MODULE(timeval); -#ifdef _WIN32 +#if defined(_WIN32) || defined(__MACH__) typedef unsigned int clockid_t; +static int clock_gettime(clock_t id, struct timespec *ts); #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 1 @@ -51,7 +52,9 @@ typedef unsigned int clockid_t; #ifndef CLOCK_REALTIME #define CLOCK_REALTIME 2 #endif +#endif /* defined(_WIN32) || defined(__MACH__) */ +#ifdef _WIN32 /* Number of 100 ns intervals from January 1, 1601 till January 1, 1970. */ const static unsigned long long unix_epoch = 116444736000000000; #endif /* _WIN32 */ @@ -417,6 +420,34 @@ clock_gettime(clock_t id, struct timespec *ts) } #endif /* _WIN32 */ +#ifdef __MACH__ +#include +#include +static int +clock_gettime(clock_t id, struct timespec *ts) +{ + mach_timespec_t mts; + clock_serv_t clk; + clock_id_t cid; + + if (id == CLOCK_MONOTONIC) { + cid = SYSTEM_CLOCK; + } else if (id == CLOCK_REALTIME) { + cid = CALENDAR_CLOCK; + } else { + return -1; + } + + host_get_clock_service(mach_host_self(), cid, &clk); + clock_get_time(clk, &mts); + mach_port_deallocate(mach_task_self(), clk); + ts->tv_sec = mts.tv_sec; + ts->tv_nsec = mts.tv_nsec; + + return 0; +} +#endif + void xgettimeofday(struct timeval *tv) {