<commit_before>package class

import (
    "sync"
    . "jvmgo/any"
    "jvmgo/util"
)

type ReentrantLock struct {
    holder      Any // *rtda.Thread
    holderLock  sync.Mutex
    lock        sync.Mutex
    lockCount   int
}

// thread: *rtda.Thread
func (self *ReentrantLock) Lock(thread Any) {
    self.holderLock.Lock()
    defer self.holderLock.Unlock()

    if self.holder == thread {
        self.lockCount++
    } else if self.holder == nil {
        self.holder = thread
        self.lockCount++
        self.lock.Lock()
    }
}

func (self *ReentrantLock) Unlock(thread Any) {
    self.holderLock.Lock()
    defer self.holderLock.Unlock()

    if self.holder == thread && self.lockCount > 0 {
        self.lockCount--
        if self.lockCount == 0 {
            self.holder = nil
            self.lock.Unlock()
        }
    } else {
        // todo
        util.Panicf("BAD ReentrantLock state! holder:%v lockCount:%v",
            self.holder, self.lockCount)
    }
}<commit_msg>ReentrantLock...<commit_after>package class

import (
    "sync"
    . "jvmgo/any"
)

type ReentrantLock struct {
    holder      Any // *rtda.Thread
    holderLock  sync.Mutex
    lock        sync.Mutex
    lockCount   int
}

func (self *ReentrantLock) Lock(thread Any) {
    self.holderLock.Lock()
    if self.holder == thread {
        self.lockCount++
        self.holderLock.Unlock()
        return
    } else {
        self.holderLock.Unlock()
    }

    self.lock.Lock()
    self.holder = thread
    self.lockCount = 1
}

func (self *ReentrantLock) Unlock(thread Any) {
    self.holderLock.Lock()
    if self.holder == thread {
        self.lockCount--
        if self.lockCount == 0 {
            self.lock.Unlock()
        }
    }
    self.holderLock.Unlock()
}
{'fraction_non_alphanumeric': 0.11961451247165533, 'fraction_numerical': 0.0022675736961451248, 'mean_word_length': 1.951505016722408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1203664', 'n_tokens_mistral': 580, 'n_tokens_neox': 573, 'n_words': 120}