Since we are removing boost threads shortly, and since the boost::date_time has issues with thread safety on osx, we moved the code in CTimeUtils::GetTimeMS() into XbmcThread::currentClockMillis(). It was also adjusted so that the windows call to timeGetTime handles the wrapping correctly (which it didn't appear to do before)."
#include "threads/platform/Condition.h"
-#include <boost/date_time/microsec_time_clock.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-
+#include "threads/Time.h"
#include <stdio.h>
namespace XbmcThreads
ConditionVariable& cond;
P predicate;
- typedef boost::posix_time::ptime system_time;
-
- inline static unsigned long timeLeft(const system_time& endtime)
+ inline static unsigned long timeLeft(unsigned int endtime)
{
- long diff = (long)(endtime - boost::date_time::microsec_clock<system_time>::universal_time()).total_milliseconds();
- return diff < 0 ? 0 : (unsigned long)diff;
+ unsigned int cur = currentClockMillis();
+ return endtime <= cur ? 0 : (endtime - cur);
}
public:
bool ret = true;
if (!predicate)
{
- system_time const endtime = boost::date_time::microsec_clock<system_time>::universal_time() + boost::posix_time::milliseconds(milliseconds);
+ unsigned int endtime = currentClockMillis() + milliseconds;
bool notdone = true;
while (notdone && ret == true)
{
Event.cpp \
LockFree.cpp \
Thread.cpp \
+ Time.cpp \
platform/Implementation.cpp
LIB=threads.a
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include <stdint.h>
+
+#ifdef __APPLE__
+#if defined(__ppc__) || defined(__arm__)
+#include <mach/mach_time.h>
+#include <CoreVideo/CVHostTime.h>
+#else
+#include <time.h>
+#include "posix-realtime-stub.h"
+#endif
+#elif defined(_LINUX)
+#include <time.h>
+#elif defined(_WIN32)
+#include <windows.h>
+#endif
+
+namespace XbmcThreads
+{
+ unsigned int currentClockMillis()
+ {
+ uint64_t now_time;
+ static uint64_t start_time = 0;
+ static bool start_time_set = false;
+#ifdef _LINUX
+#if defined(__APPLE__) && (defined(__ppc__) || defined(__arm__))
+ now_time = CVGetCurrentHostTime() * 1000 / CVGetHostClockFrequency();
+#else
+ struct timespec ts = {};
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ now_time = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+#endif
+#else
+ now_time = (uint64_t)timeGetTime();
+#endif
+ if (!start_time_set)
+ {
+ start_time = now_time;
+ start_time_set = true;
+ }
+ return (now_time - start_time);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2005-2011 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#pragma once
+
+namespace XbmcThreads
+{
+ /**
+ * This function returns the system clock's number of milliseconds but with
+ * an arbitrary reference point. It handles the wrapping of any underlying
+ * system clock by setting a starting point at the first call. It should
+ * only be used for measuring time durations.
+ *
+ * Of course, on windows it just calls timeGetTime, so you're on your own.
+ */
+ unsigned int currentClockMillis();
+}
#include "TimeUtils.h"
#include "XBDateTime.h"
+#include "threads/Time.h"
#ifdef __APPLE__
#if defined(__ppc__) || defined(__arm__)
unsigned int CTimeUtils::GetTimeMS()
{
-#ifdef _LINUX
- uint64_t now_time;
- static uint64_t start_time = 0;
-#if defined(__APPLE__) && (defined(__ppc__) || defined(__arm__))
- now_time = CVGetCurrentHostTime() * 1000 / CVGetHostClockFrequency();
-#else
- struct timespec ts = {};
- clock_gettime(CLOCK_MONOTONIC, &ts);
- now_time = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
-#endif
- if (start_time == 0)
- start_time = now_time;
- return (now_time - start_time);
-#else
- return timeGetTime();
-#endif
+ return XbmcThreads::currentClockMillis();
}
CDateTime CTimeUtils::GetLocalTime(time_t time)