runtime: encapsulate checkpoint progress state
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
LPHEART thecore_heart = NULL;
|
LPHEART thecore_heart = NULL;
|
||||||
|
|
||||||
std::atomic<int> shutdowned = FALSE;
|
std::atomic<int> shutdowned = FALSE;
|
||||||
std::atomic<int> tics = 0;
|
|
||||||
unsigned int thecore_profiler[NUM_PF];
|
unsigned int thecore_profiler[NUM_PF];
|
||||||
|
|
||||||
static int pid_init(void)
|
static int pid_init(void)
|
||||||
@@ -115,5 +114,5 @@ int thecore_is_shutdowned(void)
|
|||||||
|
|
||||||
void thecore_tick(void)
|
void thecore_tick(void)
|
||||||
{
|
{
|
||||||
++tics;
|
signal_mark_progress();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
extern std::atomic<int> tics;
|
|
||||||
extern std::atomic<int> shutdowned;
|
extern std::atomic<int> shutdowned;
|
||||||
|
|
||||||
#include "heart.h"
|
#include "heart.h"
|
||||||
@@ -27,5 +26,4 @@ float thecore_time(void);
|
|||||||
float thecore_pulse_per_second(void);
|
float thecore_pulse_per_second(void);
|
||||||
int thecore_is_shutdowned(void);
|
int thecore_is_shutdowned(void);
|
||||||
|
|
||||||
void thecore_tick(void); // tics 증가
|
void thecore_tick(void); // checkpoint progress 증가
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,32 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::atomic<int> s_checkpoint_ticks { 0 };
|
||||||
|
|
||||||
|
const char* signal_checkpoint_backend_name_impl(ECheckpointBackend backend)
|
||||||
|
{
|
||||||
|
switch (backend)
|
||||||
|
{
|
||||||
|
case CHECKPOINT_BACKEND_NONE:
|
||||||
|
return "none";
|
||||||
|
case CHECKPOINT_BACKEND_VIRTUAL_TIMER:
|
||||||
|
return "virtual-timer";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef OS_WINDOWS
|
#ifdef OS_WINDOWS
|
||||||
void signal_setup() {}
|
void signal_setup() {}
|
||||||
void signal_timer_disable() {}
|
void signal_timer_disable() {}
|
||||||
void signal_timer_enable(int timeout_seconds) {}
|
void signal_timer_enable(int timeout_seconds) {}
|
||||||
|
void signal_mark_progress() {}
|
||||||
|
ECheckpointBackend signal_checkpoint_backend() { return CHECKPOINT_BACKEND_NONE; }
|
||||||
|
const char* signal_checkpoint_backend_name(ECheckpointBackend backend) { return signal_checkpoint_backend_name_impl(backend); }
|
||||||
#else
|
#else
|
||||||
#define RETSIGTYPE void
|
#define RETSIGTYPE void
|
||||||
|
|
||||||
@@ -16,13 +39,13 @@ RETSIGTYPE reap(int sig)
|
|||||||
|
|
||||||
RETSIGTYPE checkpointing(int sig)
|
RETSIGTYPE checkpointing(int sig)
|
||||||
{
|
{
|
||||||
if (!tics.load())
|
if (!s_checkpoint_ticks.load())
|
||||||
{
|
{
|
||||||
sys_err("CHECKPOINT shutdown: tics did not updated.");
|
sys_err("CHECKPOINT shutdown: tics did not updated.");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tics.store(0);
|
s_checkpoint_ticks.store(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,4 +104,19 @@ void signal_setup(void)
|
|||||||
signal(SIGUSR1, usrsig);
|
signal(SIGUSR1, usrsig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void signal_mark_progress()
|
||||||
|
{
|
||||||
|
s_checkpoint_ticks.fetch_add(1, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
ECheckpointBackend signal_checkpoint_backend()
|
||||||
|
{
|
||||||
|
return CHECKPOINT_BACKEND_VIRTUAL_TIMER;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* signal_checkpoint_backend_name(ECheckpointBackend backend)
|
||||||
|
{
|
||||||
|
return signal_checkpoint_backend_name_impl(backend);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
enum ECheckpointBackend
|
||||||
|
{
|
||||||
|
CHECKPOINT_BACKEND_NONE = 0,
|
||||||
|
CHECKPOINT_BACKEND_VIRTUAL_TIMER = 1,
|
||||||
|
};
|
||||||
|
|
||||||
void signal_setup();
|
void signal_setup();
|
||||||
void signal_timer_disable();
|
void signal_timer_disable();
|
||||||
void signal_timer_enable(int timeout_seconds);
|
void signal_timer_enable(int timeout_seconds);
|
||||||
|
void signal_mark_progress();
|
||||||
|
ECheckpointBackend signal_checkpoint_backend();
|
||||||
|
const char* signal_checkpoint_backend_name(ECheckpointBackend backend);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "game/stdafx.h"
|
#include "game/stdafx.h"
|
||||||
#include "game/SecureCipher.h"
|
#include "game/SecureCipher.h"
|
||||||
#include "libthecore/fdwatch.h"
|
#include "libthecore/fdwatch.h"
|
||||||
|
#include "libthecore/signal.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -309,6 +310,19 @@ void TestFdwatchBackendMetadata()
|
|||||||
fdwatch_delete(fdw);
|
fdwatch_delete(fdw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestCheckpointBackendMetadata()
|
||||||
|
{
|
||||||
|
#ifdef OS_WINDOWS
|
||||||
|
Expect(signal_checkpoint_backend() == CHECKPOINT_BACKEND_NONE, "Expected no checkpoint backend on Windows");
|
||||||
|
Expect(std::strcmp(signal_checkpoint_backend_name(signal_checkpoint_backend()), "none") == 0,
|
||||||
|
"Unexpected checkpoint backend name on Windows");
|
||||||
|
#else
|
||||||
|
Expect(signal_checkpoint_backend() == CHECKPOINT_BACKEND_VIRTUAL_TIMER, "Expected virtual timer checkpoint backend");
|
||||||
|
Expect(std::strcmp(signal_checkpoint_backend_name(signal_checkpoint_backend()), "virtual-timer") == 0,
|
||||||
|
"Unexpected checkpoint backend name");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void TestFdwatchSlotReuseAfterDelete()
|
void TestFdwatchSlotReuseAfterDelete()
|
||||||
{
|
{
|
||||||
int sockets_a[2] = { -1, -1 };
|
int sockets_a[2] = { -1, -1 };
|
||||||
@@ -358,6 +372,7 @@ int main()
|
|||||||
TestSecureCipherRoundTrip();
|
TestSecureCipherRoundTrip();
|
||||||
TestSocketAuthWireFlow();
|
TestSocketAuthWireFlow();
|
||||||
TestFdwatchBackendMetadata();
|
TestFdwatchBackendMetadata();
|
||||||
|
TestCheckpointBackendMetadata();
|
||||||
TestFdwatchReadAndOneshotWrite();
|
TestFdwatchReadAndOneshotWrite();
|
||||||
TestFdwatchSlotReuseAfterDelete();
|
TestFdwatchSlotReuseAfterDelete();
|
||||||
std::cout << "metin smoke tests passed\n";
|
std::cout << "metin smoke tests passed\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user