Commit 266c62de authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Add a method to disable shutdown timer

Reviewed By: yfeldblum

Differential Revision: D22071829

fbshipit-source-id: c7f0e1bc5a4257731bafee09144c33c9fb474e10
parent 29adc304
...@@ -393,6 +393,10 @@ void SingletonVault::startShutdownTimer() { ...@@ -393,6 +393,10 @@ void SingletonVault::startShutdownTimer() {
return; return;
} }
if (!shutdownTimeout_.count()) {
return;
}
struct sigevent sig; struct sigevent sig;
sig.sigev_notify = SIGEV_THREAD; sig.sigev_notify = SIGEV_THREAD;
sig.sigev_notify_function = fireShutdownSignalHelper; sig.sigev_notify_function = fireShutdownSignalHelper;
......
...@@ -520,6 +520,10 @@ class SingletonVault { ...@@ -520,6 +520,10 @@ class SingletonVault {
shutdownTimeout_ = shutdownTimeout; shutdownTimeout_ = shutdownTimeout;
} }
void disableShutdownTimeout() {
shutdownTimeout_ = std::chrono::milliseconds::zero();
}
void addToShutdownLog(std::string message); void addToShutdownLog(std::string message);
void startShutdownTimer(); void startShutdownTimer();
......
...@@ -1053,3 +1053,25 @@ TEST(Singleton, ShutdownTimer) { ...@@ -1053,3 +1053,25 @@ TEST(Singleton, ShutdownTimer) {
vault.startShutdownTimer(); vault.startShutdownTimer();
vault.destroyInstances(); vault.destroyInstances();
} }
TEST(Singleton, ShutdownTimerDisable) {
struct VaultTag {};
struct PrivateTag {};
struct Object {
~Object() {
/* sleep override */ std::this_thread::sleep_for(shutdownDuration);
}
std::chrono::milliseconds shutdownDuration;
};
using SingletonObject = Singleton<Object, PrivateTag, VaultTag>;
auto& vault = *SingletonVault::singleton<VaultTag>();
SingletonObject object;
vault.registrationComplete();
vault.disableShutdownTimeout();
SingletonObject::try_get()->shutdownDuration = 100ms;
vault.startShutdownTimer();
vault.destroyInstances();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment