Changeset 94


Ignore:
Timestamp:
05/29/10 04:17:41 (4 years ago)
Author:
faltet
Message:

Removed the necessity of the additional barrier.

A smart combination of a flag and a lock is more than enough. This allows better speed, specially for decompression.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/blosc.c

    r92 r94  
    5555int32_t init_threads_done = 0;   /* pool of threads initialized? */ 
    5656int32_t end_threads = 0;         /* should exisiting threads end? */ 
     57int32_t init_sentinels_done = 0; /* sentinels initialized? */ 
    5758int32_t giveup_code;             /* error code when give up */ 
    5859int32_t nblock;                  /* block counter */ 
     
    691692 
    692693  while (1) { 
     694 
     695    init_sentinels_done = 0;     /* sentinels have to be initialised yet */ 
     696     
    693697    /* Meeting point for all threads (wait for initialization) */ 
    694698#ifdef _POSIX_BARRIERS_MINE 
     
    715719    } 
    716720 
    717     /* Set sentinels and other global variables */ 
    718     giveup_code = 1;            /* no error code initially */ 
    719     nblock = -1;                /* block counter */ 
    720  
    721     /* Get parameters for this thread before entering the second barrier */ 
     721    pthread_mutex_lock(&count_mutex); 
     722    if (!init_sentinels_done) { 
     723      /* Set sentinels and other global variables */ 
     724      giveup_code = 1;            /* no error code initially */ 
     725      nblock = -1;                /* block counter */ 
     726      init_sentinels_done = 1;    /* sentinels have been initialised */ 
     727    } 
     728    pthread_mutex_unlock(&count_mutex); 
     729 
     730    /* Get parameters for this thread before entering the main loop */ 
    722731    blocksize = params.blocksize; 
    723732    ebsize = blocksize + params.typesize*sizeof(int32_t); 
    724733    compress = params.compress; 
    725734    nbytes = params.nbytes; 
    726     ntbytes = params.ntbytes; 
    727735    nblocks = params.nblocks; 
    728736    leftover = params.leftover; 
     
    733741    tmp2 = params.tmp2[tid]; 
    734742 
    735  
    736     /* Ensure that all threads arrive here before to continue.  This 
    737        avoids sentinels and others globals above to be overwritten. */ 
    738 #ifdef _POSIX_BARRIERS_MINE 
    739     rc = pthread_barrier_wait(&barr2_init); 
    740     if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { 
    741       printf("Could not wait on barrier (init)\n"); 
    742       exit(-1); 
    743     } 
    744 #else 
    745     pthread_mutex_lock(&count2_threads_mutex); 
    746     if (count2_threads < nthreads-1) { 
    747       count2_threads++; 
    748       pthread_cond_wait(&count2_threads_cv, &count2_threads_mutex); 
    749     } 
    750     else { 
    751       pthread_cond_broadcast(&count2_threads_cv); 
    752       count2_threads = 0;       /* Reset counter */ 
    753     } 
    754     pthread_mutex_unlock(&count2_threads_mutex); 
    755 #endif 
     743    ntbytes = 0;                /* only useful for decompression */ 
    756744 
    757745    if (compress) { 
     
    832820      else { 
    833821        nblock_++; 
    834       } 
    835       /* Update counter for this thread */ 
    836       ntbytes += cbytes; 
     822        /* Update counter for this thread */ 
     823        ntbytes += cbytes; 
     824      } 
    837825 
    838826    } /* closes while (nblock_) */ 
    839827 
     828    /* Sum up all the bytes decompressed */ 
    840829    if (!compress && giveup_code > 0) { 
    841830      /* Update global counter for all threads (decompression only) */ 
Note: See TracChangeset for help on using the changeset viewer.