FACT++  1.0
void * CompressedFitsWriter::threadFunction ( void *  context)
staticprivate

the main function compressing the data

Definition at line 1406 of file fitsCompressor.cc.

References _mutex, CompressedFitsFile::_numThreads, CompressedFitsFile::_THREAD_COMPRESS_, CompressedFitsFile::_THREAD_EXIT_, CompressedFitsFile::_THREAD_WAIT_, CompressedFitsFile::_THREAD_WRITE_, CompressedFitsFile::_threadIndex, CompressedFitsFile::_threadStatus, compressBuffer(), and writeCompressedDataToDisk().

Referenced by open().

1407 {
1408  CompressedFitsWriter* myself =static_cast<CompressedFitsWriter*>(context);
1409 
1410  uint32_t myID = 0;
1411  pthread_mutex_lock(&(myself->_mutex));
1412  myID = myself->_threadIndex++;
1413  pthread_mutex_unlock(&(myself->_mutex));
1414  uint32_t threadToWaitForBeforeWriting = (myID == 0) ? myself->_numThreads-1 : myID-1;
1415 
1416  while (myself->_threadStatus[myID] != _THREAD_EXIT_)
1417  {
1418  while (myself->_threadStatus[myID] == _THREAD_WAIT_)
1419  usleep(100000);
1420  if (myself->_threadStatus[myID] != _THREAD_COMPRESS_)
1421  continue;
1422  uint32_t numBytes = myself->compressBuffer(myID);
1423  myself->_threadStatus[myID] = _THREAD_WRITE_;
1424 
1425  //wait for the previous data to be written
1426  while (myself->_threadIndex != threadToWaitForBeforeWriting)
1427  usleep(1000);
1428  //do the actual writing to disk
1429  pthread_mutex_lock(&(myself->_mutex));
1430  myself->writeCompressedDataToDisk(myID, numBytes);
1431  myself->_threadIndex = myID;
1432  pthread_mutex_unlock(&(myself->_mutex));
1433  myself->_threadStatus[myID] = _THREAD_WAIT_;
1434  }
1435  return NULL;
1436 }
uint32_t _numThreads
The number of threads that will be used to compress.
static const uint32_t _THREAD_WRITE_
Thread writing data to disk.
vector< uint32_t > _threadStatus
Flag telling whether the buffer to be transposed (and compressed) is full or empty.
static const uint32_t _THREAD_WAIT_
Thread doing nothing.
uint64_t compressBuffer(uint32_t threadIndex)
compresses one buffer of data, the one given by threadIndex
static const uint32_t _THREAD_EXIT_
Thread exiting.
pthread_mutex_t _mutex
mutex for compressing threads
bool writeCompressedDataToDisk(uint32_t threadID, uint32_t sizeToWrite)
writes an already compressed buffer to disk
uint32_t _threadIndex
A variable to assign threads indices.
static const uint32_t _THREAD_COMPRESS_
Thread working, compressing.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: