-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathThreadBridge.ts
More file actions
142 lines (108 loc) · 2.51 KB
/
Copy pathThreadBridge.ts
File metadata and controls
142 lines (108 loc) · 2.51 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { sharedWash } from "./Output"
export interface Runnable{
className: string;
run(): void;
}
export class Thread implements Runnable{
private runnableShared: Runnable;
public className: string = "Thread";
static getThreadOwn(myClass: Runnable): Runnable{
return myClass;
}
public async start(){
// if (isMainThread()) {
// await taskpool.execute(runThread, this.runnableShared);
// }
}
public run() {}
constructor(runnableShared: Runnable | null = null) {
if(runnableShared !== null){
this.runnableShared = runnableShared;
}
else{
this.runnableShared = Thread.getThreadOwn(this);
}
}
}
function runThread(runnable: Runnable) {
sharedWash(runnable);
}
export function isMainThread(): boolean {
// return process.pid == process.tid;
return true
}
export class SharedBoolean{
private sharedArray: Uint8Array = new Uint8Array([]);
constructor(b ?: boolean) {
this.sharedArray[0] = 0;
if(b !== undefined){
if(b === true){
this.sharedArray[0] = 1;
}
}
}
public setValue(b: boolean) {
if(b === true){
this.sharedArray[0] = 1;
}
else {
this.sharedArray[0] = 0;
}
}
public getValue(): boolean {
if (this.sharedArray[0] == 0) {
return false;
}
return true;
}
}
export class SharedString {
private sharedArray: Uint8Array = new Uint8Array([]);
constructor(s ?: string) {
if (s !== undefined){
this.setValue(s);
}
}
public setValue(s: string) {
}
public getValue() {
let receivedString = "";
for(let i = 0; i < this.sharedArray.length && this.sharedArray[i] !== 0; i++){
receivedString += String.fromCharCode(this.sharedArray[i]);
}
return receivedString;
}
}
export class SharedNumber {
private sharedArray: Float64Array = new Float64Array([]);
constructor(n ?: number) {
this.sharedArray[0] = 0;
if(n !== undefined){
this.sharedArray[0] = n;
}
}
public setValue(n: number) {
this.sharedArray[0] = n;
}
public getValue(): number {
return this.sharedArray[0];
}
}
export class Syc {
public synArray: Int32Array = new Int32Array([]);
public wnSynArray: Int32Array = new Int32Array([]);
constructor() {
this.synArray[0] = 1;
this.wnSynArray[0] = 0;
}
}
export function SynStart(syc: Syc){
}
export function SynEnd(syc: Syc){
}
export function wait(syc: Syc){
}
export function notify(syc: Syc){
}
export function addFunc(runnableShared: object, archetype: object){
}