@@ -76,8 +76,8 @@ CompressedInputStream::CompressedInputStream(InputStream& is,
7676 _available = 0 ;
7777 _entropyType = EntropyDecoderFactory::getType (entropy.c_str ()); // throws on error
7878 _transformType = TransformFactory<byte>::getType (transform.c_str ()); // throws on error
79- _initialized = false ;
80- _closed = false ;
79+ _initialized = 0 ;
80+ _closed = 0 ;
8181 _gcount = 0 ;
8282 _ibs = new DefaultInputBitStream (is, DEFAULT_BUFFER_SIZE);
8383 _jobs = tasks;
@@ -152,8 +152,8 @@ CompressedInputStream::CompressedInputStream(InputStream& is, Context& ctx, bool
152152 _available = 0 ;
153153 _entropyType = EntropyDecoderFactory::NONE_TYPE;
154154 _transformType = TransformFactory<byte>::NONE_TYPE;
155- _initialized = false ;
156- _closed = false ;
155+ _initialized = 0 ;
156+ _closed = 0 ;
157157 _gcount = 0 ;
158158 _ibs = new DefaultInputBitStream (is, DEFAULT_BUFFER_SIZE);
159159 _jobs = tasks;
@@ -326,15 +326,15 @@ void CompressedInputStream::submitBlock(int bufferId)
326326int CompressedInputStream::_get (int inc)
327327{
328328 try {
329- if (_initialized. load (memory_order_acquire ) == false ) {
329+ if (LOAD_ATOMIC (_initialized ) == 0 ) {
330330 readHeader ();
331331
332332 for (int i = 0 ; i < _jobs; i++)
333333 submitBlock (i);
334334 }
335335
336336 if (_available == 0 ) {
337- if (_closed. load (memory_order_relaxed ) == true )
337+ if (LOAD_ATOMIC (_closed ) == 1 )
338338 throw ios_base::failure (" Stream closed" );
339339
340340 DecodingTaskResult res;
@@ -427,7 +427,7 @@ istream& CompressedInputStream::read(char* data, streamsize length)
427427
428428 while (remaining > 0 ) {
429429 // Reuse _get(0) logic logic implicitly
430- if (_initialized. load (memory_order_acquire ) == false ) {
430+ if (LOAD_ATOMIC (_initialized ) == 0 ) {
431431 readHeader ();
432432
433433 for (int i = 0 ; i < _jobs; i++)
@@ -507,7 +507,7 @@ istream& CompressedInputStream::read(char* data, streamsize length)
507507
508508void CompressedInputStream::readHeader ()
509509{
510- if (_initialized. exchange ( true , memory_order_acquire) )
510+ if (EXCHANGE_ATOMIC (_initialized, 1 ) == 1 )
511511 return ;
512512
513513 if (_headless == true )
@@ -695,11 +695,11 @@ bool CompressedInputStream::removeListener(Listener<Event>& bl)
695695
696696void CompressedInputStream::close ()
697697{
698- if (_closed. exchange ( true , memory_order_relaxed) )
698+ if (EXCHANGE_ATOMIC (_closed, 1 ) == 1 )
699699 return ;
700700
701701 // Signal to break the spin-loops in DecodingTask::run immediately.
702- _blockId. store (CANCEL_TASKS_ID, memory_order_release );
702+ STORE_ATOMIC (_blockId, CANCEL_TASKS_ID );
703703
704704#ifdef CONCURRENCY_ENABLED
705705 // We must ensure no thread is writing to _buffers before we delete them.
@@ -748,7 +748,7 @@ void CompressedInputStream::notifyListeners(vector<Listener<Event>*>& listeners,
748748template <class T >
749749DecodingTask<T>::DecodingTask(SliceArray<byte>* iBuffer, SliceArray<byte>* oBuffer,
750750 int blockSize, DefaultInputBitStream* ibs, XXHash32* hasher32, XXHash64* hasher64,
751- ATOMIC_INT * processedBlockId, vector<Listener<Event>*>& listeners,
751+ atomic_int_t * processedBlockId, vector<Listener<Event>*>& listeners,
752752 const Context& ctx)
753753 : _listeners(listeners)
754754 , _ctx(ctx)
@@ -779,7 +779,7 @@ T DecodingTask<T>::run()
779779
780780 // Lock free synchronization
781781 while (true ) {
782- const int taskId = _processedBlockId-> load (memory_order_acquire );
782+ const int taskId = LOAD_ATOMIC (*_processedBlockId );
783783
784784 if (taskId == CompressedInputStream::CANCEL_TASKS_ID) {
785785 // Skip, an error occurred
@@ -807,12 +807,12 @@ T DecodingTask<T>::run()
807807 uint64 read = _ibs->readBits (lr);
808808
809809 if (read == 0 ) {
810- _processedBlockId-> store ( CompressedInputStream::CANCEL_TASKS_ID, memory_order_release );
810+ STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID);
811811 return T (*_data, blockId, 0 , 0 , 0 , " Success" );
812812 }
813813
814814 if (read > (uint64 (1 ) << 34 )) {
815- _processedBlockId-> store ( CompressedInputStream::CANCEL_TASKS_ID, memory_order_release );
815+ STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID);
816816 return T (*_data, blockId, 0 , 0 , Error::ERR_BLOCK_SIZE, " Invalid block size" );
817817 }
818818
@@ -835,7 +835,7 @@ T DecodingTask<T>::run()
835835
836836 // After completion of the bitstream reading, increment the block id.
837837 // It unblocks the task processing the next block (if any)
838- _processedBlockId-> store (blockId, memory_order_release );
838+ STORE_ATOMIC (*_processedBlockId, blockId );
839839
840840 const int from = _ctx.getInt (" from" , 1 );
841841 const int to = _ctx.getInt (" to" , CompressedInputStream::MAX_BLOCK_ID);
@@ -876,7 +876,7 @@ T DecodingTask<T>::run()
876876
877877 if ((preTransformLength <= 0 ) || (preTransformLength > maxTransformSize)) {
878878 // Error => cancel concurrent decoding tasks
879- _processedBlockId-> store ( CompressedInputStream::CANCEL_TASKS_ID, memory_order_release );
879+ STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID);
880880 stringstream ss;
881881 ss << " Invalid compressed block length: " << preTransformLength;
882882
@@ -933,7 +933,7 @@ T DecodingTask<T>::run()
933933 if (ed->decode (_buffer->_array , 0 , preTransformLength) != preTransformLength) {
934934 // Error => cancel concurrent decoding tasks
935935 delete ed;
936- _processedBlockId-> store ( CompressedInputStream::CANCEL_TASKS_ID, memory_order_release );
936+ STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID);
937937 return T (*_data, blockId, 0 , checksum1, Error::ERR_PROCESS_BLOCK,
938938 " Entropy decoding failed" );
939939 }
@@ -998,8 +998,8 @@ T DecodingTask<T>::run()
998998 }
999999 catch (const exception& e) {
10001000 // Make sure to unfreeze next block
1001- if (_processedBlockId-> load (memory_order_acquire) == blockId - 1 )
1002- _processedBlockId-> store (blockId, memory_order_release );
1001+ int curBlockId = blockId - 1 ;
1002+ COMPARE_EXCHANGE_ATOMIC (*_processedBlockId, curBlockId, blockId );
10031003
10041004 if (transform != nullptr )
10051005 delete transform;
0 commit comments