void valvula_mutex_lock ( ValvulaMutex mutex_def)

Locks the given mutex.

If the mutex is currently unlocked, it becomes locked and owned by the calling thread, and valvula_mutex_lock returns immediately. If the mutex is already locked by another thread, valvula_mutex_lock suspends the calling thread until the mutex is unlocked.

Parameters
mutex_defThe reference to the mutex to be locked. If the mutex reference is NULL no lock operation is performed.

NOTE: It is important to use the pair of calls to valvula_mutex_lock and valvula_mutex_unlock from the same thread. This is because under windows, the couple of functions WaitForSingleObject and ReleaseMutex are used to implement lock and unlocking. Under this context, a thread not owning a mutex (acquired via WaitForSingleObject) can't release it with ReleaseMutex. This has the case consequence that a thread that has not called to valvula_mutex_lock cannot do a valvula_mutex_unlock until the owner thread do it.

Referenced by valvula_async_queue_foreach(), valvula_async_queue_items(), valvula_async_queue_length(), valvula_async_queue_lock(), valvula_async_queue_lookup(), valvula_async_queue_pop(), valvula_async_queue_priority_push(), valvula_async_queue_push(), valvula_async_queue_ref(), valvula_async_queue_ref_count(), valvula_async_queue_safe_unref(), valvula_async_queue_timedpop(), valvula_async_queue_unref(), valvula_async_queue_waiters(), valvula_connection_get_host_ip(), valvula_connection_is_ok(), valvula_connection_ref_internal(), valvula_ctx_free2(), valvula_ctx_ref2(), valvula_ctx_ref_count(), valvula_ctx_register_request_handler(), valvula_ctx_unref2(), valvula_exit_ctx(), valvula_hash_clear(), valvula_hash_delete(), valvula_hash_destroy(), valvula_hash_exists(), valvula_hash_foreach(), valvula_hash_foreach2(), valvula_hash_foreach3(), valvula_hash_insert(), valvula_hash_lock_until_changed(), valvula_hash_lookup(), valvula_hash_lookup_and_clear(), valvula_hash_ref(), valvula_hash_remove(), valvula_hash_replace(), valvula_hash_replace_full(), valvula_hash_size(), valvula_is_exiting(), valvula_support_inet_ntoa(), valvula_thread_pool_add(), valvula_thread_pool_event_stats(), valvula_thread_pool_new_event(), valvula_thread_pool_remove(), valvula_thread_pool_remove_event(), valvula_thread_pool_stats(), valvulad_run_add_object_resolver(), and valvulad_run_remove_object_resolver().