Just Launched: You can now import projects and releases from Google Code onto SourceForge
We are excited to release new functionality to enable a 1-click import from Google Code onto the Allura platform on SourceForge. You can import tickets, wikis, source, releases, and more with a few simple steps. Read More
Update of /cvsroot/sbcl/sbcl/src/code
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv30917/src/code
184.108.40.206: Make SB-THREAD:TRY-SEMAPHORE decrement count by N.
Add an &optional N parameter to SB-THREAD:TRY-SEMAPHORE as an
optimization so a user who wants to do so does not need to
acquire a semaphore's lock multiple times but just once.
RCS file: /cvsroot/sbcl/sbcl/src/code/target-thread.lisp,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- target-thread.lisp 29 Mar 2010 08:05:11 -0000 1.125
+++ target-thread.lisp 29 Mar 2010 10:54:08 -0000 1.126
@@ -691,17 +691,15 @@
;; may unwind without the lock being held due to timeouts.
(atomic-decf (semaphore-waitcount semaphore)))))))
-(defun try-semaphore (semaphore)
+(defun try-semaphore (semaphore &optional (n 1))
- "Try to decrement the count of SEMAPHORE if the count would not be
-negative. Else return NIL."
- ;; No need for disabling interrupts; the mutex prevents interleaved
- ;; modifications, and we don't leave temporarily inconsistent state
- ;; around.
+ "Try to decrement the count of SEMAPHORE by N. If the count were to
+become negative, punt and return NIL, otherwise return true."
+ (declare (type (integer 1) n))
(with-mutex ((semaphore-mutex semaphore))
- (let ((count (semaphore-%count semaphore)))
- (when (plusp count)
- (setf (semaphore-%count semaphore) (1- count))))))
+ (let ((new-count (- (semaphore-%count semaphore) n)))
+ (when (not (minusp new-count))
+ (setf (semaphore-%count semaphore) new-count)))))
(defun signal-semaphore (semaphore &optional (n 1))