PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
validator/PlatformTimer.cpp
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: platforms/validator/PlatformTimer.cpp
4// Purpose: Validator Platform Timer Implementation
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2025 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9// This file is part of the PEBL project.
10//
11// PEBL is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2 of the License, or
14// (at your option) any later version.
15//
16// PEBL is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with PEBL; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25#include "PlatformTimer.h"
26#include <thread>
27#include <sys/time.h>
28
30 : mStartTime(std::chrono::steady_clock::now()) {
31}
32
34}
35
36void PlatformTimer::Wait(unsigned long int msecs) {
37 std::this_thread::sleep_for(std::chrono::milliseconds(msecs));
38}
39
40void PlatformTimer::Sleep(unsigned long int msecs) {
41 // For validator platform, Sleep and Wait are identical (both yield CPU)
42 std::this_thread::sleep_for(std::chrono::milliseconds(msecs));
43}
44
45unsigned long int PlatformTimer::GetTime() const {
46 auto now = std::chrono::steady_clock::now();
47 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - mStartTime);
48 return static_cast<unsigned long int>(duration.count());
49}
50
51void PlatformTimer::GetTimeOfDay(unsigned long & secs, unsigned long & msecs) {
52 struct timeval tv;
53 gettimeofday(&tv, NULL);
54 secs = tv.tv_sec;
55 msecs = tv.tv_usec / 1000;
56}
57
58int PlatformTimer::GetState(int iface) const {
59 return 0;
60}
61
62std::ostream& PlatformTimer::SendToStream(std::ostream& out) const {
63 out << "PlatformTimer (validator)";
64 return out;
65}
#define NULL
Definition BinReloc.cpp:317
virtual void Sleep(unsigned long int msecs)
virtual void GetTimeOfDay(unsigned long &secs, unsigned long &msecs)
PlatformTimer()
The Standard constructor.
virtual void Wait(unsigned long int msecs)
virtual unsigned long int GetTime() const
virtual int GetState(int iface) const
virtual ~PlatformTimer()
The Standard destructor.