+ while(n > 0) {
+ p = (n - 1) >> 1;
+ if(timeheap.b[p].to <= ent.to)
+ break;
+ timeheap.b[n] = timeheap.b[p];
+ timeheap.b[n].bl->thpos = n;
+ n = p;
+ }
+ timeheap.b[n] = ent;
+ ent.bl->thpos = n;
+}
+
+static void thlower(struct timeentry ent, int n)
+{
+ int c;
+
+ while(1) {
+ c = (n << 1) + 1;
+ if(c >= timeheap.d)
+ break;
+ if((c + 1 < timeheap.d) && (timeheap.b[c + 1].to < timeheap.b[c].to))
+ c = c + 1;
+ if(timeheap.b[c].to > ent.to)
+ break;
+ timeheap.b[n] = timeheap.b[c];
+ timeheap.b[n].bl->thpos = n;
+ n = c;
+ }
+ timeheap.b[n] = ent;
+ ent.bl->thpos = n;
+}
+
+static void addtimeout(struct blocker *bl, time_t to)
+{
+ sizebuf(timeheap, ++timeheap.d);
+ thraise((struct timeentry){.to = to, .bl = bl}, timeheap.d - 1);
+}
+
+static void deltimeout(struct blocker *bl)
+{
+ struct timeentry ent;
+ int n;
+
+ if(bl->thpos == timeheap.d - 1) {
+ timeheap.d--;
+ return;