Changeset 9389 in project


Ignore:
Timestamp:
03/09/08 21:57:56 (12 years ago)
Author:
sjamaan
Message:

Fix locking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/9p/trunk/9p-client.scm

    r9388 r9389  
    7979  (cond
    8080   ((not (eq? (mutex-state mutex) (current-thread))) (error "The current thread does not own the mutex!"))
    81    ((> (mutex-specific mutex) 1) (mutex-specific-set! mutex (sub1 (mutex-specific mutex))))
     81   ((> (mutex-specific mutex) 0) (mutex-specific-set! mutex (sub1 (mutex-specific mutex))))
    8282   (else (mutex-unlock! mutex))))
    8383
     
    120120    (with-semaphore
    121121     (9p:connection-write-mutex con)
    122      (lambda () (9p:send-message (9p:connection-outport con) (make-9p:message type tag args))))
     122     (lambda ()
     123       (9p:send-message (9p:connection-outport con) (make-9p:message type tag args))))
    123124    tag))
    124125
     
    141142;; Threadsafe receive-message.
    142143(define (9p:client-receive-message tag con)
    143   (with-semaphore
    144    (9p:connection-read-mutex con)
    145    (lambda ()
    146      (let ((message
    147             (or
    148              (9p:retrieve-message con tag)
    149              (let loop ((message (9p:receive-message
    150                                   (9p:connection-inport con))))
    151                (if (= (9p:message-tag message) tag)
    152                    message
    153                    (begin
    154                      (9p:store-message con message)
    155                      (loop (9p:receive-message
    156                             (9p:connection-inport con)))))))))
    157        (unless (= tag 9p:notag) (9p:release-tag con (9p:message-tag message)))
    158        message))))
     144  (semaphore-lock! (9p:connection-read-mutex con))
     145  (let ((message (or
     146                  (9p:retrieve-message con tag)
     147                  (9p:receive-message
     148                   (9p:connection-inport con)))))
     149    (if (= (9p:message-tag message) tag)
     150        (begin
     151          (unless (= tag 9p:notag) (9p:release-tag con (9p:message-tag message)))
     152          (semaphore-unlock! (9p:connection-read-mutex con))
     153          message)
     154        (begin
     155          (9p:store-message con message)
     156          (semaphore-unlock! (9p:connection-read-mutex con))
     157          (9p:client-receive-message tag con)))))
    159158
    160159;; Client request.  Sends a message of the given type and args and waits
Note: See TracChangeset for help on using the changeset viewer.