-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved lock mechanism using lock-token.
- Loading branch information
Showing
15 changed files
with
246 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
# Changes Logs | ||
|
||
## v0.2.0 | ||
|
||
- Added documents. | ||
- Improved lock mechanism using lock-token. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# LiteRT/Mutex 文档 | ||
|
||
Mutex.js 库提供互斥量,用于多会话、多进程环境下,对资源的访问进行控制。 | ||
|
||
## 目录 | ||
|
||
- [API 文档](./apis/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# LiteRT/Mutex API 文档 | ||
|
||
## 目录 | ||
|
||
- [接口 IDriver](./interface.IDriver.md) | ||
- [接口 IFactory](./interface.IFactory.md) | ||
- [接口 IMutex](./interface.IMutex.md) | ||
- [模块方法 createFactory](./method.createFactory.md) | ||
- [模块方法 getDefaultFactory](./method.getDefaultFactory.md) | ||
- [模块方法 createIntraprocessDriver](./method.createIntraprocessDriver.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 接口 IDriver | ||
|
||
该接口描述一个驱动对象的基本方法。 | ||
|
||
```ts | ||
interface IDriver { | ||
|
||
/** | ||
* 尝试锁定一个互斥量。 | ||
* | ||
* @param key 互斥量的唯一名称。 | ||
* @param token 互斥量的锁定状态标识,用于确认是由哪个对象锁定的。 | ||
* @param expiringAt 互斥量的锁定有效时长。设置为 0 则永不过期。 | ||
* 这是一个毫秒时间戳。 | ||
*/ | ||
lock( | ||
key: string, | ||
token: string, | ||
expiringAt: number | ||
): Promise<boolean> | boolean; | ||
|
||
/** | ||
* 根据锁定标识解锁一个互斥量。 | ||
* | ||
* @param key 互斥量的唯一名称。 | ||
* @param token 互斥量的锁定状态标识,用于确认是由哪个对象锁定的。 | ||
*/ | ||
unlock(key: string, token: string): Promise<boolean> | boolean; | ||
|
||
/** | ||
* 判断一个互斥量是否被(指定锁定标识的拥有者)锁定。 | ||
* | ||
* @param key 互斥量的唯一名称。 | ||
* @param token 互斥量的锁定状态标识,用于确认是由哪个对象锁定的。 | ||
*/ | ||
checkLocked(key: string, token: string): Promise<boolean> | boolean; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 接口 IFactory | ||
|
||
该接口描述一个工厂对象的基本方法。 | ||
|
||
```ts | ||
interface IFactory { | ||
|
||
/** | ||
* 将一个驱动对象注册为一种互斥量类型。 | ||
* | ||
* @param name 类型名称 | ||
* @param driver 驱动对象 | ||
*/ | ||
registerType( | ||
name: string, | ||
driver: IDriver | ||
): this; | ||
|
||
/** | ||
* 列出所有可用的互斥量类型名称。 | ||
*/ | ||
listTypes(): string[]; | ||
|
||
/** | ||
* 创建一个指定类型的互斥量对象。 | ||
* | ||
* @param type 互斥量类型 | ||
* @param key 互斥量的唯一标识符 | ||
* @param ttl 互斥量的锁定有效时长。设置为 0 则永不过期。默认值:0 (毫秒) | ||
*/ | ||
createMutex( | ||
type: string, | ||
key: string, | ||
ttl?: number | ||
): IMutex; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# 接口 IMutex | ||
|
||
该接口描述一个互斥量对象的基本操作接口。 | ||
|
||
每个互斥量通过一个 key 进行标识。而一个互斥量对象是对特定一个互斥量的控制器。多个对象 | ||
可以通过同一个 key 对同一个互斥量进行控制。彼此之间的控制相互排斥。 | ||
|
||
```ts | ||
interface IMutex { | ||
|
||
/** | ||
* 获取当前对象互斥量的唯一名称。 | ||
*/ | ||
readonly key: string; | ||
|
||
/** | ||
* 当前对象对该互斥量的每次锁定有效时长,单位:毫秒。 | ||
* | ||
* 0 表示永久有效。 | ||
*/ | ||
readonly ttl: number; | ||
|
||
/** | ||
* 当前对象对该互斥量的锁定时间,这是一个毫秒时间戳。 | ||
* | ||
* 0 表示未锁定。 | ||
*/ | ||
readonly lockedAt: number; | ||
|
||
/** | ||
* 该互斥量的锁定状态过期时间,到这个时间则该互斥量的锁定状态自动解除。 | ||
* | ||
* 这是一个毫秒时间戳。 | ||
* | ||
* 0 表示未永不过期。 | ||
*/ | ||
readonly expiringAt: number; | ||
|
||
/** | ||
* 检查当前对象是否成功锁定了该互斥量。 | ||
*/ | ||
isLocked(): boolean; | ||
|
||
/** | ||
* 检查当前对象对该互斥量的锁定状态是否已经过期。 | ||
*/ | ||
isExpired(): boolean; | ||
|
||
/** | ||
* 重新检查当前对象对该互斥量的锁定状态。 | ||
*/ | ||
recheckLocked(): Promise<boolean> | boolean; | ||
|
||
/** | ||
* 尝试锁定该互斥量。该接口是非阻塞的,一旦失败立即返回,而不是等待其他会话、进程 | ||
* 释放锁。 | ||
* | ||
* 如果该互斥量此前已经被当前对象锁定了,则也会返回 false。 | ||
* | ||
* @param ttl 锁定状态的有效时长,该参数可以覆盖该互斥量对象的设置。如果设置为 | ||
* 0 则互斥量的锁定状态永不过期。 | ||
* 默认值:0 (毫秒) | ||
*/ | ||
lock(ttl?: number): Promise<boolean> | boolean; | ||
|
||
/** | ||
* 解除当前对象对该互斥量的锁定。 | ||
* | ||
* 如果该互斥量不是被当前对象锁定的,则无法解除锁定,返回 false。 | ||
*/ | ||
unlock(): Promise<boolean> | boolean; | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 模块方法 createFactory | ||
|
||
该方法用于创建一个互斥量对象的工厂对象。 | ||
|
||
```ts | ||
function createFactory(): IFactory; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# 模块方法 createIntraprocessDriver | ||
|
||
该方法用于创建一个进程内(`Intraprocess`)的互斥量驱动对象。 | ||
|
||
> 每个 `Intraprocess` 对象彼此独立隔离,即不同的 `Intraprocess` 对象之间,可以有 | ||
> 同名的互斥量,且互不干扰。 | ||
```ts | ||
function createIntraprocessDriver(): IDriver; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 模块方法 getDefaultFactory | ||
|
||
该方法用于获取默认的互斥量对象的工厂对象。 | ||
|
||
```ts | ||
function getDefaultFactory(): IFactory; | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.