Commit df4875cc authored by NzSN's avatar NzSN

update

parent ec7e8502
......@@ -20,8 +20,7 @@
"karma-jasmine": "^5.0.0",
"watchify": "^4.0.0",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"worker-loader": "^3.0.8"
"webpack-cli": "^4.9.2"
},
"scripts": {
"test": "karma start"
......
......@@ -42,13 +42,16 @@ export class Channel {
* 2.Read Position
*
* Figure:
* ------------------------------------------------------------------------
* | ReadPointer (4 bytes) | WritePointer (4 Bytes) | Data Area (N bytes) |
* -------------------------------------------------------------------------
* --------------------------------------------------------------------------------------------
* | ReadPointer (4 bytes) | WritePointer (4 Bytes) | Private (4 Bytes) | Data Area (N bytes) |
* --------------------------------------------------------------------------------------------
* where N >= 2
*
* */
#numOfMetaField = 2
#rFieldPosLen = 4;
#wFieldPosLen = 4;
#priFieldLen = 4;
#numOfMetaField = 3
#fieldSize = 0;
#metaSize = 0;
......@@ -73,9 +76,8 @@ export class Channel {
this.#WW = WW;
this.#size = size;
// 4 Bytes
this.#fieldSize = 4;
this.#metaSize = this.#numOfMetaField * this.#fieldSize;
// Init shared memory
this.#metaSize = this.#rFieldPosLen + this.#wFieldPosLen + this.#priFieldLen;
this.#shMem = new bufferType(size + this.#metaSize);
this.#view = new DataView(this.#shMem);
this.#buffer = new Uint8Array(this.#shMem);
......@@ -84,6 +86,8 @@ export class Channel {
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.#metaSize);
this.#view.setUint32(4, this.#metaSize);
}
......@@ -92,6 +96,27 @@ export class Channel {
return this.#view.getUint32(0);
}
readPriv() {
return [
this.#view.getUint8(8),
this.#view.getUint8(9),
this.#view.getUint8(10),
this.#view.getUint8(11),
];
}
writePriv(privData) {
if (!(privData instanceof Array) ||
privData.length > this.#priFieldLen) {
throw new Error("Invalid Private datas");
}
for (let i = 8; i < 12; ++i) {
this.#view.setUint8(i);
}
}
/* Semantic: Is able to write 'size' of datas
* into #shMem. */
#isAbleToWrite(size) {
......
import { WW } from '../src/WW.js';
import '../src/res.js';
// For Webpack 5
let url = new URL('../resources/worker.js', import.meta.url);
......
......@@ -14,9 +14,10 @@ module.exports = {
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
use: ['babel-loader']
},
{
}
]
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment