Ejemplo n.º 1
0
acpi_status
acpi_ex_acquire_mutex (
	acpi_operand_object     *time_desc,
	acpi_operand_object     *obj_desc,
	acpi_walk_state         *walk_state)
{
	acpi_status             status;


	FUNCTION_TRACE_PTR ("Ex_acquire_mutex", obj_desc);

	if (!obj_desc) {
		return_ACPI_STATUS (AE_BAD_PARAMETER);
	}

	/*
	 * Current Sync must be less than or equal to the sync level of the
	 * mutex.  This mechanism provides some deadlock prevention
	 */
	if (walk_state->current_sync_level > obj_desc->mutex.sync_level) {
		return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
	}

	/*
	 * If the mutex is already owned by this thread,
	 * just increment the acquisition depth
	 */
	if (obj_desc->mutex.owner == walk_state) {
		obj_desc->mutex.acquisition_depth++;
		return_ACPI_STATUS (AE_OK);
	}

	/* Acquire the mutex, wait if necessary */

	status = acpi_ex_system_acquire_mutex (time_desc, obj_desc);
	if (ACPI_FAILURE (status)) {
		/* Includes failure from a timeout on Time_desc */

		return_ACPI_STATUS (status);
	}

	/* Have the mutex, update mutex and walk info */

	obj_desc->mutex.owner = walk_state;
	obj_desc->mutex.acquisition_depth = 1;
	walk_state->current_sync_level = obj_desc->mutex.sync_level;

	/* Link the mutex to the walk state for force-unlock at method exit */

	acpi_ex_link_mutex (obj_desc, (acpi_operand_object *)
			 &(walk_state->walk_list->acquired_mutex_list));

	return_ACPI_STATUS (AE_OK);
}
Ejemplo n.º 2
0
acpi_status
acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
		      union acpi_operand_object *obj_desc,
		      struct acpi_walk_state *walk_state)
{
	acpi_status status;

	ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex, obj_desc);

	if (!obj_desc) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
	}

	/* Sanity check -- we must have a valid thread ID */

	if (!walk_state->thread) {
		ACPI_ERROR((AE_INFO,
			    "Cannot acquire Mutex [%4.4s], null thread info",
			    acpi_ut_get_node_name(obj_desc->mutex.node)));
		return_ACPI_STATUS(AE_AML_INTERNAL);
	}

	/*
	 * Current Sync must be less than or equal to the sync level of the
	 * mutex. This mechanism provides some deadlock prevention
	 */
	if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
		ACPI_ERROR((AE_INFO,
			    "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)",
			    acpi_ut_get_node_name(obj_desc->mutex.node),
			    walk_state->thread->current_sync_level));
		return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
	}

	/* Support for multiple acquires by the owning thread */

	if (obj_desc->mutex.owner_thread) {

		/* Special case for Global Lock, allow all threads */

		if ((obj_desc->mutex.owner_thread->thread_id ==
		     walk_state->thread->thread_id) ||
		    (obj_desc->mutex.os_mutex == ACPI_GLOBAL_LOCK)) {
			/*
			 * The mutex is already owned by this thread,
			 * just increment the acquisition depth
			 */
			obj_desc->mutex.acquisition_depth++;
			return_ACPI_STATUS(AE_OK);
		}
	}

	/* Acquire the mutex, wait if necessary */

	status = acpi_ex_system_acquire_mutex(time_desc, obj_desc);
	if (ACPI_FAILURE(status)) {

		/* Includes failure from a timeout on time_desc */

		return_ACPI_STATUS(status);
	}

	/* Have the mutex: update mutex and walk info and save the sync_level */

	obj_desc->mutex.owner_thread = walk_state->thread;
	obj_desc->mutex.acquisition_depth = 1;
	obj_desc->mutex.original_sync_level =
	    walk_state->thread->current_sync_level;

	walk_state->thread->current_sync_level = obj_desc->mutex.sync_level;

	/* Link the mutex to the current thread for force-unlock at method exit */

	acpi_ex_link_mutex(obj_desc, walk_state->thread);

	return_ACPI_STATUS(AE_OK);
}