[MIRROR] Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking (#430)

* Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking (#52761)

Adds SIGNAL_HANDLER, a macro that sets SHOULD_NOT_SLEEP(TRUE). This should ideally be required on all new signal callbacks.

Adds BLOCKING_SIGNAL_HANDLER, a macro that does nothing except symbolize "this is an older signal that didn't necessitate a code rewrite". It should not be allowed for new work.

This comes from discussion around #52735, which yields by calling input, and (though it sets the return type beforehand) will not properly return the flag to prevent attack from slapping.

To fix 60% of the yielding cases, WrapAdminProcCall no longer waits for another admin's proc call to finish. I'm not an admin, so I don't know how many behinds this has saved, but if this is problematic for admins I can just make it so that it lets you do it anyway. I'm not sure what the point of this babysitting was anyway.

Requested by @optimumtact.
Changelog

cl
admin: Calling a proc while another admin is calling one will no longer wait for the first to finish. You will simply just have to call it again.
/cl

* Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking

Co-authored-by: Jared-Fogle <35135081+Jared-Fogle@users.noreply.github.com>
This commit is contained in:
SkyratBot
2020-08-19 20:17:28 -04:00
committed by GitHub
co-authored by Jared-Fogle
parent d129e6973c
commit e65a48e91f
166 changed files with 906 additions and 20 deletions
+2
View File
@@ -23,5 +23,7 @@
return ..()
/obj/effect/blessing/proc/block_cult_teleport(datum/source, channel, turf/origin, turf/destination)
SIGNAL_HANDLER
if(channel == TELEPORT_CHANNEL_CULT)
return COMPONENT_BLOCK_TELEPORT
+2
View File
@@ -36,6 +36,8 @@
return ..()
/datum/proximity_monitor/proc/HandleMove()
SIGNAL_HANDLER_DOES_SLEEP
var/atom/_host = host
var/atom/new_host_loc = _host.loc
if(last_host_loc != new_host_loc)
+6
View File
@@ -35,10 +35,14 @@
/// triggered on wield of two handed item
/obj/item/rcl/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
active = TRUE
/// triggered on unwield of two handed item
/obj/item/rcl/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
active = FALSE
/obj/item/rcl/attackby(obj/item/W, mob/user)
@@ -170,6 +174,8 @@
listeningTo = to_hook
/obj/item/rcl/proc/trigger(mob/user)
SIGNAL_HANDLER
if(active)
layCable(user)
if(wiring_gui_menu) //update the wire options as you move
+8
View File
@@ -25,6 +25,8 @@
return ..()
/obj/item/binoculars/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
RegisterSignal(user, COMSIG_MOVABLE_MOVED, .proc/on_walk)
RegisterSignal(user, COMSIG_ATOM_DIR_CHANGE, .proc/rotate)
listeningTo = user
@@ -34,15 +36,21 @@
user.client.view_size.zoomOut(zoom_out_amt, zoom_amt, user.dir)
/obj/item/binoculars/proc/rotate(atom/thing, old_dir, new_dir)
SIGNAL_HANDLER
if(ismob(thing))
var/mob/lad = thing
lad.regenerate_icons()
lad.client.view_size.zoomOut(zoom_out_amt, zoom_amt, new_dir)
/obj/item/binoculars/proc/on_walk()
SIGNAL_HANDLER
attack_self(listeningTo) //Yes I have sinned, why do you ask?
/obj/item/binoculars/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
if(listeningTo)
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)
UnregisterSignal(user, COMSIG_ATOM_DIR_CHANGE)
+6
View File
@@ -37,6 +37,8 @@
* * user - The user which is wielding the broom
*/
/obj/item/pushbroom/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
to_chat(user, "<span class='notice'>You brace the [src] against the ground in a firm sweeping stance.</span>")
RegisterSignal(user, COMSIG_MOVABLE_MOVED, .proc/sweep)
@@ -48,6 +50,8 @@
* * user - The user which is unwielding the broom
*/
/obj/item/pushbroom/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)
/obj/item/pushbroom/afterattack(atom/A, mob/user, proximity)
@@ -65,6 +69,8 @@
* * moving - Boolean argument declaring if the sweep is from generated from movement or not
*/
/obj/item/pushbroom/proc/sweep(mob/user, atom/A, moving = TRUE)
SIGNAL_HANDLER
var/turf/target = moving ? user.loc : (isturf(A) ? A : A.loc)
if (!isturf(target))
return
+2
View File
@@ -298,6 +298,8 @@
. += mutable_appearance(icon, "id[job]")
/obj/item/card/id/proc/update_in_wallet()
SIGNAL_HANDLER
if(istype(loc, /obj/item/storage/wallet))
var/obj/item/storage/wallet/powergaming = loc
if(powergaming.front_id == src)
+4
View File
@@ -36,10 +36,14 @@
/// triggered on wield of two handed item
/obj/item/chainsaw/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
/// triggered on unwield of two handed item
/obj/item/chainsaw/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/chainsaw/suicide_act(mob/living/carbon/user)
+6
View File
@@ -314,10 +314,14 @@
/// triggered on wield of two handed item
/obj/item/shockpaddles/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
/// triggered on unwield of two handed item
/obj/item/shockpaddles/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/shockpaddles/Destroy()
@@ -340,6 +344,8 @@
defib.fire_act(exposed_temperature, exposed_volume)
/obj/item/shockpaddles/proc/check_range()
SIGNAL_HANDLER
if(!req_defib || !defib)
return
if(!in_range(src,defib))
+4
View File
@@ -40,6 +40,8 @@
/// Triggered on wield of two handed item
/// Specific hulk checks due to reflection chance for balance issues and switches hitsounds.
/obj/item/dualsaber/proc/on_wield(obj/item/source, mob/living/carbon/user)
SIGNAL_HANDLER
if(user && user.has_dna())
if(user.dna.check_mutation(HULK))
to_chat(user, "<span class='warning'>You lack the grace to wield this!</span>")
@@ -53,6 +55,8 @@
/// Triggered on unwield of two handed item
/// switch hitsounds
/obj/item/dualsaber/proc/on_unwield(obj/item/source, mob/living/carbon/user)
SIGNAL_HANDLER
wielded = FALSE
w_class = initial(w_class)
hitsound = "swing_hit"
+4
View File
@@ -34,10 +34,14 @@
/// triggered on wield of two handed item
/obj/item/fireaxe/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
/// triggered on unwield of two handed item
/obj/item/fireaxe/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/fireaxe/update_icon_state()
+2
View File
@@ -137,6 +137,8 @@
move_gracefully()
/obj/item/his_grace/proc/move_gracefully()
SIGNAL_HANDLER
if(!awakened)
return
var/static/list/transforms
+4
View File
@@ -27,10 +27,14 @@
/// triggered on wield of two handed item
/obj/item/pitchfork/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
/// triggered on unwield of two handed item
/obj/item/pitchfork/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/pitchfork/update_icon_state()
@@ -29,10 +29,14 @@
///triggered on wield of two handed item
/obj/item/singularityhammer/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
///triggered on unwield of two handed item
/obj/item/singularityhammer/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/singularityhammer/update_icon_state()
+4
View File
@@ -66,10 +66,14 @@
/// triggered on wield of two handed item
/obj/item/spear/explosive/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
/// triggered on unwield of two handed item
/obj/item/spear/explosive/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/spear/explosive/update_icon_state()
+2
View File
@@ -68,6 +68,8 @@
return ..()
/obj/item/melee/baton/proc/convert(datum/source, obj/item/I, mob/user)
SIGNAL_HANDLER
if(istype(I,/obj/item/conversion_kit) && convertible)
var/turf/T = get_turf(src)
var/obj/item/melee/classic_baton/B = new /obj/item/melee/classic_baton (T)
+2
View File
@@ -195,6 +195,8 @@
add_fingerprint(user)
/obj/item/hand_tele/proc/on_portal_destroy(obj/effect/portal/P)
SIGNAL_HANDLER
active_portal_pairs -= P //If this portal pair is made by us it'll be erased along with the other portal by the portal.
/obj/item/hand_tele/proc/is_parent_of_portal(obj/effect/portal/P)
+6
View File
@@ -740,6 +740,8 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301
/// Stage 1: The mistake is made
/obj/item/circlegame/proc/ownerExamined(mob/living/owner, mob/living/sucker)
SIGNAL_HANDLER
if(!istype(sucker) || !in_range(owner, sucker))
return
addtimer(CALLBACK(src, .proc/waitASecond, owner, sucker), 4)
@@ -908,10 +910,14 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301
/// triggered on wield of two handed item
/obj/item/vibro_weapon/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = TRUE
/// triggered on unwield of two handed item
/obj/item/vibro_weapon/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
wielded = FALSE
/obj/item/vibro_weapon/update_icon_state()
+2
View File
@@ -117,6 +117,8 @@
T.ChangeTurf(/turf/open/transparent/openspace, flags = CHANGETURF_INHERIT_AIR)
/obj/structure/stairs/proc/on_multiz_new(turf/source, dir)
SIGNAL_HANDLER
if(dir == UP)
var/turf/open/transparent/openspace/T = get_step_multiz(get_turf(src), UP)
if(T && !istype(T))
@@ -279,6 +279,8 @@
RegisterSignal(I, COMSIG_MOVABLE_MOVED, .proc/RemoveItemFromTable) //Listen for the pickup event, unregister on pick-up so we aren't moved
/obj/structure/table/rolling/proc/RemoveItemFromTable(datum/source, newloc, dir)
SIGNAL_HANDLER
if(newloc != loc) //Did we not move with the table? because that shit's ok
return FALSE
attached_items -= source