Ticket #3381: fifowriter.patch

File fifowriter.patch, 1.9 KB (added by russell@…, 13 years ago)
  • fifowriter.cpp

     
    3737    full_cond = new pthread_cond_t[count];
    3838    for (int i = 0; i < count; i++)
    3939    {
    40       pthread_cond_init(&empty_cond[i], NULL);
    41       pthread_cond_init(&full_cond[i], NULL);
     40        pthread_cond_init(&empty_cond[i], NULL);
     41        pthread_cond_init(&full_cond[i], NULL);
     42        pthread_mutex_init(&fifo_lock[i], NULL);
    4243    }
    4344    filename = new QString [count];
    4445    fbdesc = new QString [count];
     
    4647
    4748FIFOWriter::~FIFOWriter()
    4849{
    49     for (int i = 0; i <num_fifos; i++)
     50    for (int i = 0; i < num_fifos; i++)
    5051    {
    5152        killwr[i] = 1;
     53
     54        pthread_mutex_lock(&fifo_lock[i]);
    5255        pthread_cond_signal(&empty_cond[i]);
     56        pthread_mutex_unlock(&fifo_lock[i]);
     57
    5358        pthread_join(fifothrds[i], NULL);
     59
     60        pthread_cond_destroy(&empty_cond[i]);
     61        pthread_cond_destroy(&full_cond[i]);
     62        pthread_mutex_destroy(&fifo_lock[i]);
    5463    }
    5564    delete [] maxblksize;
    5665    delete [] fifo_buf;
     
    5968    delete [] fifothrds;
    6069    delete [] full_cond;
    6170    delete [] empty_cond;
     71    delete [] fifo_lock;
    6272    delete [] filename;
    6373    delete [] fbdesc;
    6474    delete [] killwr;
     
    125135    while (1)
    126136    {
    127137        if (fb_inptr[id] == fb_outptr[id])
    128             pthread_cond_wait(&empty_cond[id],&fifo_lock[id]);
     138            pthread_cond_wait(&empty_cond[id], &fifo_lock[id]);
    129139        pthread_mutex_unlock(&fifo_lock[id]);
    130140        if (killwr[id])
    131141            break;
     
    214224            if (fb_inptr[i] == fb_outptr[i])
    215225            {
    216226                killwr[i] = 1;
     227                pthread_mutex_lock(&fifo_lock[i]);
    217228                pthread_cond_signal(&empty_cond[i]);
     229                pthread_mutex_unlock(&fifo_lock[i]);
    218230                count++;
    219231            }
    220232        }