Browse code
prealpha checkpoint
2010-01-21 Robert Rorschach <rfr@franz.com>
* imap.cl: threadsafe resource management
Showing 2 changed files
... | ... |
@@ -2101,20 +2101,25 @@ |
2101 | 2101 |
;;-- reusable line buffers |
2102 | 2102 |
|
2103 | 2103 |
(defvar *line-buffers* nil) |
2104 |
+(defvar *line-buffers-lock* (make-basic-lock :name "line-buffers")) |
|
2104 | 2105 |
|
2105 | 2106 |
(defun get-line-buffer (size) |
2106 | 2107 |
;; get a buffer of at least size bytes |
2107 | 2108 |
(setq size (min size (1- array-total-size-limit))) |
2108 |
- (mp::without-scheduling |
|
2109 |
- (dolist (buff *line-buffers* (make-string size)) |
|
2110 |
- (if* (>= (length buff) size) |
|
2111 |
- then ; use this one |
|
2112 |
- (setq *line-buffers* (delete buff *line-buffers*)) |
|
2113 |
- (return buff))))) |
|
2109 |
+ (let ((found |
|
2110 |
+ (with-locked-structure (*line-buffers-lock* |
|
2111 |
+ :non-smp :without-scheduling) |
|
2112 |
+ (dolist (buff *line-buffers*) |
|
2113 |
+ (if* (>= (length buff) size) |
|
2114 |
+ then ;; use this one |
|
2115 |
+ (setq *line-buffers* (delete buff *line-buffers*)) |
|
2116 |
+ (return buff)))))) |
|
2117 |
+ (or found (make-string size)))) |
|
2114 | 2118 |
|
2115 | 2119 |
|
2116 | 2120 |
(defun free-line-buffer (buff) |
2117 |
- (mp:without-scheduling |
|
2121 |
+ (with-locked-structure (*line-buffers-lock* |
|
2122 |
+ :non-smp :without-scheduling) |
|
2118 | 2123 |
(push buff *line-buffers*))) |
2119 | 2124 |
|
2120 | 2125 |
(defun init-line-buffer (new old) |