Class ErrorModeLock

Class Documentation

class ErrorModeLock

A recursive lock on the current global navtk::ErrorMode (as reported by navtk::get_global_error_mode) that makes sure the value can only be changed by the current thread.

The lock is honored both by other navtk::ErrorModeLock instances and navtk::set_global_error_mode.

When an instance of ErrorModeLock is created, the current global ErrorMode is stored. If the enable_restore parameter is true (the default), this saved state will be restored (regardless of any same-thread calls to navtk::set_global_error_mode that may have run during its lifetime).

ErrorModeLock instances are backed by std::unique_lock, and as such can be moved but not copied.

Python users should use this object as a context manager (using the with statement) to ensure the lock is correctly released at the appropriate time.

with navtk.ErrorModeLock(navtk.ErrorMode.OFF):
    # your code here

The ErrorModeLock python bindings are not threadsafe themselves. The __enter__ and __exit__ methods (used by the with statement) should only be called by the thread that created the ErrorModeLock.

Public Functions

ErrorModeLock(ErrorMode target_mode, bool enable_restore = true)

Sets the value of the global ErrorMode (see navtk::get_global_error_mode) for the lifetime of this object.

Parameters
  • target_mode – Mode to set.

  • enable_restore – Whether to restore the previous global error mode when this object goes out of scope.

ErrorModeLock(ErrorModeLock &&src)

Moves ownership of the lock to a new instance, preventing the original instance from changing the global state when it is destroyed.

Parameters

src – Source object being moved-from

ErrorModeLock(const ErrorModeLock&) = delete

Deleted; use std::move instead.

ErrorModeLock &operator=(ErrorModeLock&&) = delete

Deleted; causes nonsense behavior.

ErrorModeLock &operator=(const ErrorModeLock&) = delete

Deleted; causes nonsense behavior.

virtual ~ErrorModeLock()

Protected Functions

void unlock()

Release the underlying lock and restore the previous navtk::ErrorMode.

C++ users should allow the destructor to be called instead; this function exists to allow Python users to use ErrorModeLock as a context manager.

void relock()

Re-acquire the underlying lock and set the global error mode to the target_mode passed into the constructor.

C++ users should avoid this function; it exists to allow Python users to use ErrorModeLock as a context manager.