Skip to content

rust: Port libobs/util/threading-windows.c to obs-util - #389

Merged
zackees merged 2 commits into
obs-rust:masterfrom
nathan-v:port/threading
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
nathan-v:port/threading

Conversation

@nathan-v

@nathan-v nathan-v commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Refs #356

What and why

threading-posix.c already builds as the Rust event and semaphore. This ports threading-windows.c: a Win32 event, a Win32 semaphore, and os_set_thread_name. On Windows the task queue uses that semaphore and event.

Both sides sit on the platform boundary. The POSIX condvar event is in platform/unix. The Win32 event and semaphore are in platform/windows. threading.rs re-exports Event, EventType, and Sem. Event::wait returns () on both platforms. The Windows shim reads the wait code from wait_code, which is 0 or EINVAL. Header-inline atomics stay C.

The oracle renames os_event_*, os_sem_*, and os_set_thread_name on Windows the same way it already does on Unix, and it does not compile the raw threading-windows.c. That keeps the public symbols out of the oracle archive. The ENABLE_RUST_LIBOBS generator expression is closed, same as the pipe-windows.c line.

A NULL out-pointer after a successful CreateEvent or CreateSemaphore returns EINVAL and the kernel object is closed. C writes through the pointer. SetEvent failure returns EINVAL, as threading-windows.c does. The boxed handle is not the raw HANDLE. Neither path uses bmalloc.

test/cmocka/test_threading.c was already the characterization test. It is unchanged, so the branch on master is RED then GREEN.

RED → GREEN

  • RED commit: 2c576d5d9. On Windows, sem_initial_value fails because Sem::try_new(2) returns None, and event_init_auto fails because os_event_init returns -1 and a null handle. Those tests are #![cfg(windows)].
  • GREEN: 4b9482eac, stamped. macOS Tier 2 on the POSIX tree: 77/77 with ENABLE_RUST_LIBOBS OFF and ON, then 100 repeats of test_threading|test_task in each build. Exported symbols identical, 1876. Linux Tier 2 was re-run for this tree in the local-gate tier2-linux lane (70s). Rust tests and lint passed in that stamp. thread_name_seh.c is clang-formatted; the lint lane does not scan .c files under rust/, and CI does. This machine has no Windows target, so Windows Tier 1, Tier 3, and Tier 2 are the Windows CI job.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • Local gate passed and the pushed head is stamped
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

test sem_initial_value fails because Sem::try_new(2) returns None.
test event_init_auto fails because os_event_init returns -1 and a null handle.

Refs obs-rust#356
Win32 CreateEvent and CreateSemaphore replace the condvar stand-in
the task queue was using. os_set_thread_name raises 0x406D1388 from
a small MSVC helper and then calls SetThreadDescription. Header-inline
atomics stay C. ENABLE_RUST_LIBOBS drops util/threading-windows.c.
The generator expression is closed, same as pipe-windows.c.

The Win32 event and semaphore live in platform/windows. The POSIX
condvar event lives in platform/unix. threading.rs re-exports both
and has no host cfg. Event::wait returns () on both platforms. The
Windows shim reads the wait code from wait_code, 0 or EINVAL.

The oracle renames os_event_*, os_sem_* and os_set_thread_name on
Windows the same way it already does on Unix, and does not compile
the raw threading-windows.c.

A NULL out-pointer after a successful create returns EINVAL and the
kernel object is closed. SetEvent failure returns EINVAL, matching
threading-windows.c. The boxed handle is not the raw HANDLE. Neither
path uses bmalloc.

Refs obs-rust#356

Local-Gate: v1 tree=d7477f2d6f1fc32b3ae219011b48efb2ad70cd5a secs=148 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791822753,"gate":"rust/all/fmt","host":"darwin-arm64","key":"5891f2a006c8903d78667a176430e1396d7296963a3d9f2abf48543131ec9d66","lane":"lint","parents":["2c576d5d9ae2fa88648bda9dbf43c5699b9d29b4"],"secs":39,"stamp":"e63960e291499e22c4b1180a9dc48dc8","tree":"d7477f2d6f1fc32b3ae219011b48efb2ad70cd5a","v":1,"via":"run"}
Ci-Attestation: {"at":1791822753,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"darwin-arm64","key":"5891f2a006c8903d78667a176430e1396d7296963a3d9f2abf48543131ec9d66","lane":"lint","parents":["2c576d5d9ae2fa88648bda9dbf43c5699b9d29b4"],"secs":39,"stamp":"90e39ce1d4eedf7c1f520b346be98fec","tree":"d7477f2d6f1fc32b3ae219011b48efb2ad70cd5a","v":1,"via":"run"}
Ci-Attestation: {"at":1791822753,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"darwin-arm64","key":"41dd345b754730afa358955fa9ca8a2b38b9143c5bbddbbd2028e10f25918621","lane":"rust-test","parents":["2c576d5d9ae2fa88648bda9dbf43c5699b9d29b4"],"secs":38,"stamp":"98ad9b6ea7dd31d80e4fdb346bc1e8d9","tree":"d7477f2d6f1fc32b3ae219011b48efb2ad70cd5a","v":1,"via":"run"}
Ci-Attestation: {"at":1791822753,"gate":"cpp/linux-x64/tier2","host":"darwin-arm64","key":"c7d57bcdaf77c1ff704af41f8107ddd36c4cd2b2f85ab02a3daea19c5d62b11a","lane":"tier2-linux","parents":["2c576d5d9ae2fa88648bda9dbf43c5699b9d29b4"],"secs":70,"stamp":"fc718e16b0b28b423901a9a9ca4d18b0","tree":"d7477f2d6f1fc32b3ae219011b48efb2ad70cd5a","v":1,"via":"run"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants