LockCount

Interpreting Critical Section Fields in Windows Server 2003 SP1 and Later

 

In Microsoft Windows Server 2003 Service Pack 1 and later versions of Windows, the LockCount field is parsed as follows:

 

The lowest bit shows the lock status. If this bit is 0, the critical section is locked; if it is 1, the critical section is not locked.

The next bit shows whether a thread has been woken for this lock. If this bit is 0, then a thread has been woken for this lock; if it is 1, no thread has been woken.

The remaining bits are the ones-complement of the number of threads waiting for the lock.

 

As an example, suppose the LockCount is -22. The lowest bit can be determined in this way:

 

0:009> ? 0x1 & (-0n22)

uate expression: 0 = 00000000

 

The next-lowest bit can be determined in this way:

 

0:009> ? (0x2 & (-0n22)) >> 1

uate expression: 1 = 00000001

 

The ones-complement of the remaining bits can be determined in this way:

 

0:009> ? ((-1) - (-0n22)) >> 2

uate expression: 5 = 00000005

 

In this example, the first bit is 0 and therefore the critical section is locked. The second bit is 1, and so no thread has been woken for this lock. The complement of the remaining bits is 5, and so there are five threads waiting for this lock.
jetcache这部分操作是什么意思 default AutoReleaseLock tryLock(K key, long expire, TimeUnit timeUnit) { if (key == null) { return null; } else { String uuid = UUID.randomUUID().toString(); long expireTimestamp = System.currentTimeMillis() + timeUnit.toMillis(expire); CacheConfig config = this.config(); AutoReleaseLock lock = () -> { int unlockCount = 0; while(unlockCount++ < config.getTryLockUnlockCount()) { if (System.currentTimeMillis() >= expireTimestamp) { logger.info("[tryLock] [{} of {}] [{}] lock already expired: Key={}", new Object[]{unlockCount, config.getTryLockUnlockCount(), uuid, key}); return; } CacheResult unlockResult = this.REMOVE(key); if (unlockResult.getResultCode() != CacheResultCode.FAIL && unlockResult.getResultCode() != CacheResultCode.PART_SUCCESS) { if (unlockResult.isSuccess()) { logger.debug("[tryLock] [{} of {}] [{}] successfully release the lock. Key={}", new Object[]{unlockCount, config.getTryLockUnlockCount(), uuid, key}); return; } logger.warn("[tryLock] [{} of {}] [{}] unexpected unlock result: Key={}, result={}", new Object[]{unlockCount, config.getTryLockUnlockCount(), uuid, key, unlockResult.getResultCode()}); return; } logger.info("[tryLock] [{} of {}] [{}] unlock failed. Key={}, msg = {}", new Object[]{unlockCount, config.getTryLockUnlockCount(), uuid, key, unlockResult.getMessage()}); } }; int lockCount = 0; Cache cache = this; while(lockCount++ < config.getTryLockLockCount()) { CacheResult lockResult = cache.PUT_IF_ABSENT(key, uuid, expire, timeUnit); if (lockResult.isSuccess()) { logger.debug("[tryLock] [{} of {}] [{}] successfully get a lock. Key={}", new Object[]{lockCount, config.getTryLockLockCount(), uuid, key}); return lock; } if (lockResult.getResultCode() != CacheResultCode.FAIL && lockResult.getResultCode() != CacheResultCode.PART_SUCCESS) { logger.debug("[tryLock] [{} of {}] [{}] others holds the lock, return null. Key={}", new Object[]{lockCount, config.getTryLockLockCount(), uuid, key}); return null; } logger.info("[tryLock] [{} of {}] [{}] cache access failed during get lock, will inquiry {} times. Key={}, msg={}", new Object[]{lockCount, config.getTryLockLockCount(), uuid, config.getTryLockInquiryCount(), key, lockResult.getMessage()}); int inquiryCount = 0; while(inquiryCount++ < config.getTryLockInquiryCount()) { CacheGetResult inquiryResult = cache.GET(key); if (inquiryResult.isSuccess()) { if (uuid.equals(inquiryResult.getValue())) { logger.debug("[tryLock] [{} of {}] [{}] successfully get a lock after inquiry. Key={}", new Object[]{inquiryCount, config.getTryLockInquiryCount(), uuid, key}); return lock; } logger.debug("[tryLock] [{} of {}] [{}] not the owner of the lock, return null. Key={}", new Object[]{inquiryCount, config.getTryLockInquiryCount(), uuid, key}); return null; } logger.info("[tryLock] [{} of {}] [{}] inquiry failed. Key={}, msg={}", new Object[]{inquiryCount, config.getTryLockInquiryCount(), uuid, key, inquiryResult.getMessage()}); } } logger.debug("[tryLock] [{}] return null after {} attempts. Key={}", new Object[]{uuid, config.getTryLockLockCount(), key}); return null; } }
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值