/[svn]/linuxsampler/trunk/src/testcases/MutexTest.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/testcases/MutexTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3547 by schoenebeck, Fri Apr 29 20:43:07 2005 UTC revision 3548 by schoenebeck, Wed Jul 31 09:35:10 2019 UTC
# Line 9  using namespace std; Line 9  using namespace std;
9    
10  // ConcurrentThread  // ConcurrentThread
11    
12  MutexTest::ConcurrentThread::ConcurrentThread() : Thread(false, false, 0, -4) {  MutexTest::ConcurrentThread::ConcurrentThread() : Thread(false, false, 0, -4),
13        mutex(Mutex::RECURSIVE)
14    {
15      resource = 0;      resource = 0;
16  }  }
17    
# Line 22  int MutexTest::ConcurrentThread::Main() Line 24  int MutexTest::ConcurrentThread::Main()
24    
25  // DummyThread  // DummyThread
26    
27  MutexTest::DummyThread::DummyThread() : Thread(false, false, 0, -4) {  MutexTest::DummyThread::DummyThread() : Thread(false, false, 0, -4),
28        mutex(Mutex::RECURSIVE)
29    {
30      resource = 0;      resource = 0;
31  }  }
32    
# Line 86  void MutexTest::testDoubleLock() { Line 90  void MutexTest::testDoubleLock() {
90    
91  // Check if the previous tests namely 'testLock()' and 'testUnlock()' still work with double locking previously  // Check if the previous tests namely 'testLock()' and 'testUnlock()' still work with double locking previously
92  void MutexTest::testDoubleLockStillBlocksConcurrentThread() {  void MutexTest::testDoubleLockStillBlocksConcurrentThread() {
   bool success = false;  
93    // check if testDoubleLock() succeeds, otherwise this test doesnt make sense anyway    // check if testDoubleLock() succeeds, otherwise this test doesnt make sense anyway
94    doubleLockSucceeded = false;    doubleLockSucceeded = false;
95    testDoubleLock();    testDoubleLock();
# Line 96  void MutexTest::testDoubleLockStillBlock Line 99  void MutexTest::testDoubleLockStillBlock
99        t.mutex.Lock();        t.mutex.Lock();
100        t.SignalStartThread();        t.SignalStartThread();
101        usleep(400000); // wait 400ms        usleep(400000); // wait 400ms
102        success = (t.resource == 0);        bool success = (t.resource == 0);
103        t.mutex.Unlock();        CPPUNIT_ASSERT(success);
104          if (success) {
105              t.mutex.Unlock();
106              usleep(200000); // wait 200ms
107              success = (t.resource == 0); // thread should should still be blocked, since recursive mutex
108              CPPUNIT_ASSERT(success);
109          }
110        if (success) {        if (success) {
111              t.mutex.Unlock();
112            usleep(200000); // wait 200ms            usleep(200000); // wait 200ms
113            success = (t.resource == 1);            CPPUNIT_ASSERT(t.resource == 1); // unlock count matches previous lock count, so thread should have run through now
114        }        }
115      } else {
116          CPPUNIT_ASSERT(false);
117    }    }
   CPPUNIT_ASSERT(success);  
118  }  }

Legend:
Removed from v.3547  
changed lines
  Added in v.3548

  ViewVC Help
Powered by ViewVC