From: <der...@us...> - 2003-10-27 22:19:31
|
Update of /cvsroot/openh323/pwlib/samples/ThreadSafe In directory sc8-pr-cvs1:/tmp/cvs-serv1999 Modified Files: main.cxx main.h Log Message: Add more good changes to get Compare method work. Thanks to Gene Small Index: main.cxx =================================================================== RCS file: /cvsroot/openh323/pwlib/samples/ThreadSafe/main.cxx,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.cxx 13 Oct 2003 23:38:31 -0000 1.4 --- main.cxx 27 Oct 2003 22:12:56 -0000 1.5 *************** *** 9,12 **** --- 9,15 ---- * * $Log$ + * Revision 1.5 2003/10/27 22:12:56 dereksmithies + * Add more good changes to get Compare method work. Thanks to Gene Small + * * Revision 1.4 2003/10/13 23:38:31 dereksmithies * Add debugging statements, usage(), Fixed Compare method. Thanks Gene Small. *************** *** 58,65 **** PAssert(obj.IsDescendant(Class()), PInvalidCast); unsigned othervalue = ((const TestObject &)obj).value; if (value < othervalue) return LessThan; if (value > othervalue) ! return GreaterThan; return EqualTo; } --- 61,69 ---- PAssert(obj.IsDescendant(Class()), PInvalidCast); unsigned othervalue = ((const TestObject &)obj).value; + if (value < othervalue) return LessThan; if (value > othervalue) ! return GreaterThan; return EqualTo; } *************** *** 157,165 **** } ! Test1Output(); sorted.RemoveAll(); unsorted.RemoveAll(); sparse.RemoveAll(); ! Test1Output(); } --- 161,169 ---- } ! Test1OutputEnd(); sorted.RemoveAll(); unsorted.RemoveAll(); sparse.RemoveAll(); ! Test1OutputEnd(); } *************** *** 167,170 **** --- 171,175 ---- void ThreadSafe::Test1Output() { + PSafePtr<TestObject> ptr; sorted.DeleteObjectsToBeRemoved(); unsorted.DeleteObjectsToBeRemoved(); *************** *** 176,189 **** << ", Sorted=" << sorted.GetSize() << ", Dictionary=" << sparse.GetSize() ! << ", Objects="; mutexObjects.Wait(); ! cout << currentObjects << '/' << totalObjects; mutexObjects.Signal(); - cout << endl; } void ThreadSafe::Test1Thread(PThread &, INT duration) { --- 181,219 ---- << ", Sorted=" << sorted.GetSize() << ", Dictionary=" << sparse.GetSize() ! << ", Objects:"; ! mutexObjects.Wait(); ! cout << currentObjects << '/' << totalObjects << endl; mutexObjects.Signal(); + + } + + void ThreadSafe::Test1OutputEnd() + { + PSafePtr<TestObject> ptr; + + Test1Output(); + + cout << setprecision(0) << setw(5) << (PTimer::Tick() - startTick) << " Unsorted:" << endl; + for (ptr = unsorted.GetWithLock(0, PSafeReference); ptr != NULL; ++ptr) { + cout << *ptr << endl; + } + + cout << setprecision(0) << setw(5) << (PTimer::Tick() - startTick) << " Sorted:" << endl; + for (ptr = sorted.GetWithLock(0, PSafeReference); ptr != NULL; ++ptr) { + cout << *ptr << endl; + } + + cout << setprecision(0) << setw(5) << (PTimer::Tick() - startTick) << " Sparse:" << endl; + for (ptr = sparse.GetWithLock(0, PSafeReference); ptr != NULL; ++ptr) { + cout << *ptr << endl; + } + } + void ThreadSafe::Test1Thread(PThread &, INT duration) { *************** *** 194,198 **** while (timeout.IsRunning()) { ! switch (random%15) { case 0 : if (random%(unsorted.GetSize()+1) == 0) --- 224,228 ---- while (timeout.IsRunning()) { ! switch (random%17) { case 0 : if (random%(unsorted.GetSize()+1) == 0) *************** *** 271,274 **** --- 301,325 ---- Sleep(random%50); break; + + + case 15 : + if ( unsorted.GetSize() > 0 ) { + PSafePtr<TestObject> ptr2 = unsorted.GetWithLock(unsorted.GetSize() - 1, PSafeReadOnly); + + if ( ptr2 != NULL ) + ptr2 = unsorted.FindWithLock(*ptr2, PSafeReadOnly); + } + + break; + + case 16 : + if ( sorted.GetSize() > 0 ) { + PSafePtr<TestObject> ptr2 = unsorted.GetWithLock(sorted.GetSize() - 1, PSafeReference); + + if ( ptr2 != NULL ) + ptr2 = sorted.FindWithLock(*ptr2, PSafeReference); + } + break; + } Sleep(random%500); Index: main.h =================================================================== RCS file: /cvsroot/openh323/pwlib/samples/ThreadSafe/main.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.h 13 Oct 2003 23:38:31 -0000 1.5 --- main.h 27 Oct 2003 22:12:56 -0000 1.6 *************** *** 7,10 **** --- 7,13 ---- * * $Log$ + * Revision 1.6 2003/10/27 22:12:56 dereksmithies + * Add more good changes to get Compare method work. Thanks to Gene Small + * * Revision 1.5 2003/10/13 23:38:31 dereksmithies * Add debugging statements, usage(), Fixed Compare method. Thanks Gene Small. *************** *** 47,54 **** }; - PLIST(TestList, TestObject); - PSORTED_LIST(TestSortedList, TestObject); - PDICTIONARY(TestDict, POrdinalKey, TestObject); - class ThreadSafe : public PProcess --- 50,53 ---- *************** *** 66,69 **** --- 65,69 ---- void Test1(PArgList & args); void Test1Output(); + void Test1OutputEnd(); PDECLARE_NOTIFIER(PThread, ThreadSafe, Test1Thread); *************** *** 77,81 **** PSafeList<TestObject> unsorted; ! PSafeList<TestObject> sorted; PSafeDictionary<POrdinalKey, TestObject> sparse; --- 77,81 ---- PSafeList<TestObject> unsorted; ! PSafeSortedList<TestObject> sorted; PSafeDictionary<POrdinalKey, TestObject> sparse; |