MXS-1754 Use signed types for expressing milliseconds

This commit is contained in:
Johan Wikman 2018-04-20 10:07:15 +03:00
parent be9504ac94
commit a84e369a97
2 changed files with 28 additions and 23 deletions

View File

@ -447,7 +447,7 @@ public:
* *
* @attention A value of 0 means that the timer is cancelled. * @attention A value of 0 means that the timer is cancelled.
*/ */
void start(uint64_t interval); void start(int32_t interval);
/** /**
* @brief Cancel the timer. * @brief Cancel the timer.
@ -922,14 +922,14 @@ public:
* case the return value is ignored and the function will not * case the return value is ignored and the function will not
* be called again. * be called again.
*/ */
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
intptr_t tag, intptr_t tag,
bool (*pFunction)(Worker::Call::action_t action)) bool (*pFunction)(Worker::Call::action_t action))
{ {
add_delayed_call(new DelayedCallFunctionVoid(delay, tag, pFunction)); add_delayed_call(new DelayedCallFunctionVoid(delay, tag, pFunction));
} }
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
void* tag, void* tag,
bool (*pFunction)(Worker::Call::action_t action)) bool (*pFunction)(Worker::Call::action_t action))
{ {
@ -955,7 +955,7 @@ public:
* be called again. * be called again.
*/ */
template<class D> template<class D>
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
intptr_t tag, intptr_t tag,
bool (*pFunction)(Worker::Call::action_t action, D data), D data) bool (*pFunction)(Worker::Call::action_t action, D data), D data)
{ {
@ -963,7 +963,7 @@ public:
} }
template<class D> template<class D>
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
void* pTag, void* pTag,
bool (*pFunction)(Worker::Call::action_t action, D data), D data) bool (*pFunction)(Worker::Call::action_t action, D data), D data)
{ {
@ -988,7 +988,7 @@ public:
* be called again. * be called again.
*/ */
template<class T> template<class T>
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
intptr_t tag, intptr_t tag,
T* pT, T* pT,
bool (T::*pMethod)(Worker::Call::action_t action)) bool (T::*pMethod)(Worker::Call::action_t action))
@ -997,7 +997,7 @@ public:
} }
template<class T> template<class T>
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
void* pTag, void* pTag,
T* pT, T* pT,
bool (T::*pMethod)(Worker::Call::action_t action)) bool (T::*pMethod)(Worker::Call::action_t action))
@ -1024,7 +1024,7 @@ public:
* be called again. * be called again.
*/ */
template<class T, class D> template<class T, class D>
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
intptr_t tag, intptr_t tag,
T* pT, T* pT,
bool (T::*pMethod)(Worker::Call::action_t action, D data), D data) bool (T::*pMethod)(Worker::Call::action_t action, D data), D data)
@ -1033,7 +1033,7 @@ public:
} }
template<class T, class D> template<class T, class D>
void delayed_call(uint32_t delay, void delayed_call(int32_t delay,
void* pTag, void* pTag,
T* pT, T* pT,
bool (T::*pMethod)(Worker::Call::action_t action, D data), D data) bool (T::*pMethod)(Worker::Call::action_t action, D data), D data)
@ -1109,7 +1109,7 @@ private:
{ {
} }
uint32_t delay() const int32_t delay() const
{ {
return m_delay; return m_delay;
} }
@ -1119,7 +1119,7 @@ private:
return m_tag; return m_tag;
} }
uint64_t at() const int64_t at() const
{ {
return m_at; return m_at;
} }
@ -1136,18 +1136,21 @@ private:
} }
protected: protected:
DelayedCall(uint32_t delay, intptr_t tag) DelayedCall(int32_t delay, intptr_t tag)
: m_delay(delay) : m_delay(delay)
, m_tag(tag) , m_tag(tag)
, m_at(get_at(delay)) , m_at(get_at(delay))
{ {
ss_dassert(delay > 0);
} }
virtual bool do_call(Worker::Call::action_t action) = 0; virtual bool do_call(Worker::Call::action_t action) = 0;
private: private:
static uint64_t get_at(uint32_t delay) static int64_t get_at(int32_t delay)
{ {
ss_dassert(delay > 0);
struct timespec ts; struct timespec ts;
ss_debug(int rv =) clock_gettime(CLOCK_MONOTONIC, &ts); ss_debug(int rv =) clock_gettime(CLOCK_MONOTONIC, &ts);
ss_dassert(rv == 0); ss_dassert(rv == 0);
@ -1156,9 +1159,9 @@ private:
} }
private: private:
uint32_t m_delay; // The delay in milliseconds. int32_t m_delay; // The delay in milliseconds.
intptr_t m_tag; // Tag identifying the delayed call. intptr_t m_tag; // Tag identifying the delayed call.
uint64_t m_at; // The next time the function should be invoked. int64_t m_at; // The next time the function should be invoked.
}; };
template<class D> template<class D>
@ -1168,7 +1171,7 @@ private:
DelayedCallFunction& operator = (const DelayedCallFunction&) = delete; DelayedCallFunction& operator = (const DelayedCallFunction&) = delete;
public: public:
DelayedCallFunction(uint32_t delay, DelayedCallFunction(int32_t delay,
void* pTag, void* pTag,
bool (*pFunction)(Worker::Call::action_t action, D data), D data) bool (*pFunction)(Worker::Call::action_t action, D data), D data)
: DelayedCall(delay, pTag) : DelayedCall(delay, pTag)
@ -1195,7 +1198,7 @@ private:
DelayedCallFunctionVoid& operator = (const DelayedCallFunctionVoid&) = delete; DelayedCallFunctionVoid& operator = (const DelayedCallFunctionVoid&) = delete;
public: public:
DelayedCallFunctionVoid(uint32_t delay, DelayedCallFunctionVoid(int32_t delay,
intptr_t tag, intptr_t tag,
bool (*pFunction)(Worker::Call::action_t action)) bool (*pFunction)(Worker::Call::action_t action))
: DelayedCall(delay, tag) : DelayedCall(delay, tag)
@ -1220,7 +1223,7 @@ private:
DelayedCallMethod& operator = (const DelayedCallMethod&) = delete; DelayedCallMethod& operator = (const DelayedCallMethod&) = delete;
public: public:
DelayedCallMethod(uint32_t delay, DelayedCallMethod(int32_t delay,
intptr_t tag, intptr_t tag,
T* pT, T* pT,
bool (T::*pMethod)(Worker::Call::action_t action, D data), D data) bool (T::*pMethod)(Worker::Call::action_t action, D data), D data)
@ -1250,7 +1253,7 @@ private:
DelayedCallMethodVoid& operator = (const DelayedCallMethodVoid&) = delete; DelayedCallMethodVoid& operator = (const DelayedCallMethodVoid&) = delete;
public: public:
DelayedCallMethodVoid(uint32_t delay, DelayedCallMethodVoid(int32_t delay,
intptr_t tag, intptr_t tag,
T* pT, T* pT,
bool (T::*pMethod)(Worker::Call::action_t)) bool (T::*pMethod)(Worker::Call::action_t))

View File

@ -232,8 +232,10 @@ WorkerTimer::~WorkerTimer()
} }
} }
void WorkerTimer::start(uint64_t interval) void WorkerTimer::start(int32_t interval)
{ {
ss_dassert(interval > 0);
// TODO: Add possibility to set initial delay and interval. // TODO: Add possibility to set initial delay and interval.
time_t initial_sec = interval / 1000; time_t initial_sec = interval / 1000;
long initial_nsec = (interval - initial_sec * 1000) * 1000000; long initial_nsec = (interval - initial_sec * 1000) * 1000000;
@ -1112,7 +1114,7 @@ void Worker::poll_waitevents()
namespace namespace
{ {
uint64_t get_current_time_ms() int64_t get_current_time_ms()
{ {
struct timespec ts; struct timespec ts;
ss_debug(int rv =) clock_gettime(CLOCK_MONOTONIC, &ts); ss_debug(int rv =) clock_gettime(CLOCK_MONOTONIC, &ts);
@ -1125,7 +1127,7 @@ uint64_t get_current_time_ms()
void Worker::tick() void Worker::tick()
{ {
uint64_t now = get_current_time_ms(); int64_t now = get_current_time_ms();
ss_dassert(!m_delayed_calls.empty()); ss_dassert(!m_delayed_calls.empty());