Commit 7334317c authored by Arnaud Blanchard's avatar Arnaud Blanchard

m

parent 8e0bb2ad
......@@ -207,7 +207,7 @@ void blc_channel::create(char const *new_name, int access_mode){
SYSTEM_ERROR_CHECK(file=fopen(BLC_CHANNELS_LIST_PATH, "a+"), NULL, "Openning the file '" BLC_CHANNELS_LIST_PATH"' in order to reference the channel '%s'.", name);
fd = shm_open(name, O_CREAT | O_EXCL | access_mode, S_IRWXU); // (O_EXCL first) is important in order to avoid a race condition. We create it at the same time we check it does not exist. Otherwise someone else could create it in between.
fd = shm_open(name, O_CREAT | O_EXCL | O_RDWR, S_IRWXU); // (O_EXCL first) is important in order to avoid a race condition. We create it at the same time we check it does not exist. Otherwise someone else could create it in between.
if (fd==-1){//Creation impossible
fclose(file);
......@@ -246,7 +246,11 @@ void blc_channel::create(char const *new_name, int access_mode){
sem_ack_data=NULL;
}
SYSTEM_ERROR_CHECK(ftruncate(fd, size), -1, "fd:%d, size '%ld'.", fd, size);
SYSTEM_ERROR_CHECK(ftruncate(fd, size), -1, "fd:%d, size '%ld' for channel '%s'.", fd, size, name);
if (access_mode==BLC_CHANNEL_READ){
close(fd);
fd = shm_open(name, O_RDONLY, S_IRWXU);
}
map_memory(access_mode);
}
}
......@@ -330,13 +334,13 @@ void blc_channel::open(const char *name, int access_mode){
if (sync_new_data) {
sprintf(name_tmp, "blc_channel%d_sem_new_data0", id);
SYSTEM_ERROR_CHECK(sem_new_data = sem_open(name_tmp, NO_FLAG), SEM_FAILED, "Opening named semaphore '%s' for blc_channel '%s'", name_tmp, name);
/* if (access_mode==BLC_CHANNEL_READ){ //As we have just started. Any data is new
while (sem_trywait(sem_new_data)==-1){ //If the semaphore is busy we post it until it is unlocked
if (errno==EAGAIN) SYSTEM_ERROR_CHECK(sem_post(sem_new_data), -1, "blc_channel '%s'", this->name);
else EXIT_ON_SYSTEM_ERROR("blc_channel '%s'", this->name);
}
SYSTEM_ERROR_CHECK(sem_post(sem_new_data), -1, "blc_channel '%s'", this->name);
}*/
/* if (access_mode==BLC_CHANNEL_READ){ //As we have just started. Any data is new
while (sem_trywait(sem_new_data)==-1){ //If the semaphore is busy we post it until it is unlocked
if (errno==EAGAIN) SYSTEM_ERROR_CHECK(sem_post(sem_new_data), -1, "blc_channel '%s'", this->name);
else EXIT_ON_SYSTEM_ERROR("blc_channel '%s'", this->name);
}
SYSTEM_ERROR_CHECK(sem_post(sem_new_data), -1, "blc_channel '%s'", this->name);
}*/
}
if (sync_ack_data){
......@@ -447,15 +451,15 @@ blc_channel::~blc_channel(){
void blc_channel::remove(){
blc_remove_channel_with_name(name);
if (dims) FREE(dims);
if (data){
SYSTEM_SUCCESS_CHECK(munmap(data, size), 0, "Closing blc_channel '%s'", name);
data=NULL;
}
close(fd);
blc_channel_post_event();
if (dims) FREE(dims);
if (data){
SYSTEM_SUCCESS_CHECK(munmap(data, size), 0, "Closing blc_channel '%s'", name);
data=NULL;
}
close(fd);
blc_channel_post_event();
}
void blc_channel::publish(){
......@@ -482,7 +486,6 @@ void blc_channel::fprint_debug(FILE *file){
}
int blc_channel::post_new_data(){
int listenner = -1;
......@@ -510,3 +513,4 @@ int blc_channel::post_ack_data(){
return listenner;
}
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