Changeset 12213


Ignore:
Timestamp:
10/23/09 20:03:55 (12 years ago)
Author:
ehuelsmann
Message:

Move the implementation of the Mutex functionality to the THREADS package
*and* move the implementation to Lisp.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Autoload.java

    r12059 r12213  
    666666        autoload(PACKAGE_SYS, "zip", "zip", true);
    667667
    668         autoload(PACKAGE_THREADS, "make-mutex", "Mutex", true);
    669         autoload(PACKAGE_THREADS, "get-mutex", "Mutex", true);
    670         autoload(PACKAGE_THREADS, "release-mutex", "Mutex", true);
    671 
    672668        autoload(Symbol.COPY_LIST, "copy_list");
    673669
  • trunk/abcl/src/org/armedbear/lisp/autoloads.lisp

    r12075 r12213  
    293293
    294294(in-package "THREADS")
    295 (sys::export '(mailbox-send mailbox-empty-p mailbox-read mailbox-peek))
    296 (sys::autoload '(mailbox-send mailbox-empty-p mailbox-read mailbox-peek)
     295
     296
     297(autoload '(;; Mailbox
     298            make-mailbox mailbox-send mailbox-empty-p
     299            mailbox-read mailbox-peek
     300
     301            ;; Lock
     302            make-thread-lock thread-lock thread-unlock
     303
     304            ;; Mutex
     305            make-mutex get-mutex release-mutex)
    297306    "threads")
    298307
    299 (sys::export '(make-thread-lock thread-lock thread-unlock with-thread-lock))
    300 (sys::autoload '(make-thread-lock thread-lock thread-unlock) "threads")
    301 (sys::autoload-macro 'with-thread-lock "threads")
    302 
    303 ;; block to be removed at 0.22
    304 
    305 (in-package "EXTENSIONS")
    306 
    307 (export '(mailbox-send mailbox-empty-p mailbox-read mailbox-peek))
     308(autoload-macro '(;; Lock
     309                  with-thread-lock
     310
     311                  ;; Mutex
     312                  with-mutex)
     313                "threads")
     314
     315(export '(make-mailbox mailbox-send mailbox-empty-p
     316          mailbox-read mailbox-peek))
    308317(export '(make-thread-lock thread-lock thread-unlock with-thread-lock))
     318(export '(make-mutex get-mutex release-mutex with-mutex))
     319
     320(progn
     321  ;; block to be removed at 0.22
     322  ;; It exists solely for pre-0.17 compatibility
     323  ;; FIXME 0.22
     324  (in-package "EXTENSIONS")
     325  (export '(mailbox-send mailbox-empty-p mailbox-read mailbox-peek))
     326  (export '(make-thread-lock thread-lock thread-unlock with-thread-lock))
     327  (export '(with-mutex make-mutex get-mutex release-mutex)))
    309328
    310329;; end of 0.22 block
     
    341360(autoload 'compiler-let)
    342361
    343 (in-package "THREADS")
    344 (export 'with-mutex)
    345 (ext:autoload-macro 'with-mutex)
  • trunk/abcl/src/org/armedbear/lisp/compile-system.lisp

    r12060 r12213  
    257257                           "with-hash-table-iterator.lisp"
    258258                           "with-input-from-string.lisp"
    259                            "with-mutex.lisp"
    260259                           "with-open-file.lisp"
    261260                           "with-output-to-string.lisp"
  • trunk/abcl/src/org/armedbear/lisp/threads.lisp

    r12059 r12213  
    3939
    4040;; this export statement is also in autoloads.lisp
    41 (export '(mailbox-send mailbox-empty-p mailbox-read mailbox-peek))
     41(export '(make-mailbox mailbox-send mailbox-empty-p mailbox-read mailbox-peek))
    4242
    4343(defstruct mailbox
     
    8383
    8484;;
     85;; Mutex implementation
     86;;
     87
     88
     89;; this export statement is also in autoloads.lisp
     90(export '(make-mutex get-mutex release-mutex))
     91
     92(defstruct mutex
     93  in-use)
     94
     95(defun get-mutex (mutex)
     96  "Acquires a lock on the `mutex'."
     97  (synchronized-on mutex
     98    (loop
     99       while (mutex-in-use mutex)
     100       do (object-wait mutex))
     101    (setf (mutex-in-use mutex) T)))
     102
     103(defun release-mutex (mutex)
     104  "Releases a lock on the `mutex'."
     105  (synchronized-on mutex
     106    (setf (mutex-in-use mutex) NIL)
     107    (object-notify mutex)))
     108
     109(defmacro with-mutex ((mutex) &body body)
     110  "Acquires a lock on `mutex', executes the body
     111and releases the lock."
     112  (let ((m (gensym)))
     113    `(let ((,m ,mutex))
     114       (when (get-mutex ,m)
     115         (unwind-protect
     116          (progn
     117            ,@body)
     118          (release-mutex ,m))))))
     119
     120
     121;;
    85122;; Lock implementation
    86123;;
     
    91128
    92129(defmacro with-thread-lock ((lock) &body body)
     130  "Acquires a lock on the `lock', executes `body' and releases the lock."
    93131  (let ((glock (gensym)))
    94132    `(let ((,glock ,lock))
Note: See TracChangeset for help on using the changeset viewer.