diff options
| -rw-r--r-- | src/rw-lock.lisp | 2 | ||||
| -rw-r--r-- | test/rw-lock.lisp | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/rw-lock.lisp b/src/rw-lock.lisp index b32d3d0..bd2606c 100644 --- a/src/rw-lock.lisp +++ b/src/rw-lock.lisp | |||
| @@ -72,6 +72,7 @@ | |||
| 72 | (check-type rw-lock rw-lock) | 72 | (check-type rw-lock rw-lock) |
| 73 | (with-slots (lock unlocked readers has-writer) rw-lock | 73 | (with-slots (lock unlocked readers has-writer) rw-lock |
| 74 | (with-lock-held (lock) | 74 | (with-lock-held (lock) |
| 75 | (assert (> readers 0) nil "Trying to release a read lock that's not taken!") | ||
| 75 | (decf readers) | 76 | (decf readers) |
| 76 | (when (zerop readers) | 77 | (when (zerop readers) |
| 77 | (condition-broadcast unlocked)))) | 78 | (condition-broadcast unlocked)))) |
| @@ -117,6 +118,7 @@ | |||
| 117 | (check-type rw-lock rw-lock) | 118 | (check-type rw-lock rw-lock) |
| 118 | (with-slots (lock unlocked readers has-writer) rw-lock | 119 | (with-slots (lock unlocked readers has-writer) rw-lock |
| 119 | (with-lock-held (lock) | 120 | (with-lock-held (lock) |
| 121 | (assert has-writer nil "Trying to release a write lock that's not taken!") | ||
| 120 | (setf has-writer nil) | 122 | (setf has-writer nil) |
| 121 | (condition-broadcast unlocked))) | 123 | (condition-broadcast unlocked))) |
| 122 | rw-lock) | 124 | rw-lock) |
diff --git a/test/rw-lock.lisp b/test/rw-lock.lisp index 4460398..fdb60bd 100644 --- a/test/rw-lock.lisp +++ b/test/rw-lock.lisp | |||
| @@ -33,6 +33,12 @@ | |||
| 33 | (is (rw-lock-p (release-read-lock lock))) | 33 | (is (rw-lock-p (release-read-lock lock))) |
| 34 | (is (rw-lock-p (release-read-lock lock)))))) | 34 | (is (rw-lock-p (release-read-lock lock)))))) |
| 35 | 35 | ||
| 36 | (test release-read-lock.failing | ||
| 37 | (let ((lock (make-rw-lock))) | ||
| 38 | (signals error (release-read-lock lock)) | ||
| 39 | (is-true (acquire-write-lock lock :wait nil)) | ||
| 40 | (signals error (release-read-lock lock)))) | ||
| 41 | |||
| 36 | (test acquire-write-lock.no-contention | 42 | (test acquire-write-lock.no-contention |
| 37 | (let ((lock (make-rw-lock))) | 43 | (let ((lock (make-rw-lock))) |
| 38 | (is-true (acquire-write-lock lock :wait nil)) | 44 | (is-true (acquire-write-lock lock :wait nil)) |
| @@ -46,6 +52,12 @@ | |||
| 46 | (is-false (acquire-write-lock lock :wait nil)) | 52 | (is-false (acquire-write-lock lock :wait nil)) |
| 47 | (is (rw-lock-p (release-write-lock lock))))) | 53 | (is (rw-lock-p (release-write-lock lock))))) |
| 48 | 54 | ||
| 55 | (test acquire-write-lock.failing | ||
| 56 | (let ((lock (make-rw-lock))) | ||
| 57 | (signals error (release-write-lock lock)) | ||
| 58 | (is-true (acquire-read-lock lock :wait nil)) | ||
| 59 | (signals error (release-write-lock lock)))) | ||
| 60 | |||
| 49 | (test acquire-read&write-lock.contention | 61 | (test acquire-read&write-lock.contention |
| 50 | (let ((lock (make-rw-lock))) | 62 | (let ((lock (make-rw-lock))) |
| 51 | (is-true (acquire-read-lock lock :wait nil)) | 63 | (is-true (acquire-read-lock lock :wait nil)) |