-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoo.d.ts
87 lines (87 loc) · 2.37 KB
/
foo.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
declare module "Sized" {
/**
* Stores data in a SharedArrayBuffer
*/
export interface Sized {
/**
* Size in bytes that class requires
*/
readonly sizeof: number;
}
}
declare module "Mutex" {
import { Sized } from "Sized";
/**
* Binary mutex that protects a SharedArrayBuffer
*/
export class Mutex implements Sized {
private state;
private isOwner;
/**
* Construct a view of a mutex in a buffer
* @param buff to store mutex in
* @param offset into buff to store mutex
*/
constructor(buff: SharedArrayBuffer, offset: number);
/**
* Initializes the mutex to be unlocked
* This function doesn't need to be called if the SharedArrayBuffer
* being used is zero'd
*/
init(): void;
/**
* Obtain the lock, blocks until lock is acquired
* Cannot be called on main thread
*/
lock(): void;
/**
* Release the lock
* @throws err if thread does not hold the lock
*/
unlock(): void;
/**
* Attempt to acquire the lock, but returns immediately if lock cannot be obtained
* @returns whether lock was aqcuired
*/
tryLock(): boolean;
static readonly sizeof = 4;
readonly sizeof = 4;
}
}
declare module "Semaphore" {
import { Sized } from "Sized";
/**
* Counting semaphore
*/
export class Semaphore implements Sized {
private counter;
private mutex;
constructor(buff: SharedArrayBuffer, offset: number);
/**
* Initialize the semaphore's counter
* @param value set semaphore as
*/
init(value: number): void;
/**
* Decrement the counter and block if the counter is < 1
*/
wait(): void;
/**
* Decrement the counter if it is > 0 and return true
* otherwise return false
* Does not block
* @returns whether counter was decremented
*/
tryWait(): boolean;
/**
* Increment the counter, wake up any waiting threads
*/
post(): void;
static readonly sizeof: number;
readonly sizeof: number;
}
}
declare module "main" {
export * from "Mutex";
export * from "Semaphore";
}