mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
artf4107: GetInstance() calls are now atomic
C++11 guarantees construction of static variables to be atomic, so this patch takes advantage of that. Change-Id: I4a3db0f19c5fa5461fef3b6b63d7b8fec596c962
This commit is contained in:
@@ -50,7 +50,6 @@ class Scheduler : public ErrorBase, public NamedSendable {
|
||||
|
||||
void ProcessCommandAddition(Command *command);
|
||||
|
||||
static Scheduler *_instance;
|
||||
Command::SubsystemSet m_subsystems;
|
||||
MUTEX_ID m_buttonsLock = nullptr;
|
||||
typedef std::vector<ButtonScheduler *> ButtonVector;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
Scheduler *Scheduler::_instance = nullptr;
|
||||
|
||||
Scheduler::Scheduler() {
|
||||
m_buttonsLock = initializeMutexNormal();
|
||||
m_additionsLock = initializeMutexNormal();
|
||||
@@ -38,8 +36,8 @@ Scheduler::~Scheduler() {
|
||||
* @return the {@link Scheduler}
|
||||
*/
|
||||
Scheduler *Scheduler::GetInstance() {
|
||||
if (_instance == nullptr) _instance = new Scheduler();
|
||||
return _instance;
|
||||
static Scheduler instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
* how many times GetInstance is called.
|
||||
*/
|
||||
LiveWindow *LiveWindow::GetInstance() {
|
||||
static LiveWindow *instance = new LiveWindow();
|
||||
|
||||
return instance;
|
||||
static LiveWindow instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,8 +55,6 @@ class CameraServer : public ErrorBase {
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
static CameraServer* s_instance;
|
||||
|
||||
public:
|
||||
static CameraServer* GetInstance();
|
||||
void SetImage(Image const* image);
|
||||
|
||||
@@ -82,8 +82,6 @@ class Preferences : public ErrorBase, public ITableListener {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Preferences *_instance;
|
||||
|
||||
/** The semaphore for accessing the file */
|
||||
MUTEX_ID m_fileLock = nullptr;
|
||||
/** The semaphore for beginning reads and writes to the file */
|
||||
|
||||
@@ -10,13 +10,10 @@
|
||||
#include <netdb.h>
|
||||
|
||||
constexpr uint8_t CameraServer::kMagicNumber[];
|
||||
CameraServer* CameraServer::s_instance = nullptr;
|
||||
|
||||
CameraServer* CameraServer::GetInstance() {
|
||||
if (s_instance == nullptr) {
|
||||
s_instance = new CameraServer;
|
||||
}
|
||||
return s_instance;
|
||||
static CameraServer instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
CameraServer::CameraServer()
|
||||
|
||||
@@ -28,7 +28,6 @@ const double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0;
|
||||
Log().Get(level)
|
||||
|
||||
const uint32_t DriverStation::kJoystickPorts;
|
||||
DriverStation* DriverStation::m_instance = nullptr;
|
||||
|
||||
/**
|
||||
* DriverStation constructor.
|
||||
@@ -73,7 +72,6 @@ DriverStation::DriverStation() {
|
||||
|
||||
DriverStation::~DriverStation() {
|
||||
m_task.Stop();
|
||||
m_instance = nullptr;
|
||||
deleteMultiWait(m_waitForDataSem);
|
||||
// Unregister our semaphore.
|
||||
HALSetNewDataSem(nullptr);
|
||||
@@ -111,10 +109,8 @@ void DriverStation::Run() {
|
||||
* @return Pointer to the DS instance
|
||||
*/
|
||||
DriverStation* DriverStation::GetInstance() {
|
||||
if (m_instance == nullptr) {
|
||||
m_instance = new DriverStation();
|
||||
}
|
||||
return m_instance;
|
||||
static DriverStation instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,8 +24,6 @@ static const char *kFileName = "/home/lvuser/wpilib-preferences.ini";
|
||||
static const char *kValuePrefix = "=\"";
|
||||
/** The characters to put after the value */
|
||||
static const char *kValueSuffix = "\"\n";
|
||||
/** The singleton instance */
|
||||
Preferences *Preferences::_instance = nullptr;
|
||||
|
||||
Preferences::Preferences()
|
||||
: m_readTask("PreferencesReadTask", (FUNCPTR)Preferences::InitReadTask),
|
||||
@@ -54,8 +52,8 @@ Preferences::~Preferences() {
|
||||
* @return pointer to the {@link Preferences}
|
||||
*/
|
||||
Preferences *Preferences::GetInstance() {
|
||||
if (_instance == nullptr) _instance = new Preferences;
|
||||
return _instance;
|
||||
static Preferences instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,10 +10,8 @@ using namespace gazebo;
|
||||
class MainNode {
|
||||
public:
|
||||
static MainNode* GetInstance() {
|
||||
if (instance == nullptr) {
|
||||
instance = new MainNode();
|
||||
}
|
||||
return instance;
|
||||
static MainNode instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
template<typename M>
|
||||
@@ -39,8 +37,6 @@ public:
|
||||
|
||||
transport::NodePtr main;
|
||||
private:
|
||||
static MainNode* instance;
|
||||
|
||||
MainNode() {
|
||||
gazebo::transport::init();
|
||||
main = transport::NodePtr(new transport::Node());
|
||||
|
||||
@@ -26,7 +26,6 @@ const uint32_t DriverStation::kBatteryChannel;
|
||||
const uint32_t DriverStation::kJoystickPorts;
|
||||
const uint32_t DriverStation::kJoystickAxes;
|
||||
constexpr float DriverStation::kUpdatePeriod;
|
||||
DriverStation* DriverStation::m_instance = nullptr;
|
||||
uint8_t DriverStation::m_updateNumber = 0;
|
||||
|
||||
/**
|
||||
@@ -70,7 +69,6 @@ DriverStation::DriverStation()
|
||||
|
||||
DriverStation::~DriverStation()
|
||||
{
|
||||
m_instance = nullptr;
|
||||
deleteMultiWait(m_waitForDataSem);
|
||||
deleteMutex(m_waitForDataMutex);
|
||||
// TODO: Release m_stateSemaphore and m_joystickSemaphore?
|
||||
@@ -81,11 +79,8 @@ DriverStation::~DriverStation()
|
||||
*/
|
||||
DriverStation* DriverStation::GetInstance()
|
||||
{
|
||||
if (m_instance == nullptr)
|
||||
{
|
||||
m_instance = new DriverStation();
|
||||
}
|
||||
return m_instance;
|
||||
static DriverStation instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
|
||||
#include "simulation/MainNode.h"
|
||||
MainNode* MainNode::instance = nullptr;
|
||||
Reference in New Issue
Block a user