Commit 1a8195a2 authored by Huihuo Zheng's avatar Huihuo Zheng
Browse files

fixed mutex lock issue

parent 52135344
......@@ -110,8 +110,15 @@ void *H5Dwrite_pthread_func(void *arg) {
// this is to us the H5DWMM as an input
H5Dwrite_cache_metadata *wmm = (H5Dwrite_cache_metadata*) arg;
pthread_mutex_lock(&wmm->io.request_lock);
while (wmm->io.num_request>=0) {
if (wmm->io.num_request >0) {
bool loop= (wmm->io.num_request>=0);
bool working = (wmm->io.num_request>0);
bool done = (wmm->io.num_request==0);
pthread_mutex_unlock(&wmm->io.request_lock);
while (loop) {
pthread_mutex_lock(&wmm->io.request_lock);
pthread_mutex_unlock(&wmm->io.request_lock);
if (working) {
thread_data_t *data = wmm->io.current_request;
data->buf = mmap(NULL, data->size, PROT_READ, MAP_SHARED, wmm->mmap.fd, data->offset);
msync(data->buf, data->size, MS_SYNC);
......@@ -133,12 +140,20 @@ void *H5Dwrite_pthread_func(void *arg) {
munmap(data->buf, data->size);
wmm->io.current_request=wmm->io.current_request->next;
wmm->io.num_request--;
} if (wmm->io.num_request == 0) {
if (io_node()==wmm->mpi.rank) printf("wmm: %d\n", wmm->io.current_request->id);
}
pthread_mutex_lock(&wmm->io.request_lock);
loop= (wmm->io.num_request>=0);
working = (wmm->io.num_request>0);
done = (wmm->io.num_request==0);
pthread_mutex_unlock(&wmm->io.request_lock);
if (done) {
pthread_mutex_unlock(&wmm->io.request_lock);
pthread_cond_signal(&wmm->io.master_cond);
pthread_cond_wait(&wmm->io.io_cond, &wmm->io.request_lock);
pthread_mutex_unlock(&wmm->io.request_lock);
}
}
pthread_mutex_unlock(&wmm->io.request_lock);
return NULL;
}
......@@ -225,6 +240,7 @@ H5Dwrite_cache(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id,
H5DWMM.io.request_list->mem_space_id = H5Scopy(mem_space_id);
H5DWMM.io.request_list->file_space_id = H5Scopy(file_space_id);
H5DWMM.io.request_list->xfer_plist_id = H5Pcopy(dxpl_id);
if (io_node()==H5DWMM.mpi.rank) printf("building task list %d: \n", H5DWMM.io.request_list->id);
H5DWMM.io.request_list->size = size;
H5DWMM.io.request_list->next = (thread_data_t*) malloc(sizeof(thread_data_t));
H5DWMM.io.request_list->next->id = H5DWMM.io.request_list->id + 1;
......
......@@ -1227,8 +1227,12 @@ void *H5Dwrite_pthread_func_vol(void *arg) {
// this is to us the H5DWMM as an input
H5Dwrite_cache_metadata *wmm = (H5Dwrite_cache_metadata*) arg;
pthread_mutex_lock(&wmm->io.request_lock);
while (wmm->io.num_request>=0) {
if (wmm->io.num_request >0) {
bool loop = (wmm->io.num_request>=0);
bool working = (wmm->io.num_request>0);
bool done = (wmm->io.num_request==0);
pthread_mutex_unlock(&wmm->io.request_lock);
while (loop) {
if (working) {
thread_data_t *data = wmm->io.current_request;
data->buf = mmap(NULL, data->size, PROT_READ, MAP_SHARED, wmm->mmap.fd, data->offset);
msync(data->buf, data->size, MS_SYNC);
......@@ -1255,15 +1259,25 @@ void *H5Dwrite_pthread_func_vol(void *arg) {
H5Sclose(data->file_space_id);
H5Pclose(data->xfer_plist_id);
H5Tclose(data->mem_type_id);
pthread_mutex_lock(&wmm->io.request_lock);
wmm->io.current_request=wmm->io.current_request->next;
wmm->io.num_request--;
o->num_request_dataset--;
} if (wmm->io.num_request == 0) {
pthread_mutex_unlock(&wmm->io.request_lock);
}
pthread_mutex_lock(&wmm->io.request_lock);
loop = (wmm->io.num_request>=0);
working = (wmm->io.num_request>0);
done = (wmm->io.num_request==0);
pthread_mutex_unlock(&wmm->io.request_lock);
if (done) {
pthread_mutex_lock(&wmm->io.request_lock);
pthread_cond_signal(&wmm->io.master_cond);
pthread_cond_wait(&wmm->io.io_cond, &wmm->io.request_lock);
pthread_mutex_unlock(&wmm->io.request_lock);
}
}
pthread_mutex_unlock(&wmm->io.request_lock);
return NULL;
}
......
......@@ -7,7 +7,7 @@ LIBS=-L$(HDF5_DIR)/lib -lhdf5 -lz
#DEBUG=-DENABLE_EXT_PASSTHRU_LOGGING
CFLAGS=$(INCLUDES) $(LIBS)
TARGET=libh5passthrough_vol.so
TARGET=libh5passthrough_vol.dylib
CXX=mpicxx -DTHETA
all: makeso test_write_cache
......
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