diff --git a/changelogs/unreleased/gh-7166-deprecate-fiber_set_cancellable.md b/changelogs/unreleased/gh-7166-deprecate-fiber_set_cancellable.md new file mode 100644 index 0000000000000000000000000000000000000000..640e842ea0b9b2fbee22fb05753f40ca31906226 --- /dev/null +++ b/changelogs/unreleased/gh-7166-deprecate-fiber_set_cancellable.md @@ -0,0 +1,4 @@ +## feature/core + +* **[Breaking change]** `fiber_set_cancellable()` is deprecated and + now does nothing (gh-7166). diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c index d7aa243e3574fada219c13ec01a61140c5799910..7471b5ffa2e92fbde1353a3e39df11afd4859037 100644 --- a/src/lib/core/fiber.c +++ b/src/lib/core/fiber.c @@ -509,20 +509,6 @@ fiber_wakeup(struct fiber *f) fiber_make_ready(f); } -/** Cancel the subject fiber. -* - * Note: cancelation is asynchronous. Use fiber_join() to wait for the - * cancelation to complete. - * - * A fiber may opt to set FIBER_IS_CANCELLABLE to false, and never test - * that it was cancelled. Such fiber can not ever be cancelled. - * However, as long as most of the cooperative code calls - * fiber_testcancel(), most of the fibers are cancellable. - * - * The fiber which is cancelled, has FiberIsCancelled raised - * in it. For cancellation to work, this exception type should be - * re-raised whenever (if) it is caught. - */ void fiber_cancel(struct fiber *f) { @@ -541,27 +527,13 @@ fiber_cancel(struct fiber *f) } f->flags |= FIBER_IS_CANCELLED; - - /** - * Don't wake self and zombies. - */ - if ((f->flags & FIBER_IS_CANCELLABLE) != 0) - fiber_wakeup(f); + fiber_wakeup(f); } -/** - * Change the current cancellation state of a fiber. This is not - * a cancellation point. - */ bool -fiber_set_cancellable(bool yesno) +fiber_set_cancellable(MAYBE_UNUSED bool yesno) { - bool prev = fiber()->flags & FIBER_IS_CANCELLABLE; - if (yesno == true) - fiber()->flags |= FIBER_IS_CANCELLABLE; - else - fiber()->flags &= ~FIBER_IS_CANCELLABLE; - return prev; + return true; } bool diff --git a/src/lib/core/fiber.h b/src/lib/core/fiber.h index fc1e39d9809cd64f8ed8f8b2eb8c66c993b5579d..97faaa523d1d96245213fd9be0fb0269c0e5563a 100644 --- a/src/lib/core/fiber.h +++ b/src/lib/core/fiber.h @@ -121,18 +121,11 @@ enum { }; enum { - /** - * It's safe to resume (wakeup) this fiber - * with a spurious wakeup if it is suspended, - * e.g. to force it to check that it's been - * cancelled. - */ - FIBER_IS_CANCELLABLE = 1 << 0, /** * Indicates that a fiber has been requested to end * prematurely. */ - FIBER_IS_CANCELLED = 1 << 1, + FIBER_IS_CANCELLED = 1 << 0, /** * The fiber will garbage collect automatically * when fiber function ends. The alternative @@ -140,41 +133,41 @@ enum { * the end of this fiber and garbage collect it * with fiber_join(). */ - FIBER_IS_JOINABLE = 1 << 2, + FIBER_IS_JOINABLE = 1 << 1, /** * The fiber is in cord->ready list or in * a call chain created by fiber_schedule_list(). * The flag is set to help fiber_wakeup() avoid * double wakeup of an already scheduled fiber. */ - FIBER_IS_READY = 1 << 3, + FIBER_IS_READY = 1 << 2, /** * This flag is set when fiber function ends and before * the fiber is recycled. */ - FIBER_IS_DEAD = 1 << 4, + FIBER_IS_DEAD = 1 << 3, /** * This flag is set when fiber uses custom stack size. */ - FIBER_CUSTOM_STACK = 1 << 5, + FIBER_CUSTOM_STACK = 1 << 4, /** * The flag is set for the fiber currently being executed by the cord. */ - FIBER_IS_RUNNING = 1 << 6, + FIBER_IS_RUNNING = 1 << 5, /** * This flag is set when fiber is in the idle list * of fiber_pool. */ - FIBER_IS_IDLE = 1 << 7, + FIBER_IS_IDLE = 1 << 6, /** * This flag is set when fiber has custom max slice. */ - FIBER_CUSTOM_SLICE = 1 << 8, + FIBER_CUSTOM_SLICE = 1 << 7, /** * This flag idicates, if the fiber can be killed from the Lua world. */ - FIBER_IS_SYSTEM = 1 << 9, - FIBER_DEFAULT_FLAGS = FIBER_IS_CANCELLABLE + FIBER_IS_SYSTEM = 1 << 8, + FIBER_DEFAULT_FLAGS = 0 }; /** \cond public */ @@ -299,12 +292,15 @@ API_EXPORT void fiber_wakeup(struct fiber *f); /** - * Cancel the subject fiber. (set FIBER_IS_CANCELLED flag) + * Cancel the subject fiber. + * + * Cancellation is asynchronous. Use fiber_join() to wait for the cancellation + * to complete. * - * If target fiber's flag FIBER_IS_CANCELLABLE set, then it would - * be woken up (maybe prematurely). Then current fiber yields - * until the target fiber is dead (or is woken up by - * \sa fiber_wakeup). + * After fiber_cancel() is called, the fiber may or may not check whether it + * was cancelled. If the fiber does not check it, it cannot ever be cancelled. + * However, as long as most of the cooperative code calls fiber_testcancel(), + * most of the fibers are cancellable. * * \param f fiber to be cancelled */ @@ -312,11 +308,9 @@ API_EXPORT void fiber_cancel(struct fiber *f); /** - * Make it possible or not possible to wakeup the current - * fiber immediately when it's cancelled. + * Deprecated. * - * @param yesno status to set - * @return previous state. + * @return true */ API_EXPORT bool fiber_set_cancellable(bool yesno); diff --git a/src/lua/fiber.c b/src/lua/fiber.c index 1831fe66dc39f5088ba1587653ba7bdb7548e420..9914681cbc3665e125f3f5736667a6cf480a7322 100644 --- a/src/lua/fiber.c +++ b/src/lua/fiber.c @@ -724,12 +724,7 @@ static int lbox_fiber_wakeup(struct lua_State *L) { struct fiber *f = lbox_checkfiber(L, 1); - /* - * It's unsafe to wakeup fibers which don't expect - * it. - */ - if (f->flags & FIBER_IS_CANCELLABLE) - fiber_wakeup(f); + fiber_wakeup(f); return 0; } diff --git a/test/unit/fiber.cc b/test/unit/fiber.cc index e65490d129ca0b17f9ef72be1047497eb2d34158..69399bf853442e8bbf9d7bc90d200775920638d2 100644 --- a/test/unit/fiber.cc +++ b/test/unit/fiber.cc @@ -29,7 +29,6 @@ noop_f(va_list ap) static int cancel_f(va_list ap) { - fiber_set_cancellable(true); while (true) { fiber_sleep(0.001); fiber_testcancel(); @@ -67,7 +66,6 @@ static int cancel_dead_f(va_list ap) { note("cancel dead has started"); - fiber_set_cancellable(true); tnt_raise(OutOfMemory, 42, "allocator", "exception"); return 0; } @@ -318,7 +316,7 @@ fiber_flags_respect_test(void) /* Fibers taken from the cache need to respect the passed flags. */ struct fiber_attr attr; fiber_attr_create(&attr); - uint32_t flags = FIBER_IS_JOINABLE | FIBER_IS_CANCELLABLE; + uint32_t flags = FIBER_IS_JOINABLE; attr.flags |= flags; f = fiber_new_ex("wait_cancel", &attr, wait_cancel_f); fail_unless((f->flags & flags) == flags); diff --git a/test/unit/latch.c b/test/unit/latch.c index 06d1ced2c803fcaef6c3017781b745abf07f544c..e08afbf030c943683d60b448f1882087e1d95836 100644 --- a/test/unit/latch.c +++ b/test/unit/latch.c @@ -25,7 +25,6 @@ sleep_f(va_list ap) { struct latch *latch = va_arg(ap, struct latch *); latch_lock(latch); - fiber_set_cancellable(true); while (!fiber_is_cancelled()) fiber_sleep(0.001);