public class SegmentedLock extends Object
Constructor and Description |
---|
SegmentedLock(int numLocks,
int numBuckets)
Create a segmented lock with specified locks.
|
Modifier and Type | Method and Description |
---|---|
int |
getNumBucketsPerSegment() |
int |
getNumLocks() |
int |
getSegmentIndex(int bucket) |
int |
getSegmentStartPos(int index) |
void |
readLock(int bucket1,
int bucket2)
Non-exclusively acquires the locks of two buckets, blocking if necessary until available.
|
void |
unlockRead(int bucket1,
int bucket2)
Releases the read locks of two buckets if they are held.
|
void |
unlockWrite(int bucket)
Releases the write lock of bucket if it is held.
|
void |
unlockWrite(int bucket1,
int bucket2)
Releases the write locks of two buckets if they are held.
|
void |
unlockWrite(int bucket1,
int bucket2,
int bucket3)
Releases the write locks of three buckets if they are held.
|
void |
unlockWriteSegment(int index)
Releases the write lock of the ith segment if it is held.
|
void |
writeLock(int bucket)
Exclusively acquires the lock of the bucket, blocking if necessary until available.
|
void |
writeLock(int b1,
int b2)
Exclusively acquires the locks of two buckets, blocking if necessary until available.
|
void |
writeLock(int bucket1,
int bucket2,
int bucket3)
Exclusively acquires the locks of three buckets, blocking if necessary until available.
|
void |
writeLockSegment(int index)
Exclusively acquires the lock of the ith segment, blocking if necessary until available.
|
public SegmentedLock(int numLocks, int numBuckets)
numBuckets
- the number of bucketsnumLocks
- the number of lockspublic void readLock(int bucket1, int bucket2)
bucket1
- the first bucket to be lockedbucket2
- the second bucket to be lockedpublic void unlockRead(int bucket1, int bucket2)
bucket1
- the first bucket to be unlockedbucket2
- the second bucket to be unlockedpublic void writeLock(int bucket)
bucket
- the bucket to be lockedpublic void writeLock(int b1, int b2)
b1
- the first bucket to be lockedb2
- the second bucket to be lockedpublic void writeLock(int bucket1, int bucket2, int bucket3)
bucket1
- the first bucket to be lockedbucket2
- the second bucket to be lockedbucket3
- the third bucket to be lockedpublic void unlockWrite(int bucket)
bucket
- the bucket to be unlockedpublic void unlockWrite(int bucket1, int bucket2)
bucket1
- the first bucket to be unlockedbucket2
- the second bucket to be unlockedpublic void unlockWrite(int bucket1, int bucket2, int bucket3)
bucket1
- the first bucket to be unlockedbucket2
- the second bucket to be unlockedbucket3
- the third bucket to be unlockedpublic void writeLockSegment(int index)
index
- of the segment to be lockedpublic void unlockWriteSegment(int index)
index
- of the segment to be unlockedpublic int getNumLocks()
public int getNumBucketsPerSegment()
public int getSegmentStartPos(int index)
index
- index of the segmentpublic int getSegmentIndex(int bucket)
bucket
- the bucketCopyright © 2023. All Rights Reserved.