<commit_before>;; mutexLock [Concurrency]
;;  Atomically locks a mutex byte.  The application should
;;  initialize the byte with [[initMutex]].
;;  This routine blocks until the mutex is locked.
;;  Interrupts will be enabled to perform a context switch
;;  (if needed) and restored to their former state when done.
;; Inputs:
;;  HL: Pointer to mutex byte
mutexLock:
    push af
        ; There is not a set-and-check instruction on z80,
        ; so interrupts must be disabled for the check.
        ld a, i
        push af
_:          di
            ld a, (hl)
            inc a
            jr z, _
            ei
            call contextSwitch
            jr -_
_:          call getCurrentThreadID
            ld (hl), a
        pop af
        jp po, _
        ei
_:  pop af
    ret

;; mutexUnlock [Concurrency]
;;  Atomically unlocks a mutex byte.  If the mutex is not
;;  locked already by this thread, the thread will be killed!
;; Inputs:
;;  HL: Pointer to mutex byte
mutexUnlock:
    push af
        call getCurrentThreadID
        cp (hl)
        jr z, _
        jp killCurrentThread
_:  pop af
    ; jr initMutex

;; mutexInit [Concurrency]
;;  Initializes a byte at (HL) to be used with lockMutex
;;  and unlockMutex.
;; Inputs:
;;  HL: Pointer to mutex byte
mutexInit:
    ld (hl), 0xFF
    ret


;; condInit [Concurrency]
;;  Returns a pointer to a newly allocated condition variable.
;;  The application must [[free]] this variable when no threads
;;  are using it any longer.
;; Outputs:
;;  Z: Set on success, reset on failure
;;  A: Error code (on failure)
;;  IX: Pointer to condition variable (on success)
condInit:
    push af
    push bc
        ; Up to maxThreads-1 may wait.  (All threads waiting would never awaken.)
        ; The extra byte is the counter.
        ld bc, maxThreads
        call calloc
        jr nz, .fail
    pop bc
    pop af
    cp a
    ret
.fail:<commit_msg>derp, forgot element size specifier<commit_after>;; mutexLock [Concurrency]
;;  Atomically locks a mutex byte.  The application should
;;  initialize the byte with [[initMutex]].
;;  This routine blocks until the mutex is locked.
;;  Interrupts will be enabled to perform a context switch
;;  (if needed) and restored to their former state when done.
;; Inputs:
;;  HL: Pointer to mutex byte
mutexLock:
    push af
        ; There is not a set-and-check instruction on z80,
        ; so interrupts must be disabled for the check.
        ld a, i
        push af
_:          di
            ld a, (hl)
            inc a
            jr z, _
            ei
            call contextSwitch
            jr -_
_:          call getCurrentThreadID
            ld (hl), a
        pop af
        jp po, _
        ei
_:  pop af
    ret

;; mutexUnlock [Concurrency]
;;  Atomically unlocks a mutex byte.  If the mutex is not
;;  locked already by this thread, the thread will be killed!
;; Inputs:
;;  HL: Pointer to mutex byte
mutexUnlock:
    push af
        call getCurrentThreadID
        cp (hl)
        jr z, _
        jp killCurrentThread
_:  pop af
    ; jr initMutex

;; mutexInit [Concurrency]
;;  Initializes a byte at (HL) to be used with lockMutex
;;  and unlockMutex.
;; Inputs:
;;  HL: Pointer to mutex byte
mutexInit:
    ld (hl), 0xFF
    ret


;; condInit [Concurrency]
;;  Returns a pointer to a newly allocated condition variable.
;;  The application must [[free]] this variable when no threads
;;  are using it any longer.
;; Outputs:
;;  Z: Set on success, reset on failure
;;  A: Error code (on failure)
;;  IX: Pointer to condition variable (on success)
condInit:
    push af
    push bc
        ; Up to maxThreads-1 may wait.  (All threads waiting would never awaken.)
        ; The extra byte is the counter.
        ld bc, maxThreads
        ld a, 1
        call calloc
        jr nz, .fail
    pop bc
    pop af
    cp a
    ret
.fail:
{'fraction_non_alphanumeric': 0.07512953367875648, 'fraction_numerical': 0.00233160621761658, 'mean_word_length': 2.1288492706645057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4403143', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1149, 'n_words': 504}