Skip to content

Commit 43a6d6f

Browse files
committed
timers: Use signed for id, add UNUSED_ID
1 parent 46bfb03 commit 43a6d6f

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

api/kernel/timers.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
99
// You may obtain a copy of the License at
10-
//
10+
//
1111
// http://www.apache.org/licenses/LICENSE-2.0
12-
//
12+
//
1313
// Unless required by applicable law or agreed to in writing, software
1414
// distributed under the License is distributed on an "AS IS" BASIS,
1515
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,28 +28,30 @@
2828
class Timers
2929
{
3030
public:
31-
using id_t = uint32_t;
31+
using id_t = int32_t;
3232
using duration_t = std::chrono::microseconds;
3333
using handler_t = delegate<void(id_t)>;
34-
34+
35+
static constexpr id_t UNUSED_ID = -1;
36+
3537
/// create a one-shot timer that triggers @when from now
3638
/// returns a timer id
3739
static id_t oneshot(duration_t when, const handler_t&);
3840
/// create a periodic timer that begins @when and repeats every @period
3941
static id_t periodic(duration_t when, duration_t period, const handler_t&);
4042
// un-schedule timer, and free it
4143
static void stop(id_t);
42-
44+
4345
/// returns the number of current, active timers
4446
static size_t active();
45-
47+
4648
/// initialization
4749
typedef delegate<void(duration_t)> start_func_t;
4850
typedef delegate<void()> stop_func_t;
4951
static void init(const start_func_t&, const stop_func_t&);
5052
/// signal from the underlying hardware that it is calibrated and ready to go
5153
static void ready();
52-
54+
5355
/// handler that processes timer interrupts
5456
static void timers_handler();
5557
};

api/net/tcp/connection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
887887
/*
888888
When retransmission times out.
889889
*/
890-
void rtx_timeout(uint32_t);
890+
void rtx_timeout(int);
891891

892892

893893
/** Start the timewait timeout for 2*MSL */
@@ -900,7 +900,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
900900
void timewait_restart();
901901

902902
/** When timewait timer times out */
903-
void timewait_timeout(uint32_t);
903+
void timewait_timeout(int);
904904

905905
/*
906906
Tell the host (TCP) to delete this connection.

src/net/tcp/connection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ void Connection::rtx_clear() {
737737
MUST be re-initialized to 3 seconds when data transmission
738738
begins (i.e., after the three-way handshake completes).
739739
*/
740-
void Connection::rtx_timeout(uint32_t) {
740+
void Connection::rtx_timeout(Timers::id_t) {
741741
rtx_timer.active = false;
742742
debug("<TCP::Connection::RTX@timeout> %s Timed out (%f). FS: %u\n",
743743
to_string().c_str(), flight_size());
@@ -833,7 +833,7 @@ void Connection::timewait_restart() {
833833
timewait_start();
834834
}
835835

836-
void Connection::timewait_timeout(uint32_t) {
836+
void Connection::timewait_timeout(Timers::id_t) {
837837
debug("<Connection> TimeWait timed out, closing.\n");
838838
timewait_timer.active = false;
839839

0 commit comments

Comments
 (0)