Motion Master 6.0.0-alpha.50
Next-generation motion control software
Loading...
Searching...
No Matches
mm::core::SingleInstanceLock Class Reference

RAII holder of the process-wide single-instance lock. More...

#include <platform.h>

Public Member Functions

 SingleInstanceLock ()=default
 
 SingleInstanceLock (SingleInstanceLock &&other) noexcept
 
SingleInstanceLockoperator= (SingleInstanceLock &&other) noexcept
 
 SingleInstanceLock (const SingleInstanceLock &)=delete
 
SingleInstanceLockoperator= (const SingleInstanceLock &)=delete
 
 ~SingleInstanceLock ()
 

Friends

std::expected< SingleInstanceLock, std::string > acquireSingleInstanceLock ()
 Acquire the process-wide lock that permits only one running Motion Master.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SingleInstanceLock() [1/3]

mm::core::SingleInstanceLock::SingleInstanceLock ( )
default

◆ SingleInstanceLock() [2/3]

mm::core::SingleInstanceLock::SingleInstanceLock ( SingleInstanceLock &&  other)
noexcept

◆ SingleInstanceLock() [3/3]

mm::core::SingleInstanceLock::SingleInstanceLock ( const SingleInstanceLock )
delete

◆ ~SingleInstanceLock()

mm::core::SingleInstanceLock::~SingleInstanceLock ( )

Member Function Documentation

◆ operator=() [1/2]

SingleInstanceLock & mm::core::SingleInstanceLock::operator= ( const SingleInstanceLock )
delete

◆ operator=() [2/2]

SingleInstanceLock & mm::core::SingleInstanceLock::operator= ( SingleInstanceLock &&  other)
noexcept

Friends And Related Symbol Documentation

◆ acquireSingleInstanceLock

std::expected< SingleInstanceLock, std::string > acquireSingleInstanceLock ( )
friend

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.

The documentation for this class was generated from the following files: