Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
ParaEncode
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ParaEncode
Commits
50ffd1cc
Commit
50ffd1cc
authored
Apr 25, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Channel.
parent
fac579ca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
45 deletions
+42
-45
karma.conf.js
karma.conf.js
+1
-1
channel.js
src/channel.js
+33
-36
WWGroup.spec.js
tests/WWGroup.spec.js
+8
-7
channelWW.js
tests/workers/channelWW.js
+0
-1
No files found.
karma.conf.js
View file @
50ffd1cc
...
...
@@ -82,7 +82,7 @@ module.exports = function(config) {
// start these browsers
// available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher
browsers
:
[
'ChromeHeadless'
],
//
browsers: ['ChromeHeadless'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
...
...
src/channel.js
View file @
50ffd1cc
...
...
@@ -41,8 +41,8 @@ export class Channel {
#
view
=
undefined
;
#
buffer
=
undefined
;
#
write
Val
Cache
=
0
;
#
read
Val
Cache
=
0
;
#
write
Pointer
Cache
=
0
;
#
read
Pointer
Cache
=
0
;
#
endPos
=
0
;
// size's unit is byte
...
...
@@ -59,16 +59,16 @@ export class Channel {
this
.
#
shMem
=
new
bufferType
(
size
+
this
.
#
metaSize
);
this
.
#
view
=
new
DataView
(
this
.
#
shMem
);
this
.
#
buffer
=
new
Uint8Array
(
this
.
#
shMem
);
this
.
#
write
Val
Cache
=
this
.
#
metaSize
;
this
.
#
read
Val
Cache
=
this
.
#
metaSize
;
this
.
#
write
Pointer
Cache
=
this
.
#
metaSize
;
this
.
#
read
Pointer
Cache
=
this
.
#
metaSize
;
this
.
#
size
=
size
;
this
.
#
totalSize
=
this
.
#
metaSize
+
this
.
#
size
;
this
.
#
endPos
=
this
.
#
metaSize
+
this
.
#
size
;
// Init readPointer and writePointer to
// the first bytes of data area.
this
.
#
view
.
setUint32
(
0
,
this
.
#
write
Val
Cache
);
this
.
#
view
.
setUint32
(
4
,
this
.
#
read
Val
Cache
);
this
.
#
view
.
setUint32
(
0
,
this
.
#
write
Pointer
Cache
);
this
.
#
view
.
setUint32
(
4
,
this
.
#
read
Pointer
Cache
);
}
#
getReadPointer
()
{
...
...
@@ -97,7 +97,6 @@ export class Channel {
for
(
let
i
=
8
;
i
<
12
;
++
i
)
{
this
.
#
view
.
setUint8
(
i
);
}
}
/* Semantic: Is able to write 'size' of datas
...
...
@@ -111,14 +110,14 @@ export class Channel {
}
#
remain
()
{
let
readPos
=
this
.
#
r
eadPointer
();
let
readPos
=
this
.
#
getR
eadPointer
();
if
(
this
.
#
writePo
s
==
readPos
)
{
if
(
this
.
#
writePo
interCache
==
readPos
)
{
return
this
.
#
size
-
1
;
}
else
if
(
this
.
#
writePo
s
>
readPos
)
{
return
this
.
#
size
-
(
this
.
#
writePo
s
-
readPos
)
-
1
;
}
else
if
(
this
.
#
writePo
interCache
>
readPos
)
{
return
this
.
#
size
-
(
this
.
#
writePo
interCache
-
readPos
)
-
1
;
}
else
{
return
readPos
-
this
.
#
writePo
s
-
1
;
return
readPos
-
this
.
#
writePo
interCache
-
1
;
}
}
...
...
@@ -133,22 +132,21 @@ export class Channel {
#
cpySchedule
(
size
)
{
let
firstCpySize
=
0
,
secondCpySize
=
0
,
spaceToTail
=
0
;
let
schedule
=
new
CpySchedule
();
let
readPos
=
this
.
#
readPos
();
let
readPos
=
this
.
#
getReadPointer
();
if
(
this
.
#
writePo
s
>=
readPos
)
{
spaceToTail
=
this
.
#
endPos
-
this
.
#
writePo
s
;
if
(
this
.
#
writePo
interCache
>=
readPos
)
{
spaceToTail
=
this
.
#
endPos
-
this
.
#
writePo
interCache
;
firstCpySize
=
Math
.
min
(
size
,
spaceToTail
);
secondCpySize
=
firstCpySize
<
size
?
size
-
firstCpySize
:
0
;
secondCpySize
=
Math
.
min
(
secondCpySize
,
readPos
-
this
.
#
metaSize
);
schedule
.
first
.
pos
=
this
.
#
writePo
s
;
schedule
.
first
.
pos
=
this
.
#
writePo
interCache
;
schedule
.
first
.
size
=
firstCpySize
;
schedule
.
second
.
pos
=
secondCpySize
>
0
?
this
.
#
metaSize
:
0
;
schedule
.
second
.
size
=
secondCpySize
;
}
else
{
schedule
.
first
.
pos
=
this
.
#
writePo
s
;
schedule
.
first
.
size
=
Math
.
min
(
readPos
-
this
.
#
writePo
s
-
1
,
size
);
schedule
.
first
.
pos
=
this
.
#
writePo
interCache
;
schedule
.
first
.
size
=
Math
.
min
(
readPos
-
this
.
#
writePo
interCache
-
1
,
size
);
}
return
schedule
;
...
...
@@ -159,24 +157,23 @@ export class Channel {
}
isEmpty
()
{
return
this
.
#
writePo
s
==
this
.
#
readPos
()
;
return
this
.
#
writePo
interCache
==
this
.
#
readPointerCache
;
}
// This method is for testing purposes.
readData
(
size
)
{
let
writePos
=
this
.
#
writePos
();
let
writePos
=
this
.
#
getWritePointer
();
let
readTo
=
0
,
readBuffer
=
null
;
if
(
this
.
#
readPos
==
writePos
)
{
if
(
this
.
#
readPointerCache
==
writePos
)
{
return
new
Uint8Array
(
0
);
}
else
if
(
this
.
#
readPo
s
<
writePos
)
{
readTo
=
this
.
#
readPo
s
+
Math
.
min
(
size
,
writePos
-
this
.
#
readPos
);
readBuffer
=
this
.
#
buffer
.
slice
(
this
.
#
readPo
s
,
readTo
);
this
.
#
readPo
s
Update
(
readTo
);
}
else
if
(
this
.
#
readPo
interCache
<
writePos
)
{
readTo
=
this
.
#
readPo
interCache
+
Math
.
min
(
size
,
writePos
-
this
.
#
readPointerCache
);
readBuffer
=
this
.
#
buffer
.
slice
(
this
.
#
readPo
interCache
,
readTo
);
this
.
#
readPo
inter
Update
(
readTo
);
}
else
{
// Read two times
let
firstRSize
=
Math
.
min
(
size
,
this
.
#
buffer
.
byteLength
-
this
.
#
readPo
s
);
let
firstRSize
=
Math
.
min
(
size
,
this
.
#
buffer
.
byteLength
-
this
.
#
readPo
interCache
);
let
secondRSize
=
firstRSize
<
size
?
size
-
firstRSize
:
0
;
secondRSize
=
Math
.
min
(
secondRSize
,
writePos
-
this
.
#
metaSize
);
...
...
@@ -184,18 +181,18 @@ export class Channel {
// First read
readBuffer
.
set
(
this
.
#
buffer
.
slice
(
this
.
#
readPo
s
,
this
.
#
readPos
+
firstRSize
),
0
);
this
.
#
readPo
interCache
,
this
.
#
readPointerCache
+
firstRSize
),
0
);
// Second Read
if
(
secondRSize
>
0
)
{
readBuffer
.
set
(
this
.
#
buffer
.
slice
(
this
.
#
metaSize
,
this
.
#
metaSize
+
secondRSize
),
firstRSize
);
this
.
#
readPo
s
Update
(
this
.
#
metaSize
+
secondRSize
);
this
.
#
readPo
inter
Update
(
this
.
#
metaSize
+
secondRSize
);
}
else
{
let
newPos
=
this
.
#
readPo
s
+
firstRSize
;
let
newPos
=
this
.
#
readPo
interCache
+
firstRSize
;
newPos
=
newPos
==
this
.
#
buffer
.
byteLength
?
this
.
#
metaSize
:
newPos
;
this
.
#
readPo
s
Update
(
newPos
);
this
.
#
readPo
inter
Update
(
newPos
);
}
}
...
...
@@ -204,7 +201,7 @@ export class Channel {
push
(
data
/* Uint8Array */
)
{
let
writePos
=
this
.
#
writePo
s
;
let
writePos
=
this
.
#
writePo
interCache
;
if
(
!
this
.
#
isAbleToWrite
(
data
.
byteLength
))
{
return
false
;
...
...
@@ -235,18 +232,18 @@ export class Channel {
// all datas are writed but not before or
// at intermediate of some writes otherwise
// oppsite side may read invalid datas.
this
.
#
writePo
s
Update
(
writePos
);
this
.
#
writePo
inter
Update
(
writePos
);
return
true
;
}
#
writePointerUpdate
(
pos
)
{
this
.
#
writePo
s
=
pos
;
this
.
#
writePo
interCache
=
pos
;
this
.
#
view
.
setUint32
(
4
,
pos
);
}
#
readPointerUpdate
(
pos
)
{
this
.
#
readPo
s
=
pos
;
this
.
#
readPo
interCache
=
pos
;
this
.
#
view
.
setUint32
(
0
,
pos
);
}
}
tests/WWGroup.spec.js
View file @
50ffd1cc
...
...
@@ -131,7 +131,7 @@ describe("Channel Spec", () => {
it
(
"Transfer 64 MB to WebWorker"
,
async
()
=>
{
let
url
=
new
URL
(
'./workers/channelWW.js'
,
import
.
meta
.
url
),
ret
=
true
;
let
channel
=
new
Channel
(
Math
.
pow
(
2
,
2
0
));
let
channel
=
new
Channel
(
Math
.
pow
(
2
,
1
0
));
let
worker
=
new
Worker
(
url
,
{
type
:
'module'
});
let
sended
=
0
;
...
...
@@ -139,9 +139,9 @@ describe("Channel Spec", () => {
[...
Array
(
getRandomInt
(
Math
.
pow
(
2
,
10
))).
keys
()]);
let
cur
=
0
;
let
size
=
Math
.
pow
(
2
,
26
);
let
rBuffer
=
new
Uint8Array
(
Math
.
pow
(
2
,
27
));
let
sBuffer
=
new
Uint8Array
(
Math
.
pow
(
2
,
27
));
let
size
=
Math
.
pow
(
2
,
15
);
let
rBuffer
=
new
Uint8Array
(
Math
.
pow
(
2
,
16
));
let
sBuffer
=
new
Uint8Array
(
Math
.
pow
(
2
,
16
));
worker
.
postMessage
(
channel
.
getShMem
());
...
...
@@ -159,7 +159,7 @@ describe("Channel Spec", () => {
ret
=
channel
.
push
(
dataToWrite
);
if
(
ret
==
false
)
{
await
sleep
(
10
0
);
await
sleep
(
10
);
continue
;
}
else
{
sBuffer
.
set
(
dataToWrite
,
sended
);
...
...
@@ -174,16 +174,17 @@ describe("Channel Spec", () => {
// Wait for Web Worker
await
new
Promise
(
r
=>
{
setInterval
(()
=>
{
console
.
log
(
cur
,
sended
);
if
(
cur
==
sended
)
{
r
();
}
},
10
);
},
100000
0
);
},
100000
);
worker
.
terminate
();
expect
(
areEqual
(
rBuffer
,
sBuffer
)).
toBe
(
true
);
},
10000
);
},
10000
0
);
});
...
...
tests/workers/channelWW.js
View file @
50ffd1cc
...
...
@@ -49,7 +49,6 @@ class ChannelReader {
let
writePos
=
this
.
#
writePos
();
let
readTo
=
0
,
readBuffer
=
null
;
if
(
this
.
#
readPos
==
writePos
)
{
return
new
Uint8Array
(
0
);
}
else
if
(
this
.
#
readPos
<
writePos
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment