浏览代码

Minor code reorganization

Cédric Augonnet 15 年之前
父节点
当前提交
197d8bc68c
共有 1 个文件被更改,包括 43 次插入35 次删除
  1. 43 35
      src/datawizard/user_interactions.c

+ 43 - 35
src/datawizard/user_interactions.c

@@ -21,6 +21,8 @@
 #include <datawizard/write_back.h>
 #include <datawizard/write_back.h>
 #include <core/dependencies/data_concurrency.h>
 #include <core/dependencies/data_concurrency.h>
 
 
+/* Explicitly ask StarPU to allocate room for a piece of data on the specified
+ * memory node. */
 int starpu_data_request_allocation(starpu_data_handle handle, uint32_t node)
 int starpu_data_request_allocation(starpu_data_handle handle, uint32_t node)
 {
 {
 	starpu_data_request_t r;
 	starpu_data_request_t r;
@@ -49,6 +51,9 @@ struct state_and_node {
 	void *callback_arg;
 	void *callback_arg;
 };
 };
 
 
+/*
+ *	Non Blocking data request from application
+ */
 /* put the current value of the data into RAM */
 /* put the current value of the data into RAM */
 static inline void _starpu_sync_data_with_mem_continuation_non_blocking(void *arg)
 static inline void _starpu_sync_data_with_mem_continuation_non_blocking(void *arg)
 {
 {
@@ -74,44 +79,38 @@ static inline void _starpu_sync_data_with_mem_continuation_non_blocking(void *ar
 }
 }
 
 
 /* The data must be released by calling starpu_data_release_from_mem later on */
 /* The data must be released by calling starpu_data_release_from_mem later on */
-int starpu_data_sync_with_mem(starpu_data_handle handle, starpu_access_mode mode)
+int starpu_data_sync_with_mem_non_blocking(starpu_data_handle handle,
+		starpu_access_mode mode, void (*callback)(void *), void *arg)
 {
 {
 	STARPU_ASSERT(handle);
 	STARPU_ASSERT(handle);
 
 
-	/* it is forbidden to call this function from a callback or a codelet */
+	struct state_and_node *statenode = malloc(sizeof(struct state_and_node));
-	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
+	STARPU_ASSERT(statenode);
-		return -EDEADLK;
 
 
-	struct state_and_node statenode =
+	statenode->state = handle;
-	{
+	statenode->mode = mode;
-		.state = handle,
+	statenode->callback = callback;
-		.mode = mode,
+	statenode->callback_arg = arg;
-		.node = 0, // unused
+	PTHREAD_COND_INIT(&statenode->cond, NULL);
-		.cond = PTHREAD_COND_INITIALIZER,
+	PTHREAD_MUTEX_INIT(&statenode->lock, NULL);
-		.lock = PTHREAD_MUTEX_INITIALIZER,
+	statenode->finished = 0;
-		.finished = 0
-	};
 
 
 	/* we try to get the data, if we do not succeed immediately, we set a
 	/* we try to get the data, if we do not succeed immediately, we set a
  	* callback function that will be executed automatically when the data is
  	* callback function that will be executed automatically when the data is
  	* available again, otherwise we fetch the data directly */
  	* available again, otherwise we fetch the data directly */
 	if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode,
 	if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode,
-			_starpu_sync_data_with_mem_continuation, &statenode))
+			_starpu_sync_data_with_mem_continuation_non_blocking, statenode))
 	{
 	{
 		/* no one has locked this data yet, so we proceed immediately */
 		/* no one has locked this data yet, so we proceed immediately */
-		_starpu_sync_data_with_mem_continuation(&statenode);
+		_starpu_sync_data_with_mem_continuation_non_blocking(statenode);
-	}
-	else {
-		PTHREAD_MUTEX_LOCK(&statenode.lock);
-		while (!statenode.finished)
-			PTHREAD_COND_WAIT(&statenode.cond, &statenode.lock);
-		PTHREAD_MUTEX_UNLOCK(&statenode.lock);
 	}
 	}
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-
+/*
+ *	Block data request from application
+ */
 static inline void _starpu_sync_data_with_mem_continuation(void *arg)
 static inline void _starpu_sync_data_with_mem_continuation(void *arg)
 {
 {
 	int ret;
 	int ret;
@@ -134,31 +133,40 @@ static inline void _starpu_sync_data_with_mem_continuation(void *arg)
 	PTHREAD_MUTEX_UNLOCK(&statenode->lock);
 	PTHREAD_MUTEX_UNLOCK(&statenode->lock);
 }
 }
 
 
+
 /* The data must be released by calling starpu_data_release_from_mem later on */
 /* The data must be released by calling starpu_data_release_from_mem later on */
-int starpu_data_sync_with_mem_non_blocking(starpu_data_handle handle,
+int starpu_data_sync_with_mem(starpu_data_handle handle, starpu_access_mode mode)
-		starpu_access_mode mode, void (*callback)(void *), void *arg)
 {
 {
 	STARPU_ASSERT(handle);
 	STARPU_ASSERT(handle);
 
 
-	struct state_and_node *statenode = malloc(sizeof(struct state_and_node));
+	/* it is forbidden to call this function from a callback or a codelet */
-	STARPU_ASSERT(statenode);
+	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
+		return -EDEADLK;
 
 
-	statenode->state = handle;
+	struct state_and_node statenode =
-	statenode->mode = mode;
+	{
-	statenode->callback = callback;
+		.state = handle,
-	statenode->callback_arg = arg;
+		.mode = mode,
-	PTHREAD_COND_INIT(&statenode->cond, NULL);
+		.node = 0, // unused
-	PTHREAD_MUTEX_INIT(&statenode->lock, NULL);
+		.cond = PTHREAD_COND_INITIALIZER,
-	statenode->finished = 0;
+		.lock = PTHREAD_MUTEX_INITIALIZER,
+		.finished = 0
+	};
 
 
 	/* we try to get the data, if we do not succeed immediately, we set a
 	/* we try to get the data, if we do not succeed immediately, we set a
  	* callback function that will be executed automatically when the data is
  	* callback function that will be executed automatically when the data is
  	* available again, otherwise we fetch the data directly */
  	* available again, otherwise we fetch the data directly */
 	if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode,
 	if (!_starpu_attempt_to_submit_data_request_from_apps(handle, mode,
-			_starpu_sync_data_with_mem_continuation_non_blocking, statenode))
+			_starpu_sync_data_with_mem_continuation, &statenode))
 	{
 	{
 		/* no one has locked this data yet, so we proceed immediately */
 		/* no one has locked this data yet, so we proceed immediately */
-		_starpu_sync_data_with_mem_continuation_non_blocking(statenode);
+		_starpu_sync_data_with_mem_continuation(&statenode);
+	}
+	else {
+		PTHREAD_MUTEX_LOCK(&statenode.lock);
+		while (!statenode.finished)
+			PTHREAD_COND_WAIT(&statenode.cond, &statenode.lock);
+		PTHREAD_MUTEX_UNLOCK(&statenode.lock);
 	}
 	}
 
 
 	return 0;
 	return 0;