1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: 3 #ident "$Id$" 4 /*====== 5 This file is part of PerconaFT. 6 7 8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. 9 10 PerconaFT is free software: you can redistribute it and/or modify 11 it under the terms of the GNU General Public License, version 2, 12 as published by the Free Software Foundation. 13 14 PerconaFT is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. 21 22 ---------------------------------------- 23 24 PerconaFT is free software: you can redistribute it and/or modify 25 it under the terms of the GNU Affero General Public License, version 3, 26 as published by the Free Software Foundation. 27 28 PerconaFT is distributed in the hope that it will be useful, 29 but WITHOUT ANY WARRANTY; without even the implied warranty of 30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 GNU Affero General Public License for more details. 32 33 You should have received a copy of the GNU Affero General Public License 34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. 35 36 ---------------------------------------- 37 38 Licensed under the Apache License, Version 2.0 (the "License"); 39 you may not use this file except in compliance with the License. 40 You may obtain a copy of the License at 41 42 http://www.apache.org/licenses/LICENSE-2.0 SIShrinkInstructions()43 44 Unless required by applicable law or agreed to in writing, software 45 distributed under the License is distributed on an "AS IS" BASIS, 46 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 47 See the License for the specific language governing permissions and 48 limitations under the License. 49 ======= */ 50 51 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." 52 53 #include "toku_time.h" 54 55 #if !defined(HAVE_CLOCK_REALTIME) 56 57 #include <errno.h> 58 #include <mach/clock.h> 59 #include <mach/mach.h> 60 61 int toku_clock_gettime(clockid_t clk_id, struct timespec *ts) { 62 if (clk_id != CLOCK_REALTIME) { 63 // dunno how to fake any of the other types of clock on osx 64 return EINVAL; 65 } 66 // We may want to share access to cclock for performance, but that requires 67 // initialization and destruction that's more complex than it's worth for 68 // OSX right now. Some day we'll probably just use pthread_once or 69 // library constructors. 70 clock_serv_t cclock; 71 mach_timespec_t mts; 72 host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &cclock); 73 clock_get_time(cclock, &mts); 74 mach_port_deallocate(mach_task_self(), cclock); 75 ts->tv_sec = mts.tv_sec; 76 ts->tv_nsec = mts.tv_nsec; 77 return 0; 78 } 79 #else // defined(HAVE_CLOCK_REALTIME) 80 81 #include <time.h> 82 int toku_clock_gettime(clockid_t clk_id, struct timespec *ts) { 83 return clock_gettime(clk_id, ts); 84 } 85 86 #endif 87