@@ -779,16 +779,18 @@ T DecodingTask<T>::run()
779779 bool streamPerTask = _ctx.getInt (" tasks" ) > 1 ;
780780 uint64 tType = _ctx.getLong (" tType" );
781781 short eType = short (_ctx.getInt (" eType" ));
782- #ifdef CONCURRENCY_ENABLED
783782 auto storeProcessedBlockId = [this ](int value) {
783+ #ifdef CONCURRENCY_ENABLED
784784 {
785785 std::lock_guard<std::mutex> lock (*_blockMutex);
786786 STORE_ATOMIC (*_processedBlockId, value);
787787 }
788788
789789 _blockCondition->notify_all ();
790- };
790+ #else
791+ STORE_ATOMIC (*_processedBlockId, value);
791792#endif
793+ };
792794
793795#ifdef CONCURRENCY_ENABLED
794796 {
@@ -803,22 +805,6 @@ T DecodingTask<T>::run()
803805 // Skip, an error occurred
804806 return T (*_data, blockId, 0 , 0 , 0 , " Canceled" );
805807 }
806- #else
807- // Lock free synchronization
808- while (true ) {
809- const int taskId = LOAD_ATOMIC (*_processedBlockId);
810-
811- if (taskId == CompressedInputStream::CANCEL_TASKS_ID ) {
812- // Skip, an error occurred
813- return T (*_data, blockId, 0 , 0 , 0 , " Canceled" );
814- }
815-
816- if (taskId == blockId - 1 )
817- break ;
818-
819- // Back-off improves performance
820- CPU_PAUSE ();
821- }
822808#endif
823809
824810 uint64 checksum1 = 0 ;
@@ -835,20 +821,12 @@ T DecodingTask<T>::run()
835821 uint64 read = _ibs->readBits (lr);
836822
837823 if (read == 0 ) {
838- #ifdef CONCURRENCY_ENABLED
839824 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
840- #else
841- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
842- #endif
843825 return T (*_data, blockId, 0 , 0 , 0 , " Success" );
844826 }
845827
846828 if (read > (uint64 (1 ) << 34 )) {
847- #ifdef CONCURRENCY_ENABLED
848829 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
849- #else
850- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
851- #endif
852830 return T (*_data, blockId, 0 , 0 , Error::ERR_BLOCK_SIZE , " Invalid block size" );
853831 }
854832
@@ -876,11 +854,7 @@ T DecodingTask<T>::run()
876854
877855 // After completion of the bitstream reading, increment the block id.
878856 // It unblocks the task processing the next block (if any)
879- #ifdef CONCURRENCY_ENABLED
880857 storeProcessedBlockId (blockId);
881- #else
882- STORE_ATOMIC (*_processedBlockId, blockId);
883- #endif
884858
885859 // Check if the block must be skipped
886860 if (blockId < from) {
@@ -918,11 +892,7 @@ T DecodingTask<T>::run()
918892
919893 if ((preTransformLength <= 0 ) || (preTransformLength > maxTransformSize)) {
920894 // Error => cancel concurrent decoding tasks
921- #ifdef CONCURRENCY_ENABLED
922895 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
923- #else
924- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
925- #endif
926896 stringstream ss;
927897 ss << " Invalid compressed block length: " << preTransformLength;
928898
@@ -979,11 +949,7 @@ T DecodingTask<T>::run()
979949 // Block entropy decode
980950 if (ed->decode (_buffer->_array , 0 , preTransformLength) != preTransformLength) {
981951 // Error => cancel concurrent decoding tasks
982- #ifdef CONCURRENCY_ENABLED
983952 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
984- #else
985- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
986- #endif
987953 delete ed;
988954
989955 if (streamPerTask == true )
@@ -1023,11 +989,7 @@ T DecodingTask<T>::run()
1023989 transform = nullptr ;
1024990
1025991 if (res == false ) {
1026- #ifdef CONCURRENCY_ENABLED
1027992 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
1028- #else
1029- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
1030- #endif
1031993 return T (*_data, blockId, 0 , checksum1, Error::ERR_PROCESS_BLOCK ,
1032994 " Transform inverse failed" );
1033995 }
@@ -1039,11 +1001,7 @@ T DecodingTask<T>::run()
10391001 const uint32 checksum2 = _hasher32->hash (&_data->_array [savedIdx], decoded);
10401002
10411003 if (checksum2 != uint32 (checksum1)) {
1042- #ifdef CONCURRENCY_ENABLED
10431004 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
1044- #else
1045- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
1046- #endif
10471005 stringstream ss;
10481006 ss << " Corrupted bitstream: expected checksum " << std::hex << checksum1 << " , found " << std::hex << checksum2;
10491007 return T (*_data, blockId, decoded, checksum1, Error::ERR_CRC_CHECK , ss.str ());
@@ -1053,11 +1011,7 @@ T DecodingTask<T>::run()
10531011 const uint64 checksum2 = _hasher64->hash (&_data->_array [savedIdx], decoded);
10541012
10551013 if (checksum2 != checksum1) {
1056- #ifdef CONCURRENCY_ENABLED
10571014 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
1058- #else
1059- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
1060- #endif
10611015 stringstream ss;
10621016 ss << " Corrupted bitstream: expected checksum " << std::hex << checksum1 << " , found " << std::hex << checksum2;
10631017 return T (*_data, blockId, decoded, checksum1, Error::ERR_CRC_CHECK , ss.str ());
@@ -1068,11 +1022,7 @@ T DecodingTask<T>::run()
10681022 }
10691023 catch (const exception& e) {
10701024 // Cancel any in-flight task waiting on this block.
1071- #ifdef CONCURRENCY_ENABLED
10721025 storeProcessedBlockId (CompressedInputStream::CANCEL_TASKS_ID );
1073- #else
1074- STORE_ATOMIC (*_processedBlockId, CompressedInputStream::CANCEL_TASKS_ID );
1075- #endif
10761026
10771027 if (transform != nullptr )
10781028 delete transform;
0 commit comments