Bläddra i källkod

Fix write-through in case the target already has updated data: the callback is still called in that case, so we need to take the read lock in all cases

Samuel Thibault 13 år sedan
förälder
incheckning
6d7163a74e
1 ändrade filer med 6 tillägg och 7 borttagningar
  1. 6 7
      src/datawizard/write_back.c

+ 6 - 7
src/datawizard/write_back.c

@@ -46,6 +46,12 @@ void _starpu_write_through_data(starpu_data_handle handle, uint32_t requesting_n
 				while (_starpu_spin_trylock(&handle->header_lock))
 					_starpu_datawizard_progress(requesting_node, 1);
 
+				/* We need to keep a Read lock to avoid letting writers corrupt our copy.  */
+				STARPU_ASSERT(handle->current_mode != STARPU_REDUX);
+				STARPU_ASSERT(handle->current_mode != STARPU_SCRATCH);
+				handle->refcnt++;
+				handle->current_mode = STARPU_R;
+
 				starpu_data_request_t r;
 				r = create_request_to_fetch_data(handle, &handle->per_node[node],
 						STARPU_R, 1, wt_callback, handle);
@@ -53,14 +59,7 @@ void _starpu_write_through_data(starpu_data_handle handle, uint32_t requesting_n
 			        /* If no request was created, the handle was already up-to-date on the
 			         * node */
 			        if (r)
-				{
-					/* Pending request, keep a Read lock */
-					STARPU_ASSERT(handle->current_mode != STARPU_REDUX);
-					STARPU_ASSERT(handle->current_mode != STARPU_SCRATCH);
-					handle->refcnt++;
-					handle->current_mode = STARPU_R;
 				        _starpu_spin_unlock(&handle->header_lock);
-				}
 			}
 		}
 	}