In case the lock is not locked by the current process yet
>>#critical: will not return value of the block. This is different to how Semaphore>>#critical: works. Fix it and add a testcase for both cases. 2014-06-21 Holger Hans Peter Freyther <[hidden email]> * kernel/RecursionLock.st: Return the result of >>#critical: 2014-06-21 Holger Hans Peter Freyther <[hidden email]> * kernel/RecursionLockTests.st: Add test for RecursionLock --- ChangeLog | 4 ++ NEWS | 3 ++ kernel/RecursionLock.st | 2 +- packages/kernel-tests/ChangeLog | 4 ++ packages/kernel-tests/kernel/RecursionLockTests.st | 47 ++++++++++++++++++++++ packages/kernel-tests/package.xml | 2 + 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 packages/kernel-tests/kernel/RecursionLockTests.st diff --git a/ChangeLog b/ChangeLog index 4384e2a..db932dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-06-21 Holger Hans Peter Freyther <[hidden email]> + + * kernel/RecursionLock.st: Return the result of >>#critical: + 2014-05-01 Holger Hans Peter Freyther <[hidden email]> * scripts/Test.st: Introduce pkgScript variable and diff --git a/NEWS b/NEWS index e1920c8..b50bc7f 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,9 @@ o The Netlink module has been added for Linux. o gst-sunit -p package.xml TestClass will execute only the tests of the TestClass now. +o RecursionLock>>#critical: returns the result of the block like it + is done for Semaphore>>#critical: + ----------------------------------------------------------------------------- NEWS FROM 3.2.4 to 3.2.5 diff --git a/kernel/RecursionLock.st b/kernel/RecursionLock.st index c35088b..f588c20 100644 --- a/kernel/RecursionLock.st +++ b/kernel/RecursionLock.st @@ -101,7 +101,7 @@ Object subclass: RecursionLock [ self isOwnerProcess ifTrue: [^aBlock value]. "Look out for race conditions!" - sema critical: [ + ^sema critical: [ [owner := Processor activeProcess. aBlock value] ensure: [owner := nil]]. diff --git a/packages/kernel-tests/ChangeLog b/packages/kernel-tests/ChangeLog index d0557f3..e5b8809 100644 --- a/packages/kernel-tests/ChangeLog +++ b/packages/kernel-tests/ChangeLog @@ -1,3 +1,7 @@ +2014-06-21 Holger Hans Peter Freyther <[hidden email]> + + * kernel/RecursionLockTests.st: Add test for RecursionLock + 2014-02-06 Holger Hans Peter Freyther <[hidden email]> * kernel/CCallableTest.st: Add new file. diff --git a/packages/kernel-tests/kernel/RecursionLockTests.st b/packages/kernel-tests/kernel/RecursionLockTests.st new file mode 100644 index 0000000..25e3a33 --- /dev/null +++ b/packages/kernel-tests/kernel/RecursionLockTests.st @@ -0,0 +1,47 @@ +"====================================================================== +| +| RecursionLock Tests +| +| + ======================================================================" + +"====================================================================== +| +| Copyright 2014 +| Free Software Foundation, Inc. +| Written by Holger Hans Peter Freyther. +| +| This file is part of the GNU Smalltalk class library. +| +| The GNU Smalltalk class library is free software; you can redistribute it +| and/or modify it under the terms of the GNU Lesser General Public License +| as published by the Free Software Foundation; either version 2.1, or (at +| your option) any later version. +| +| The GNU Smalltalk class library is distributed in the hope that it will be +| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +| General Public License for more details. +| +| You should have received a copy of the GNU Lesser General Public License +| along with the GNU Smalltalk class library; see the file COPYING.LIB. +| If not, write to the Free Software Foundation, 59 Temple Place - Suite +| 330, Boston, MA 02110-1301, USA. +| + ======================================================================" + +TestCase subclass: TestRecursionLock [ + + testResult [ + | lock res | + + lock := RecursionLock new. + + res := lock critical: [3]. + self assert: res equals: 3. + + + res := lock critical: [lock critical: [4]]. + self assert: res equals: 4. + ] +] diff --git a/packages/kernel-tests/package.xml b/packages/kernel-tests/package.xml index 6a84aad..3888ed5 100644 --- a/packages/kernel-tests/package.xml +++ b/packages/kernel-tests/package.xml @@ -9,6 +9,7 @@ <sunit>TestMappedCollection</sunit> <sunit>TestObject</sunit> <sunit>TestRegexp</sunit> + <sunit>TestRecursionLock</sunit> <filein>kernel/BehaviorTests.st</filein> <filein>kernel/CCallableTest.st</filein> <filein>kernel/CompiledMethodTests.st</filein> @@ -16,6 +17,7 @@ <filein>kernel/MappedCollectionTests.st</filein> <filein>kernel/ObjectTests.st</filein> <filein>kernel/RegexpTests.st</filein> + <filein>kernel/RecursionLockTests.st</filein> </test> <file>ChangeLog</file> -- 2.0.0.rc2 _______________________________________________ help-smalltalk mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |