BUGFIX: Fix a possible deadlock if an error occurs
This commit is contained in:
parent
177e548efe
commit
c9323cd901
|
@ -47,12 +47,13 @@ int get_thread_number(void)
|
||||||
|
|
||||||
int init_producer_thread(void)
|
int init_producer_thread(void)
|
||||||
{
|
{
|
||||||
int i_local;
|
int thread_num;
|
||||||
|
|
||||||
i_local = get_thread_number();
|
thread_num = get_thread_number();
|
||||||
if (init_thread_comm(&tcomms[i_local]))
|
if (init_thread_comm(&tcomms[thread_num]))
|
||||||
{
|
{
|
||||||
error = 1;
|
error = 1;
|
||||||
|
pthread_cond_signal(&init_cond);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&init_lock);
|
pthread_mutex_lock(&init_lock);
|
||||||
|
|
|
@ -17,7 +17,11 @@ int init_thread_comm(struct thread_comm *comm)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
pipe(pipefd);
|
if (pipe(pipefd))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Unable to create a pipe for pipe communication\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
flags = fcntl(pipefd[READ_IDX], F_GETFL);
|
flags = fcntl(pipefd[READ_IDX], F_GETFL);
|
||||||
fcntl(pipefd[READ_IDX], F_SETFL, flags | O_NONBLOCK);
|
fcntl(pipefd[READ_IDX], F_SETFL, flags | O_NONBLOCK);
|
||||||
comm->pipefd = pipefd;
|
comm->pipefd = pipefd;
|
||||||
|
|
|
@ -16,6 +16,11 @@ __thread volatile int prod_idx = 0;
|
||||||
int init_thread_comm(struct thread_comm *comm)
|
int init_thread_comm(struct thread_comm *comm)
|
||||||
{
|
{
|
||||||
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
|
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
|
||||||
|
if (shared_space == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Unable to allocate space for shared mem communication\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
comm->shared_space = shared_space;
|
comm->shared_space = shared_space;
|
||||||
comm->cons_idx = &cons_idx;
|
comm->cons_idx = &cons_idx;
|
||||||
comm->prod_idx = &prod_idx;
|
comm->prod_idx = &prod_idx;
|
||||||
|
|
|
@ -16,6 +16,11 @@ __thread volatile int prod_idx = 0;
|
||||||
int init_thread_comm(struct thread_comm *comm)
|
int init_thread_comm(struct thread_comm *comm)
|
||||||
{
|
{
|
||||||
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
|
shared_space = (volatile void **) malloc(SHARED_SPACE_SIZE);
|
||||||
|
if (shared_space == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Unable to allocate space for shared mem communication\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
comm->shared_space = shared_space;
|
comm->shared_space = shared_space;
|
||||||
comm->cons_idx = &cons_idx;
|
comm->cons_idx = &cons_idx;
|
||||||
comm->prod_idx = &prod_idx;
|
comm->prod_idx = &prod_idx;
|
||||||
|
|
Loading…
Reference in New Issue