system/clock: convert to C++
This commit is contained in:
		@@ -278,7 +278,7 @@ libsystem_a_SOURCES = \
 | 
				
			|||||||
	src/system/EventFD.cxx src/system/EventFD.hxx \
 | 
						src/system/EventFD.cxx src/system/EventFD.hxx \
 | 
				
			||||||
	src/system/SignalFD.cxx src/system/SignalFD.hxx \
 | 
						src/system/SignalFD.cxx src/system/SignalFD.hxx \
 | 
				
			||||||
	src/system/EPollFD.cxx src/system/EPollFD.hxx \
 | 
						src/system/EPollFD.cxx src/system/EPollFD.hxx \
 | 
				
			||||||
	src/system/clock.c src/system/clock.h
 | 
						src/system/Clock.cxx src/system/Clock.hxx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Event loop library
 | 
					# Event loop library
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "Timer.hxx"
 | 
					#include "Timer.hxx"
 | 
				
			||||||
#include "AudioFormat.hxx"
 | 
					#include "AudioFormat.hxx"
 | 
				
			||||||
#include "system/clock.h"
 | 
					#include "system/Clock.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <glib.h>
 | 
					#include <glib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -37,7 +37,7 @@ Timer::Timer(const AudioFormat af)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void Timer::Start()
 | 
					void Timer::Start()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	time = monotonic_clock_us();
 | 
						time = MonotonicClockUS();
 | 
				
			||||||
	started = true;
 | 
						started = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -58,7 +58,7 @@ void Timer::Add(int size)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
unsigned Timer::GetDelay() const
 | 
					unsigned Timer::GetDelay() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int64_t delay = (int64_t)(time - monotonic_clock_us()) / 1000;
 | 
						int64_t delay = (int64_t)(time - MonotonicClockUS()) / 1000;
 | 
				
			||||||
	if (delay < 0)
 | 
						if (delay < 0)
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,7 +74,7 @@ void Timer::Synchronize() const
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	assert(started);
 | 
						assert(started);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sleep_duration = time - monotonic_clock_us();
 | 
						sleep_duration = time - MonotonicClockUS();
 | 
				
			||||||
	if (sleep_duration > 0)
 | 
						if (sleep_duration > 0)
 | 
				
			||||||
		g_usleep(sleep_duration);
 | 
							g_usleep(sleep_duration);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,10 +19,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "Loop.hxx"
 | 
					#include "Loop.hxx"
 | 
				
			||||||
#include "system/clock.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_EPOLL
 | 
					#ifdef USE_EPOLL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "system/Clock.hxx"
 | 
				
			||||||
#include "TimeoutMonitor.hxx"
 | 
					#include "TimeoutMonitor.hxx"
 | 
				
			||||||
#include "SocketMonitor.hxx"
 | 
					#include "SocketMonitor.hxx"
 | 
				
			||||||
#include "IdleMonitor.hxx"
 | 
					#include "IdleMonitor.hxx"
 | 
				
			||||||
@@ -31,7 +31,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
EventLoop::EventLoop(Default)
 | 
					EventLoop::EventLoop(Default)
 | 
				
			||||||
	:SocketMonitor(*this),
 | 
						:SocketMonitor(*this),
 | 
				
			||||||
	 now_ms(::monotonic_clock_ms()),
 | 
						 now_ms(::MonotonicClockMS()),
 | 
				
			||||||
	 quit(false),
 | 
						 quit(false),
 | 
				
			||||||
	 n_events(0),
 | 
						 n_events(0),
 | 
				
			||||||
	 thread(ThreadId::Null())
 | 
						 thread(ThreadId::Null())
 | 
				
			||||||
@@ -114,7 +114,7 @@ EventLoop::Run()
 | 
				
			|||||||
	assert(!quit);
 | 
						assert(!quit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	do {
 | 
						do {
 | 
				
			||||||
		now_ms = ::monotonic_clock_ms();
 | 
							now_ms = ::MonotonicClockMS();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* invoke timers */
 | 
							/* invoke timers */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -162,7 +162,7 @@ EventLoop::Run()
 | 
				
			|||||||
		const int n = epoll.Wait(events, MAX_EVENTS, timeout_ms);
 | 
							const int n = epoll.Wait(events, MAX_EVENTS, timeout_ms);
 | 
				
			||||||
		n_events = std::max(n, 0);
 | 
							n_events = std::max(n, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		now_ms = ::monotonic_clock_ms();
 | 
							now_ms = ::MonotonicClockMS();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		assert(!quit);
 | 
							assert(!quit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2003-2012 The Music Player Daemon Project
 | 
					 * Copyright (C) 2003-2013 The Music Player Daemon Project
 | 
				
			||||||
 * http://www.musicpd.org
 | 
					 * http://www.musicpd.org
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software; you can redistribute it and/or modify
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
@@ -17,7 +17,7 @@
 | 
				
			|||||||
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "clock.h"
 | 
					#include "Clock.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef WIN32
 | 
					#ifdef WIN32
 | 
				
			||||||
#include <windows.h>
 | 
					#include <windows.h>
 | 
				
			||||||
@@ -31,7 +31,7 @@
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned
 | 
					unsigned
 | 
				
			||||||
monotonic_clock_ms(void)
 | 
					MonotonicClockMS(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifdef WIN32
 | 
					#ifdef WIN32
 | 
				
			||||||
	return GetTickCount();
 | 
						return GetTickCount();
 | 
				
			||||||
@@ -55,7 +55,7 @@ monotonic_clock_ms(void)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint64_t
 | 
					uint64_t
 | 
				
			||||||
monotonic_clock_us(void)
 | 
					MonotonicClockUS(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifdef WIN32
 | 
					#ifdef WIN32
 | 
				
			||||||
	LARGE_INTEGER l_value, l_frequency;
 | 
						LARGE_INTEGER l_value, l_frequency;
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2003-2012 The Music Player Daemon Project
 | 
					 * Copyright (C) 2003-2013 The Music Player Daemon Project
 | 
				
			||||||
 * http://www.musicpd.org
 | 
					 * http://www.musicpd.org
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software; you can redistribute it and/or modify
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
@@ -24,26 +24,18 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Returns the value of a monotonic clock in milliseconds.
 | 
					 * Returns the value of a monotonic clock in milliseconds.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
gcc_pure
 | 
					gcc_pure
 | 
				
			||||||
unsigned
 | 
					unsigned
 | 
				
			||||||
monotonic_clock_ms(void);
 | 
					MonotonicClockMS();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Returns the value of a monotonic clock in microseconds.
 | 
					 * Returns the value of a monotonic clock in microseconds.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
gcc_pure
 | 
					gcc_pure
 | 
				
			||||||
uint64_t
 | 
					uint64_t
 | 
				
			||||||
monotonic_clock_us(void);
 | 
					MonotonicClockUS();
 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		Reference in New Issue
	
	Block a user