]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - linux/timer.c
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / linux / timer.c
index 11a2fd8d2e5489874314a052830ce7fab9d2a3b4..7d519a4d85830108b8b0166ada31222d5fe6e59a 100644 (file)
@@ -93,9 +93,11 @@ do {                                                                 \
                                                                        \
        BUG_ON(_i >= (h)->used);                                        \
        (h)->used--;                                                    \
-       heap_swap(h, _i, (h)->used);                                    \
-       heap_sift_down(h, _i, cmp);                                     \
-       heap_sift(h, _i, cmp);                                          \
+       if ((_i) < (h)->used) {                                         \
+               heap_swap(h, _i, (h)->used);                            \
+               heap_sift_down(h, _i, cmp);                             \
+               heap_sift(h, _i, cmp);                                  \
+       }                                                               \
 } while (0)
 
 #define heap_pop(h, d, cmp)                                            \
@@ -312,6 +314,8 @@ static void timers_init(void)
 __attribute__((destructor(103)))
 static void timers_cleanup(void)
 {
+       get_task_struct(timer_task);
+
        pthread_mutex_lock(&timer_lock);
        timer_thread_stop = true;
        pthread_cond_signal(&timer_cond);
@@ -320,5 +324,6 @@ static void timers_cleanup(void)
        int ret = kthread_stop(timer_task);
        BUG_ON(ret);
 
+       put_task_struct(timer_task);
        timer_task = NULL;
 }