Use magic statics instead of ATOMIC_STATIC. (#109)

This commit is contained in:
Peter Johnson
2017-11-17 09:29:20 -08:00
committed by GitHub
parent 20c8d29ae9
commit 3324bcc5ce
10 changed files with 6 additions and 42 deletions

View File

@@ -1,13 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2017 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 "Handle.h"
using namespace cs;
ATOMIC_STATIC_INIT(Sources)
ATOMIC_STATIC_INIT(Sinks)

View File

@@ -79,7 +79,7 @@ class Sources
: public UnlimitedHandleResource<Handle, SourceData, Handle::kSource> {
public:
static Sources& GetInstance() {
ATOMIC_STATIC(Sources, instance);
static Sources instance;
return instance;
}
@@ -91,8 +91,6 @@ class Sources
private:
Sources() = default;
ATOMIC_STATIC_DECL(Sources)
};
struct SinkData {
@@ -108,7 +106,7 @@ struct SinkData {
class Sinks : public UnlimitedHandleResource<Handle, SinkData, Handle::kSink> {
public:
static Sinks& GetInstance() {
ATOMIC_STATIC(Sinks, instance);
static Sinks instance;
return instance;
}
@@ -119,8 +117,6 @@ class Sinks : public UnlimitedHandleResource<Handle, SinkData, Handle::kSink> {
private:
Sinks() = default;
ATOMIC_STATIC_DECL(Sinks)
};
} // namespace cs

View File

@@ -14,8 +14,6 @@
using namespace cs;
ATOMIC_STATIC_INIT(Logger)
static void def_log_func(unsigned int level, const char* file,
unsigned int line, const char* msg) {
llvm::SmallString<128> buf;

View File

@@ -9,14 +9,13 @@
#define CSCORE_LOG_H_
#include <support/Logger.h>
#include <support/atomic_static.h>
namespace cs {
class Logger : public wpi::Logger {
public:
static Logger& GetInstance() {
ATOMIC_STATIC(Logger, instance);
static Logger instance;
return instance;
}
~Logger();
@@ -25,8 +24,6 @@ class Logger : public wpi::Logger {
private:
Logger();
ATOMIC_STATIC_DECL(Logger)
};
#define LOG(level, x) WPI_LOG(cs::Logger::GetInstance(), level, x)

View File

@@ -25,8 +25,6 @@
using namespace cs;
ATOMIC_STATIC_INIT(NetworkListener)
class NetworkListener::Thread : public wpi::SafeThread {
public:
void Main();

View File

@@ -9,14 +9,13 @@
#define CSCORE_NETWORKLISTENER_H_
#include <support/SafeThread.h>
#include <support/atomic_static.h>
namespace cs {
class NetworkListener {
public:
static NetworkListener& GetInstance() {
ATOMIC_STATIC(NetworkListener, instance);
static NetworkListener instance;
return instance;
}
~NetworkListener();
@@ -29,8 +28,6 @@ class NetworkListener {
class Thread;
wpi::SafeThreadOwner<Thread> m_owner;
ATOMIC_STATIC_DECL(NetworkListener)
};
} // namespace cs

View File

@@ -16,7 +16,6 @@
using namespace cs;
ATOMIC_STATIC_INIT(Notifier)
bool Notifier::s_destroyed = false;
namespace {

View File

@@ -11,7 +11,6 @@
#include <functional>
#include <support/SafeThread.h>
#include <support/atomic_static.h>
#include "cscore_cpp.h"
@@ -25,7 +24,7 @@ class Notifier {
public:
static Notifier& GetInstance() {
ATOMIC_STATIC(Notifier, instance);
static Notifier instance;
return instance;
}
~Notifier();
@@ -64,8 +63,6 @@ class Notifier {
std::function<void()> m_on_start;
std::function<void()> m_on_exit;
ATOMIC_STATIC_DECL(Notifier)
static bool s_destroyed;
};

View File

@@ -14,7 +14,6 @@
#include <llvm/ArrayRef.h>
#include <llvm/SmallVector.h>
#include <support/atomic_static.h>
#include <support/mutex.h>
namespace cs {
@@ -169,14 +168,12 @@ class StaticUnlimitedHandleResource
: public UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex> {
public:
static StaticUnlimitedHandleResource& GetInstance() {
ATOMIC_STATIC(StaticUnlimitedHandleResource, instance);
static StaticUnlimitedHandleResource instance;
return instance;
}
private:
StaticUnlimitedHandleResource() = default;
ATOMIC_STATIC_DECL(StaticUnlimitedHandleResource)
};
} // namespace cs

View File

@@ -1482,8 +1482,6 @@ typedef JSingletonCallbackManager<LogMessage> LoggerJNI;
} // anonymous namespace
ATOMIC_STATIC_INIT(LoggerJNI)
extern "C" {
/*