Commit 7a69c840 authored by Swann Perarnau's avatar Swann Perarnau

[feature] make dma_linux_par thread-safe

Add mutex to make request creation and destruction thread-safe. Same as
dma_linux_seq, the changes are quite simple, as we only need to protect
modifications to the requests array.
parent 9f2b685d
......@@ -635,6 +635,7 @@ struct aml_dma_request_linux_par {
struct aml_dma_linux_par_data {
size_t nbthreads;
struct aml_vector requests;
pthread_mutex_t lock;
};
struct aml_dma_linux_par_ops {
......
......@@ -149,7 +149,9 @@ int aml_dma_linux_par_create_request(struct aml_dma_data *d,
struct aml_dma_request_linux_par *req;
pthread_mutex_lock(&dma->data.lock);
req = aml_vector_add(&dma->data.requests);
pthread_mutex_unlock(&dma->data.lock);
/* init the request */
if(type == AML_DMA_REQUEST_TYPE_COPY)
......@@ -211,7 +213,9 @@ int aml_dma_linux_par_destroy_request(struct aml_dma_data *d,
else if(req->type == AML_DMA_REQUEST_TYPE_MOVE)
aml_dma_request_linux_par_move_destroy(req);
pthread_mutex_lock(&dma->data.lock);
aml_vector_remove(&dma->data.requests, req);
pthread_mutex_unlock(&dma->data.lock);
return 0;
}
......@@ -233,7 +237,9 @@ int aml_dma_linux_par_wait_request(struct aml_dma_data *d,
else if(req->type == AML_DMA_REQUEST_TYPE_MOVE)
aml_dma_request_linux_par_move_destroy(req);
pthread_mutex_lock(&dma->data.lock);
aml_vector_remove(&dma->data.requests, req);
pthread_mutex_unlock(&dma->data.lock);
return 0;
}
......@@ -288,6 +294,7 @@ int aml_dma_linux_par_vinit(struct aml_dma *d, va_list ap)
req->thread_data = calloc(dma->data.nbthreads,
sizeof(struct aml_dma_linux_par_thread_data));
}
pthread_mutex_init(&dma->data.lock, NULL);
return 0;
}
int aml_dma_linux_par_init(struct aml_dma *d, ...)
......@@ -310,5 +317,6 @@ int aml_dma_linux_par_destroy(struct aml_dma *d)
free(req->thread_data);
}
aml_vector_destroy(&dma->data.requests);
pthread_mutex_destroy(&dma->data.lock);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment