void *AtomicTestCase::MyThread::Entry() { wxInt32 negativeValuesSeen = 0; for ( wxInt32 i = 0; i < ITERATIONS_NUM; ++i ) { switch ( m_testType ) { case AtomicTestCase::IncAndDecMixed: wxAtomicInc(m_operateOn); wxAtomicDec(m_operateOn); if (m_operateOn < 0) ++negativeValuesSeen; break; case AtomicTestCase::IncOnly: wxAtomicInc(m_operateOn); break; case AtomicTestCase::DecOnly: wxAtomicDec(m_operateOn); break; } } return wxUIntToPtr(negativeValuesSeen); }
void AtomicTestCase::TestDecReturn() { wxAtomicInt i(0); wxAtomicInc(i); wxAtomicInc(i); CPPUNIT_ASSERT( i == 2 ); CPPUNIT_ASSERT( wxAtomicDec(i) > 0 ); CPPUNIT_ASSERT( wxAtomicDec(i) == 0 ); }
void AtomicTestCase::TestNoThread() { wxAtomicInt int1 = 0, int2 = 0; for ( wxInt32 i = 0; i < ITERATIONS_NUM; ++i ) { wxAtomicInc(int1); wxAtomicDec(int2); } CPPUNIT_ASSERT( int1 == ITERATIONS_NUM ); CPPUNIT_ASSERT( int2 == -ITERATIONS_NUM ); }
/// Write the summary to disk, using the derived ReadData() to get the data /// Here, the decoder ODTask associated with this file must fetch the samples with /// the ODDecodeTask::Decode() method. int ODDecodeBlockFile::WriteODDecodeBlockFile() { // To build the summary data, call ReadData (implemented by the // derived classes) to get the sample data SampleBuffer sampleData;// = NewSamples(mLen, floatSample); int ret; { //use the decoder here. ODLocker locker{ &mDecoderMutex }; if(!mDecoder) return -1; //sampleData and mFormat are set by the decoder. ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel); if(ret < 0) { wxPrintf("ODDecodeBlockFile Decode failure\n"); return ret; //failure } } { //the summary is also calculated here. ODLocker locker{ &mFileNameMutex }; //TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile bool bSuccess = WriteSimpleBlockFile( sampleData.ptr(), mLen, mFormat, NULL); if ( !bSuccess ) return -1; } wxAtomicInc( mDataAvailable ); return ret; }
FSArchiveHandler::FSArchiveHandler(FSArchiveFile *a) { archive = a; wxAtomicInc(archive->ref); }