Browse Source

Avoid recursing when unlocking data requests, otherwise we can end up stacking calls

Samuel Thibault 9 years ago
parent
commit
d650d6dcd1

+ 12 - 0
src/core/dependencies/data_concurrency.c

@@ -391,6 +391,17 @@ int _starpu_notify_data_dependencies(starpu_data_handle_t handle)
 			_starpu_data_end_reduction_mode_terminate(handle);
 	}
 
+	if (handle->unlocking_reqs)
+		/*
+		 * Our caller is already running the unlock loop below (we were
+		 * most probably called from the ready_data_callback call
+		 * below). Avoid looping again (which would potentially mean
+		 * unbounded recursion), our caller will continue doing the
+		 * unlock work for us.
+		 */
+		return 0;
+
+	handle->unlocking_reqs = 1;
 	struct _starpu_data_requester *r;
 	while ((r = may_unlock_data_req_list_head(handle)))
 	{
@@ -460,6 +471,7 @@ int _starpu_notify_data_dependencies(starpu_data_handle_t handle)
 				return 1;
 		}
 	}
+	handle->unlocking_reqs = 0;
 
 	return 0;
 }

+ 2 - 0
src/datawizard/coherency.h

@@ -120,6 +120,8 @@ struct _starpu_data_state
 	 * the req_list anymore), i.e. the number of holders of the
 	 * current_mode rwlock */
 	unsigned refcnt;
+	/* whether we are already unlocking data requests */
+	unsigned unlocking_reqs;
 	/* Current access mode. Is always either STARPU_R, STARPU_W,
 	 * STARPU_SCRATCH or STARPU_REDUX, but never a combination such as
 	 * STARPU_RW. */

+ 1 - 0
src/datawizard/filters.c

@@ -206,6 +206,7 @@ static void _starpu_data_partition(starpu_data_handle_t initial_handle, starpu_d
 		child->reduction_tmp_handles = NULL;
 		child->write_invalidation_req = NULL;
 		child->refcnt = 0;
+		child->unlocking_reqs = 0;
 		child->busy_count = 0;
 		child->busy_waiting = 0;
 		STARPU_PTHREAD_MUTEX_INIT(&child->busy_mutex, NULL);

+ 1 - 0
src/datawizard/interfaces/data_interface.c

@@ -241,6 +241,7 @@ static void _starpu_register_new_data(starpu_data_handle_t handle,
 	/* initialize the new lock */
 	_starpu_data_requester_list_init(&handle->req_list);
 	handle->refcnt = 0;
+	handle->unlocking_reqs = 0;
 	handle->busy_count = 0;
 	handle->busy_waiting = 0;
 	STARPU_PTHREAD_MUTEX_INIT(&handle->busy_mutex, NULL);