void Manifold::setTangentDimension(Index td) { mnf_assert(isValid() || seeMessageAbove()); mnf_assert(td >= 0 && "Negative dimension not accepted"); testLock(); tangentDim_ = td; }
void Manifold::setRepresentationDimension(Index rd) { mnf_assert(isValid() || seeMessageAbove()); mnf_assert(rd >= 0 && "Negative dimension not accepted"); testLock(); representationDim_ = rd; }
/* Two readers aquire a read-lock, one writer attempts a write block, the readers release their locks, the writer gets the lock. */ void tst_QSystemReadWriteLock::multipleReadersBlockRelease() { bool print = false; QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create); release = false; writeThreadStarted = false; writeThreadDone = false; ReadLockReleaseableThread rlt1(print); ReadLockReleaseableThread rlt2(print); rlt1.start(); rlt2.start(); QTest::qSleep(1000); WriteLockThread wlt(print); wlt.start(); QTest::qSleep(1000); QVERIFY(writeThreadStarted); QVERIFY(!writeThreadDone); QVERIFY(wlt.isRunning()); QVERIFY(rlt1.isRunning()); QVERIFY(rlt2.isRunning()); release = true; QVERIFY(wlt.wait()); QVERIFY(rlt1.wait(2000)); QVERIFY(rlt2.wait(2000)); QVERIFY(writeThreadDone); }
void Manifold::setDimension(Index d) { mnf_assert(isValid() || seeMessageAbove()); mnf_assert(d >= 0 && "Negative dimension not accepted"); testLock(); dimension_ = d; }
static int threadFunc(int myid, void *data) { struct local_data *localData = (struct local_data *)data; // Wait on the barrier waitTestBarrier(&localData->barrier); // Then wait on the lock testLock(&localData->myLocks[myid]); testUnlock(&localData->myLocks[myid]); return 0; }
/* Multiple writers locks and unlocks a lock. */ void tst_QSystemReadWriteLock::multipleWritersLoop() { QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create); int time=500; int wait=0; int hold=0; const int numthreads=2; WriteLockLoopThread *threads[numthreads]; int i; for (i = 0; i < numthreads; ++i) threads[i] = new WriteLockLoopThread(time, hold, wait,false); for (i = 0; i < numthreads; ++i) threads[i]->start(); for (i = 0; i < numthreads; ++i) QVERIFY(threads[i]->wait(5000)); for (i = 0; i < numthreads; ++i) delete threads[i]; }
int test_mutex(int argc, char *argv[]) { PKIX_PL_Mutex *mutex, *mutex2, *mutex3; PKIX_UInt32 actualMinorVersion; PKIX_UInt32 j = 0; PKIX_TEST_STD_VARS(); startTests("Mutexes"); PKIX_TEST_EXPECT_NO_ERROR( PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); subTest("PKIX_PL_Mutex_Create"); createMutexes(&mutex, &mutex2, &mutex3); PKIX_TEST_EQ_HASH_TOSTR_DUP (mutex, mutex3, mutex2, NULL, Mutex, PKIX_FALSE); subTest("PKIX_PL_Mutex_Lock/Unlock"); testLock(mutex); subTest("PKIX_PL_Mutex_Destroy"); testDestroy(mutex, mutex2, mutex3); cleanup: PKIX_Shutdown(plContext); PKIX_TEST_RETURN(); endTests("Mutexes"); return (0); }
uint32 Scheduler::schedule() { if ( testLock() || block_scheduling_extern_>0 ) { //no scheduling today... //keep currentThread as it was //and stay in Kernel Kontext debug ( SCHEDULER,"schedule: currently blocked\n" ); return 0; } do { // WARNING: do not read currentThread before is has been set here // the first time scheduler is called. // before this, currentThread may be 0 !! currentThread = threads_.front(); if ( kill_old_ == false && currentThread->state_ == ToBeDestroyed ) kill_old_=true; //this operation doesn't allocate or delete any kernel memory threads_.rotateBack(); } while ( currentThread->state_ != Running ); // debug ( SCHEDULER,"Scheduler::schedule: new currentThread is %x %s, switch_userspace:%d\n",currentThread,currentThread->getName(),currentThread->switch_to_userspace_ ); uint32 ret = 1; if ( currentThread->switch_to_userspace_ ) currentThreadInfo = currentThread->user_arch_thread_info_; else { currentThreadInfo = currentThread->kernel_arch_thread_info_; ret=0; } return ret; }
static void testAPI(RTTEST hTest) { testMappingsQuery(hTest); testMappingsQueryName(hTest); testMapFolder(hTest); testUnmapFolder(hTest); testCreate(hTest); testClose(hTest); testRead(hTest); testWrite(hTest); testLock(hTest); testFlush(hTest); testDirList(hTest); testReadLink(hTest); testFSInfo(hTest); testRemove(hTest); testRename(hTest); testSymlink(hTest); testMappingsAdd(hTest); testMappingsRemove(hTest); /* testSetStatusLed(hTest); */ }
/* Multiple readers and writers locks and unlocks a lock. */ void tst_QSystemReadWriteLock::multipleReadersWritersLoop() { QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create); int time=10000; int numReaders=20; int readerWait=0; int readerHold=1; int numWriters=3; int writerWait=500; int writerHold=50; ReadLockLoopThreadPtr *readers = new ReadLockLoopThreadPtr[numReaders]; WriteLockLoopThreadPtr *writers = new WriteLockLoopThreadPtr[numWriters]; int i; for (i = 0; i < numReaders; ++i) readers[i] = new ReadLockLoopThread(time, readerHold, readerWait, false); for (i = 0; i < numWriters; ++i) writers[i] = new WriteLockLoopThread(time, writerHold, writerWait, false); for (i = 0; i < numReaders; ++i) readers[i]->start(QThread::NormalPriority); for (i = 0; i < numWriters; ++i) writers[i]->start(QThread::IdlePriority); for (i = 0; i < numReaders; ++i) QVERIFY(readers[i]->wait(time*2)); for (i = 0; i < numWriters; ++i) QVERIFY(writers[i]->wait(time*2)); for (i = 0; i < numReaders; ++i) delete readers[i]; for (i = 0; i < numWriters; ++i) delete writers[i]; delete[] readers; delete[] writers; }
/* Multiple readers locks and unlocks a lock. */ void tst_QSystemReadWriteLock::multipleReadersLoop() { QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create); int time=500; int hold=250; int wait=0; #if defined (Q_OS_HPUX) const int numthreads=50; #else const int numthreads=75; #endif ReadLockLoopThread *threads[numthreads]; int i; for (i=0; i < numthreads; ++i) threads[i] = new ReadLockLoopThread(time, hold, wait,false); for (i=0; i<numthreads; ++i) threads[i]->start(); for (i=0; i<numthreads; ++i) QVERIFY(threads[i]->wait()); for (i=0; i<numthreads; ++i) delete threads[i]; }
/* Writers increment a variable from 0 to maxval, then reset it to 0. Readers verify that the variable remains at 0. */ void tst_QSystemReadWriteLock::countingTest() { QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create); //int time=INT_MAX; int time=10000; int numReaders=20; int readerWait=1; int numWriters=3; int writerWait=150; int maxval=10000; ReadLockCountThreadPtr *readers = new ReadLockCountThreadPtr[numReaders]; WriteLockCountThreadPtr *writers= new WriteLockCountThreadPtr[numWriters]; int i; for (i = 0; i < numReaders; ++i) readers[i] = new ReadLockCountThread(time, readerWait); for (i = 0; i < numWriters; ++i) writers[i] = new WriteLockCountThread(time, writerWait, maxval); for (i = 0; i < numReaders; ++i) readers[i]->start(QThread::NormalPriority); for (i = 0; i < numWriters; ++i) writers[i]->start(QThread::LowestPriority); for (i = 0; i < numReaders; ++i) QVERIFY(readers[i]->wait(2 * time)); for (i = 0; i < numWriters; ++i) QVERIFY(writers[i]->wait(2 * time)); for (i = 0; i < numReaders; ++i) delete readers[i]; for (i = 0; i < numWriters; ++i) delete writers[i]; delete [] readers; delete [] writers; }
/* writer1 acquires a write-lock, writer 2 blocks, writer1 releases the lock, writer 2 gets the lock */ void tst_QSystemReadWriteLock::writeLockBlockRelease() { bool print = false; QSystemReadWriteLock testLock("Viper"); if (print) qDebug() << "Main Thread: About to lock for writing"; testLock.lockForWrite(); if (print) qDebug() << "Main Thread: After lock for writing"; writeThreadStarted = false; writeThreadDone = false; WriteLockThread wlt(print); wlt.start(); QTest::qSleep(1000); QVERIFY(writeThreadStarted); QVERIFY(!writeThreadDone); testLock.unlock(); if (print) qDebug() << "MainThread: After unlock(write)"; QVERIFY(wlt.wait(5000)); QVERIFY(writeThreadDone); }
/* A writer acquires a write-lock, a reader tries to lock. the writer releases the lock, the reader gets the lock */ void tst_QSystemReadWriteLock::readLockBlockRelease() { bool print = false; QSystemReadWriteLock testLock("Viper", QSystemReadWriteLock::Create); if (print) qDebug() << "Main Thread: About to lock for writing"; testLock.lockForWrite(); if (print) qDebug() << "Main Thread: After lock for writing"; readThreadStarted = false; readThreadDone = false; ReadLockThread rlt(print); rlt.start(); QTest::qSleep(1000); QVERIFY(readThreadStarted); QVERIFY(!readThreadDone); testLock.unlock(); if (print) qDebug() << "Main Thread: After unlock(write)"; rlt.wait(); QVERIFY(readThreadDone); }
//Basic test for create/attach and exit. int pc_thread_cont_mutatee() { int result; int error = 0; int i; struct local_data *localData = NULL; handshake can_stop; allow_exit can_exit; num_threads = 0; for (i = 0; i < gargc; i++) { if (strcmp(gargv[i], "-mt") == 0) { num_threads = atoi(gargv[i+1]); break; } } if( num_threads > 0 ) { // Each thread needs its own mutex and access to the barrier localData = (struct local_data *)malloc(sizeof(struct local_data)); initBarrier(&localData->barrier, num_threads+1); localData->myLocks = (testlock_t *)malloc(sizeof(testlock_t)*num_threads); for(i = 0; i < num_threads; ++i) { initLock(&localData->myLocks[i]); testLock(&localData->myLocks[i]); } } result = initProcControlTest(threadFunc, (void *)localData); if (result != 0) { output->log(STDERR, "Initialization failed\n"); if( num_threads > 0 ) freeLocalData(localData); return -1; } if( num_threads > 0 ) { logstatus("initial thread: waiting on barrier\n"); waitTestBarrier(&localData->barrier); // Alert the mutator that all the threads have gotten through the lock // and can safely be stopped now can_stop.code = HANDSHAKE_CODE; send_message((unsigned char *)&can_stop, sizeof(handshake)); // Wait for mutator to indicate that the stop finished memset(&can_stop, 0, sizeof(handshake)); recv_message((unsigned char *)&can_stop, sizeof(handshake)); if (can_stop.code != HANDSHAKE_CODE) { output->log(STDERR, "Received event that wasn't handshake\n"); error = 1; } logstatus("initial thread: received stop handshake, releasing threads\n"); // Release all the locks for(i = 0; i < num_threads; ++i) { testUnlock(&localData->myLocks[i]); } // Alert mutator that all threads can be continued when ready memset(&can_stop, 0, sizeof(handshake)); can_stop.code = HANDSHAKE_CODE; send_message((unsigned char *)&can_stop, sizeof(handshake)); logstatus("initial thread: all threads can be continued\n"); } recv_message((unsigned char *) &can_exit, sizeof(allow_exit)); if (can_exit.code != ALLOWEXIT_CODE) { output->log(STDERR, "Recieved event that wasn't allow_exit\n"); error = 1; } result = finiProcControlTest(0); if (result != 0) { output->log(STDERR, "Finalization failed\n"); if( num_threads > 0 ) freeLocalData(localData); return -1; } if (error) { if( num_threads > 0 ) freeLocalData(localData); return -1; } if( num_threads > 0 ) freeLocalData(localData); test_passes(testname); return 0; }
/* Completeness error test - need to replace with proper error-inducing code */ void tst_QSystemReadWriteLock::errorCheck() { QSystemReadWriteLock testLock("Viper"); QVERIFY(testLock.error() == 0); QCOMPARE(testLock.errorString(), QString("")); }