Function: mutex-lock

mutex-lock is a function defined in thread.c.

Signature

(mutex-lock MUTEX)

Documentation

Acquire a mutex.

If the current thread already owns MUTEX, increment the count and return. Otherwise, if no thread owns MUTEX, make the current thread own it. Otherwise, block until MUTEX is available, or until the current thread is signaled using thread-signal. Note that calls to mutex-lock and mutex-unlock must be paired.

View in manual

Source Code

// Defined in /usr/src/emacs/src/thread.c
{
  struct Lisp_Mutex *lmutex;
  specpdl_ref count = SPECPDL_INDEX ();

  CHECK_MUTEX (mutex);
  lmutex = XMUTEX (mutex);

  current_thread->event_object = mutex;
  record_unwind_protect_void (do_unwind_mutex_lock);
  flush_stack_call_func (mutex_lock_callback, lmutex);
  return unbind_to (count, Qnil);
}