Adding the ability to post an error on any object - #4843
Conversation
RAOF
left a comment
There was a problem hiding this comment.
Wheeee! What a mess. I've suggested what I think is an improvement; please check if that works!
| thread_local! { | ||
| static OBJECT_REGISTRY: RefCell<HashMap<u32, ObjectId>> = RefCell::new(HashMap::new()); | ||
| } | ||
|
|
There was a problem hiding this comment.
I'm not wild about making this a thread-local; this makes our C++ side no longer threadsafe.
A grungy, but possible, alternative would be to use handle.object_for_protocol_id()? This would require stashing the &'static protocol::Interface in addition to the object id in the C++ side, but because it's 'static that would be safe (although it's marshalling pointer -> string -> pointer, so looks groody)
There was a problem hiding this comment.
My push back is that:
- It adds a lot of complication from what I've seen so far
- When else would you be throwing a protocol error outside of the Wayland thread? Errors are thrown in response to some request typically, not out of the blue AFAIK
There was a problem hiding this comment.
What if we went the easy route and put the map behind a lock. That way we can avoid unnecessary thread safe code, and the lookup table will always be thread safe. And therefore we can post errors from any thread ð This seems like the best route in my opinion as it avoid a lot of unsafety and complication (e.g. serializing pointers)
RAOF
left a comment
There was a problem hiding this comment.
Yeah, that works, but...
One of the things that passing the &'static Interface would have handled (that I didn't explicitly mention) is removing things from the map; as it is now, IDs are never removed for dead objects.
Can we also remove from the map when the object dies? Otherwise clients will be able to cause us to consume unbounded memory ðŪâðĻ
Oof of course! Luckily, our |
RAOF
left a comment
There was a problem hiding this comment.
Sorry to make one last request; feel free to ignore it or to apply that set of changes and merge.
|
|
||
| fn register_resource(resource: &impl Resource) { | ||
| let id = resource.id(); | ||
| OBJECT_REGISTRY.write().unwrap_or_else(|e| e.into_inner()).insert(id.protocol_id(), id); |
There was a problem hiding this comment.
| OBJECT_REGISTRY.write().unwrap_or_else(|e| e.into_inner()).insert(id.protocol_id(), id); | |
| OBJECT_REGISTRY.write().expect("lock poisoned").insert(id.protocol_id(), id); |
I don't know if we can witness it, but if the Mutex is poisoned then we probably want to bail rather than continue with weirdness.
What's new?
associatestepProtocolErrornow includes this protocol ID when it sends exceptionsChecklist