|
@@ -103,6 +103,8 @@ static void _starpu_register_new_data(starpu_data_handle handle,
|
|
/* initialize the new lock */
|
|
/* initialize the new lock */
|
|
handle->req_list = starpu_data_requester_list_new();
|
|
handle->req_list = starpu_data_requester_list_new();
|
|
handle->refcnt = 0;
|
|
handle->refcnt = 0;
|
|
|
|
+ PTHREAD_MUTEX_INIT(&handle->refcnt_mutex, NULL);
|
|
|
|
+ PTHREAD_COND_INIT(&handle->refcnt_cond, NULL);
|
|
_starpu_spin_init(&handle->header_lock);
|
|
_starpu_spin_init(&handle->header_lock);
|
|
|
|
|
|
/* first take care to properly lock the data */
|
|
/* first take care to properly lock the data */
|
|
@@ -423,6 +425,11 @@ static void _starpu_data_unregister(starpu_data_handle handle, unsigned coherent
|
|
PTHREAD_COND_WAIT(&arg.cond, &arg.mutex);
|
|
PTHREAD_COND_WAIT(&arg.cond, &arg.mutex);
|
|
PTHREAD_MUTEX_UNLOCK(&arg.mutex);
|
|
PTHREAD_MUTEX_UNLOCK(&arg.mutex);
|
|
}
|
|
}
|
|
|
|
+ _starpu_spin_lock(&handle->header_lock);
|
|
|
|
+ STARPU_ASSERT(handle->refcnt > 0);
|
|
|
|
+ /* Drop the reference count we've acquired by submitting an R data request */
|
|
|
|
+ handle->refcnt--;
|
|
|
|
+ _starpu_spin_unlock(&handle->header_lock);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -431,6 +438,11 @@ static void _starpu_data_unregister(starpu_data_handle handle, unsigned coherent
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* Wait for all requests to finish (notably WT requests) */
|
|
|
|
+ PTHREAD_MUTEX_LOCK(&handle->refcnt_mutex);
|
|
|
|
+ while (handle->refcnt)
|
|
|
|
+ PTHREAD_COND_WAIT(&handle->refcnt_cond, &handle->refcnt_mutex);
|
|
|
|
+
|
|
_starpu_data_free_interfaces(handle);
|
|
_starpu_data_free_interfaces(handle);
|
|
|
|
|
|
/* Destroy the data now */
|
|
/* Destroy the data now */
|