Jacek Caban (@jacek) commented about dlls/win32u/winstation.c:
+ + data->shared_session = find_shared_session_object( locator ); + if (!(object = data->shared_session)) return STATUS_INVALID_HANDLE; + memset( lock, 0, sizeof(*lock) ); + } + + if (!lock->id || !shared_object_release_seqlock( object, lock->seq )) + { + shared_object_acquire_seqlock( object, &lock->seq ); + *session_shm = &object->shm.session; + lock->id = object->id; + return STATUS_PENDING; + } + + return STATUS_SUCCESS; +} IMHO, this is an unnecessary complication. The session pointer is shared across the entire process and remains at a fixed location for its lifetime, so we can simply store a global pointer during initialization.
Using this function for locking is both more complex than necessary and suboptimal, as it busy-loops when the server modifies an unrelated handle. Since handle entries are immutable for their lifetime, synchronization only requires validating the handle before and after reading the entry. See [this commit](https://gitlab.winehq.org/jacek/wine/-/commit/d532493c3dbcdebe937f38ab45f819...) for an example. To make this work on the server side, we just need to ensure that generation is the last field modified when allocating a handle and the first field changed when freeing it, there is no need for `SHARED_WRITE_*`. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/7610#note_98600