zeroc-ice / vscode-slice

Slice syntax highlighter for Visual Studio Code
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

Centralize Mutex Locking #51

Closed InsertCreativityHere closed 8 months ago

InsertCreativityHere commented 8 months ago

This PR centralizes all our locking to a single file: main.rs. Every other file operates without concern or knowledge of mutexes and locks. This makes it easier to see where and reason about how we lock things.

It also simplifies the lockes themselves. Currently, Session looks like:

pub struct Session {
    pub configuration_sets: Mutex<Vec<ConfigurationSet>>,
    pub server_config: RwLock<ServerConfig>,
}

Instead of having separate locks on each field, this PR moves the lock up a level to Session itself. In practice, this makes no difference. Everywhere where we locked server_config, we locked configuration_sets on the line above it. So, no difference to flow or performance.

And theoritically, it would be strange for 1 thread to be mutating server_config, while another mutates configuration_sets. The configuration sets depend on the server's configuration after all. So I think requiring a thread to lock both is saner too.

ReeceHumphreys commented 8 months ago

I could have been sure that I initially used a mutex on the session but was getting a weird deadlock, so I switched to using a RwLock for server_config and splitting them apart. Have you tested this PR yet?