File: overflow-stream-slot-id.patch

package info (click to toggle)
actor-framework 0.17.6-3.2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 9,008 kB
  • sloc: cpp: 77,684; sh: 674; python: 309; makefile: 13
file content (25 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Upstream git commit 00acaaa007825bacf8cdb01a847f55bbbfc47fc2

Index: actor-framework/libcaf_core/src/scheduled_actor.cpp
===================================================================
--- actor-framework.orig/libcaf_core/src/scheduled_actor.cpp
+++ actor-framework/libcaf_core/src/scheduled_actor.cpp
@@ -1008,7 +1008,17 @@ uint64_t scheduled_actor::set_timeout(at
 stream_slot scheduled_actor::next_slot() {
   stream_slot result = 1;
   auto nslot = [](const stream_manager_map& x) -> stream_slot {
-    return x.rbegin()->first + 1;
+    auto highest = x.rbegin()->first;
+    if (highest < std::numeric_limits<decltype(highest)>::max())
+      return highest + 1;
+    // Back-up algorithm in the case of an overflow: Take the minimum
+    // id `1` if its still free, otherwise take an id from the first
+    // gap between two consecutive keys.
+    if (1 < x.begin()->first)
+      return 1;
+    auto has_gap = [](auto& a, auto& b) { return b.first - a.first > 1; };
+    auto i = std::adjacent_find(x.begin(), x.end(), has_gap);
+    return i != x.end() ? i->first + 1 : invalid_stream_slot;
   };
   if (!stream_managers_.empty())
     result = std::max(nslot(stream_managers_), result);