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 i_local;
|
||||
int thread_num;
|
||||
|
||||
i_local = get_thread_number();
|
||||
if (init_thread_comm(&tcomms[i_local]))
|
||||
thread_num = get_thread_number();
|
||||
if (init_thread_comm(&tcomms[thread_num]))
|
||||
{
|
||||
error = 1;
|
||||
pthread_cond_signal(&init_cond);
|
||||
return -1;
|
||||
}
|
||||
pthread_mutex_lock(&init_lock);
|
||||
|
|
|
@ -17,7 +17,11 @@ int init_thread_comm(struct thread_comm *comm)
|
|||
{
|
||||
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);
|
||||
fcntl(pipefd[READ_IDX], F_SETFL, flags | O_NONBLOCK);
|
||||
comm->pipefd = pipefd;
|
||||
|
|
|
@ -16,6 +16,11 @@ __thread volatile int prod_idx = 0;
|
|||
int init_thread_comm(struct thread_comm *comm)
|
||||
{
|
||||
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->cons_idx = &cons_idx;
|
||||
comm->prod_idx = &prod_idx;
|
||||
|
|
|
@ -16,6 +16,11 @@ __thread volatile int prod_idx = 0;
|
|||
int init_thread_comm(struct thread_comm *comm)
|
||||
{
|
||||
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->cons_idx = &cons_idx;
|
||||
comm->prod_idx = &prod_idx;
|
||||
|
|
Loading…
Reference in New Issue