Files
allwpilib/hal/src/main/native/sim/MockHooks.cpp
Peter Johnson f84018af5f Move entirety of llvm namespace to wpi namespace.
During shared library loading, a different libLLVM can be pulled in, causing
llvm symbols from dependent libraries to resolve to that library instead of
this one. This has been seen in the wild with the Mesa OpenGL implementation
in JavaFX applications (see wpilibsuite/shuffleboard#361).

This is clearly a very breaking change. For some level of backwards
compatibility, a namespace alias from llvm to wpi is performed in the "llvm"
headers.  Unfortunately, forward declarations of llvm classes will still break,
but compilers seem to generate clear error messages in those cases
("namespace alias 'llvm' not allowed here, assuming 'wpi'").

This change also moves all the wpiutil headers to a single "wpi" subdirectory
from the previously split "llvm", "support", "tcpsockets", and "udpsockets".
Shim headers will be added for backwards compatibility in a later commit.
2018-04-30 10:22:54 -07:00

57 lines
1.5 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <atomic>
#include <chrono>
#include <cstdio>
#include <thread>
#include <wpi/timestamp.h>
#include "MockHooksInternal.h"
static std::atomic<bool> programStarted{false};
static std::atomic<uint64_t> programStartTime{0};
namespace hal {
namespace init {
void InitializeMockHooks() {}
} // namespace init
} // namespace hal
namespace hal {
void RestartTiming() { programStartTime = wpi::Now(); }
int64_t GetFPGATime() {
auto now = wpi::Now();
auto currentTime = now - programStartTime;
return currentTime;
}
double GetFPGATimestamp() { return GetFPGATime() * 1.0e-6; }
void SetProgramStarted() { programStarted = true; }
} // namespace hal
using namespace hal;
extern "C" {
void HALSIM_WaitForProgramStart(void) {
int count = 0;
while (!programStarted) {
count++;
std::printf("Waiting for program start signal: %d\n", count);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
void HALSIM_SetProgramStarted(void) { SetProgramStarted(); }
void HALSIM_RestartTiming(void) { RestartTiming(); }
} // extern "C"