(inst or tls tls)
(inst jmp :z global-val)
(inst cmp (make-ea :qword :base thread-base-tn :scale 1 :index tls)
- unbound-marker-widetag)
+ no-tls-value-marker-widetag)
(inst jmp :z global-val)
(inst mov (make-ea :qword :base thread-base-tn :scale 1 :index tls)
value)
(:vop-var vop)
(:save-p :compute-only)
(:generator 9
- (let* ((err-lab (generate-error-code vop unbound-symbol-error object))
+ (let* ((check-unbound-label (gen-label))
+ (err-lab (generate-error-code vop unbound-symbol-error object))
(ret-lab (gen-label)))
(loadw value object symbol-tls-index-slot other-pointer-lowtag)
(inst mov value (make-ea :qword :base thread-base-tn
:index value :scale 1))
- (inst cmp value unbound-marker-widetag)
- (inst jmp :ne ret-lab)
+ (inst cmp value no-tls-value-marker-widetag)
+ (inst jmp :ne check-unbound-label)
(loadw value object symbol-value-slot other-pointer-lowtag)
+ (emit-label check-unbound-label)
(inst cmp value unbound-marker-widetag)
(inst jmp :e err-lab)
(emit-label ret-lab))))
(loadw value object symbol-tls-index-slot other-pointer-lowtag)
(inst mov value
(make-ea :qword :base thread-base-tn :index value :scale 1))
- (inst cmp value unbound-marker-widetag)
+ (inst cmp value no-tls-value-marker-widetag)
(inst jmp :ne ret-lab)
(loadw value object symbol-value-slot other-pointer-lowtag)
(emit-label ret-lab))))
(:info target not-p)
(:temporary (:sc descriptor-reg #+nil(:from (:argument 0))) value)
(:generator 9
- (if not-p
- (let ((not-target (gen-label)))
- (loadw value object symbol-value-slot other-pointer-lowtag)
- (inst cmp value unbound-marker-widetag)
- (inst jmp :ne not-target)
- (loadw value object symbol-tls-index-slot other-pointer-lowtag)
- (inst cmp (make-ea :qword :base thread-base-tn
- :index value :scale 1) unbound-marker-widetag)
- (inst jmp :e target)
- (emit-label not-target))
- (progn
- (loadw value object symbol-value-slot other-pointer-lowtag)
- (inst cmp value unbound-marker-widetag)
- (inst jmp :ne target)
- (loadw value object symbol-tls-index-slot other-pointer-lowtag)
- (inst cmp (make-ea :qword :base thread-base-tn :index value :scale 1)
- unbound-marker-widetag)
- (inst jmp :ne target)))))
+ (let ((check-unbound-label (gen-label)))
+ (loadw value object symbol-tls-index-slot other-pointer-lowtag)
+ (inst mov value
+ (make-ea :qword :base thread-base-tn :index value :scale 1))
+ (inst cmp value no-tls-value-marker-widetag)
+ (inst jmp :ne check-unbound-label)
+ (loadw value object symbol-value-slot other-pointer-lowtag)
+ (emit-label check-unbound-label)
+ (inst cmp value unbound-marker-widetag)
+ (inst jmp (if not-p :e :ne) target))))
#!-sb-thread
(define-vop (boundp)
(define-vop (bind)
(:args (val :scs (any-reg descriptor-reg))
(symbol :scs (descriptor-reg)))
+ (:temporary (:sc descriptor-reg :offset rax-offset) rax)
(:temporary (:sc unsigned-reg) tls-index temp bsp)
- (:generator 5
- (let ((tls-index-valid (gen-label)))
+ (:generator 10
+ (let ((tls-index-valid (gen-label))
+ (get-tls-index-lock (gen-label))
+ (release-tls-index-lock (gen-label)))
(load-tl-symbol-value bsp *binding-stack-pointer*)
(loadw tls-index symbol symbol-tls-index-slot other-pointer-lowtag)
(inst add bsp (* binding-size n-word-bytes))
(store-tl-symbol-value bsp *binding-stack-pointer* temp)
-
(inst or tls-index tls-index)
(inst jmp :ne tls-index-valid)
- ;; allocate a new tls-index
- (load-symbol-value tls-index *free-tls-index*)
- (inst add tls-index 8) ;XXX surely we can do this more
- (store-symbol-value tls-index *free-tls-index*) ;succintly
- (inst sub tls-index 8)
- (storew tls-index symbol symbol-tls-index-slot other-pointer-lowtag)
+
+ (pseudo-atomic
+ (emit-label get-tls-index-lock)
+ (inst mov temp 1)
+ (inst xor rax rax)
+ (inst lock)
+ (inst cmpxchg (make-ea-for-symbol-value *tls-index-lock*) temp)
+ (inst jmp :ne get-tls-index-lock)
+ ;; now with the lock held, see if the symbol's tls index has
+ ;; been set in the meantime
+ (loadw tls-index symbol symbol-tls-index-slot other-pointer-lowtag)
+ (inst or tls-index tls-index)
+ (inst jmp :ne release-tls-index-lock)
+ ;; allocate a new tls-index
+ (load-symbol-value tls-index *free-tls-index*)
+ (inst add tls-index 8) ;XXX surely we can do this more
+ (store-symbol-value tls-index *free-tls-index*) ;succintly
+ (inst sub tls-index 8)
+ (storew tls-index symbol symbol-tls-index-slot other-pointer-lowtag)
+ (emit-label release-tls-index-lock)
+ (store-symbol-value 0 *tls-index-lock*))
+
(emit-label tls-index-valid)
(inst mov temp
(make-ea :qword :base thread-base-tn :scale 1 :index tls-index))