RAII holder of the process-wide single-instance lock.
Owns an OS handle whose lifetime is the lock: an flock'd file descriptor on Linux/macOS, a named mutex on Windows. The OS releases the lock automatically when the process exits for any reason — normal return, crash, or SIGKILL — so there is never a stale lock to clean up (unlike a PID file). Move-only; destroy it (or move-assign over it) to release the lock early.
Acquire the process-wide lock that permits only one running Motion Master.
Non-blocking. Returns the held lock when no other instance holds it; fails when one already does. The lock guards the whole process — acquired before the EtherCAT NIC is claimed and before the servers bind — so a second master can never drive the same bus alongside the first. The exclusive port bind is only a backstop: it fires too late (the NIC is already claimed by then) and misses instances configured on different ports, so the lock, not the port, is the real guard.
- Linux/macOS:
flock(LOCK_EX|LOCK_NB) on <temp_dir>/motion-master.lock (machine-wide).
- Windows: a named mutex in the session-local namespace (per interactive session — a standard user cannot create objects in the machine-global namespace).
- Returns
- The held lock on success; an error string describing the conflict on failure.