Merge branch 'master' into eduardo-camacho/feature/eduardoc-objectivec_wrapper
This commit is contained in:
Коммит
44ab7fc9bb
|
@ -46,7 +46,7 @@ namespace ARIASDK_NS_BEGIN
|
|||
/// <summary>
|
||||
/// The time (in milliseconds since epoch) when this work item should be executed
|
||||
/// </summary>
|
||||
int64_t TargetTime;
|
||||
uint64_t TargetTime;
|
||||
|
||||
/// <summary>
|
||||
/// The Task class destructor.
|
||||
|
|
|
@ -170,7 +170,7 @@ namespace ARIASDK_NS_BEGIN {
|
|||
|
||||
if ((m_DbSizeLimit != 0) && (m_DbSizeEstimate>m_DbSizeLimit))
|
||||
{
|
||||
uint64_t now = (uint64_t)PAL::getMonotonicTimeMs();
|
||||
auto now = PAL::getMonotonicTimeMs();
|
||||
if (std::abs(static_cast<long>(now-m_isStorageFullNotificationSendTime)) > static_cast<long>(DB_FULL_CHECK_TIME_MS))
|
||||
{
|
||||
// Notify the client that the DB is getting full, but only once in DB_FULL_CHECK_TIME_MS
|
||||
|
|
|
@ -671,7 +671,7 @@ namespace ARIASDK_NS_BEGIN {
|
|||
return false;
|
||||
}
|
||||
|
||||
int64_t startTime = PAL::getMonotonicTimeMs();
|
||||
auto startTime = PAL::getMonotonicTimeMs();
|
||||
LOG_DEBUG("=== [%p] execute2 step...", m_stmt);
|
||||
int result = g_sqlite3Proxy->sqlite3_step(m_stmt);
|
||||
m_duration = static_cast<unsigned>(PAL::getMonotonicTimeMs() - startTime);
|
||||
|
|
|
@ -384,7 +384,7 @@ namespace PAL_NS_BEGIN {
|
|||
* - PAL WorkItem scheduler
|
||||
* - SQLiteWrapper perf counter
|
||||
*/
|
||||
int64_t getMonotonicTimeMs()
|
||||
uint64_t getMonotonicTimeMs()
|
||||
{
|
||||
#ifdef USE_WIN32_PERFCOUNTER
|
||||
/* Win32 API implementation */
|
||||
|
@ -401,7 +401,7 @@ namespace PAL_NS_BEGIN {
|
|||
|
||||
LARGE_INTEGER now;
|
||||
::QueryPerformanceCounter(&now);
|
||||
return now.QuadPart / ticksPerMillisecond;
|
||||
return static_cast<uint64_t>(now.QuadPart / ticksPerMillisecond);
|
||||
#else
|
||||
/* Cross-platform C++11 implementation */
|
||||
return std::chrono::steady_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace PAL_NS_BEGIN
|
|||
/**
|
||||
* Return the monotonic system clock time in milliseconds (since unspecified point).
|
||||
*/
|
||||
extern int64_t getMonotonicTimeMs();
|
||||
extern uint64_t getMonotonicTimeMs();
|
||||
|
||||
/**
|
||||
* Return the current system time in milliseconds (since the UNIX epoch - Jan 1, 1970).
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace PAL_NS_BEGIN {
|
|||
{
|
||||
this->TypeName = TYPENAME(call);
|
||||
this->Type = Task::Call;
|
||||
this->TargetTime = -1;
|
||||
this->TargetTime = 0;
|
||||
}
|
||||
|
||||
TaskCall(TCall& call, int64_t targetTime) :
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#if defined(MATSDK_PAL_CPP11) || defined(MATSDK_PAL_WIN32)
|
||||
|
||||
/* Maximum scheduler interval for SDK is 1 hour required for clamping in case of monotonic clock drift */
|
||||
#define MAX_FUTURE_DELTA_MS (60 * 60 * 1000)
|
||||
|
||||
namespace PAL_NS_BEGIN {
|
||||
|
||||
class WorkerThreadShutdownItem : public Task
|
||||
|
@ -124,20 +127,33 @@ namespace PAL_NS_BEGIN {
|
|||
WorkerThread* self = reinterpret_cast<WorkerThread*>(lpThreadParameter);
|
||||
LOG_INFO("Running thread %u", std::this_thread::get_id());
|
||||
|
||||
std::unique_ptr<MAT::Task> item = nullptr;
|
||||
for (;;) {
|
||||
std::unique_ptr<MAT::Task> item = nullptr;
|
||||
wakeupCount++;
|
||||
unsigned nextTimerInMs = UINT_MAX;
|
||||
unsigned nextTimerInMs = MAX_FUTURE_DELTA_MS;
|
||||
{
|
||||
LOCKGUARD(self->m_lock);
|
||||
|
||||
int64_t now = getMonotonicTimeMs();
|
||||
if (!self->m_timerQueue.empty() && self->m_timerQueue.front()->TargetTime <= now) {
|
||||
item = std::unique_ptr<MAT::Task>(self->m_timerQueue.front());
|
||||
self->m_timerQueue.pop_front();
|
||||
}
|
||||
auto now = getMonotonicTimeMs();
|
||||
if (!self->m_timerQueue.empty()) {
|
||||
nextTimerInMs = static_cast<unsigned>(self->m_timerQueue.front()->TargetTime - now);
|
||||
const auto currTargetTime = self->m_timerQueue.front()->TargetTime;
|
||||
if (currTargetTime <= now) {
|
||||
// process the item at the front immediately
|
||||
item = std::unique_ptr<MAT::Task>(self->m_timerQueue.front());
|
||||
self->m_timerQueue.pop_front();
|
||||
} else {
|
||||
// timed call in future, we need to resort the items in the queue
|
||||
const auto delta = currTargetTime - now;
|
||||
if (delta > MAX_FUTURE_DELTA_MS) {
|
||||
const auto itemPtr = self->m_timerQueue.front();
|
||||
self->m_timerQueue.pop_front();
|
||||
itemPtr->TargetTime = now + MAX_FUTURE_DELTA_MS;
|
||||
self->Queue(itemPtr);
|
||||
continue;
|
||||
}
|
||||
// value used for sleep in case if m_queue ends up being empty
|
||||
nextTimerInMs = static_cast<unsigned>(delta);
|
||||
}
|
||||
}
|
||||
|
||||
if (!self->m_queue.empty() && !item) {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <limits>
|
||||
|
||||
#define ABS64(a,b) ((a>b)?(a-b):(b-a))
|
||||
|
||||
namespace ARIASDK_NS_BEGIN {
|
||||
|
||||
int const DEFAULT_DELAY_SEND_HTTP = 2 * 1000; // 2 sec
|
||||
|
@ -73,8 +75,8 @@ namespace ARIASDK_NS_BEGIN {
|
|||
// Allow lower priority (normal) events to get thru in the next batch
|
||||
m_runningLatency = latency;
|
||||
}
|
||||
uint64_t now = PAL::getMonotonicTimeMs();
|
||||
uint64_t delta = (m_scheduledUploadTime >= now) ? m_scheduledUploadTime - now : 0;
|
||||
auto now = PAL::getMonotonicTimeMs();
|
||||
auto delta = ABS64(m_scheduledUploadTime, now);
|
||||
if (delta <= static_cast<uint64_t>(delayInMs))
|
||||
{
|
||||
// Don't need to cancel and reschedule if it's about to happen now anyways.
|
||||
|
|
Загрузка…
Ссылка в новой задаче