Commit df4875cc authored by NzSN's avatar NzSN

update

parent ec7e8502
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
"karma-jasmine": "^5.0.0", "karma-jasmine": "^5.0.0",
"watchify": "^4.0.0", "watchify": "^4.0.0",
"webpack": "^5.72.0", "webpack": "^5.72.0",
"webpack-cli": "^4.9.2", "webpack-cli": "^4.9.2"
"worker-loader": "^3.0.8"
}, },
"scripts": { "scripts": {
"test": "karma start" "test": "karma start"
......
...@@ -42,13 +42,16 @@ export class Channel { ...@@ -42,13 +42,16 @@ export class Channel {
* 2.Read Position * 2.Read Position
* *
* Figure: * 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 * where N >= 2
* *
* */ * */
#numOfMetaField = 2 #rFieldPosLen = 4;
#wFieldPosLen = 4;
#priFieldLen = 4;
#numOfMetaField = 3
#fieldSize = 0; #fieldSize = 0;
#metaSize = 0; #metaSize = 0;
...@@ -73,9 +76,8 @@ export class Channel { ...@@ -73,9 +76,8 @@ export class Channel {
this.#WW = WW; this.#WW = WW;
this.#size = size; this.#size = size;
// 4 Bytes // Init shared memory
this.#fieldSize = 4; this.#metaSize = this.#rFieldPosLen + this.#wFieldPosLen + this.#priFieldLen;
this.#metaSize = this.#numOfMetaField * this.#fieldSize;
this.#shMem = new bufferType(size + this.#metaSize); this.#shMem = new bufferType(size + this.#metaSize);
this.#view = new DataView(this.#shMem); this.#view = new DataView(this.#shMem);
this.#buffer = new Uint8Array(this.#shMem); this.#buffer = new Uint8Array(this.#shMem);
...@@ -84,6 +86,8 @@ export class Channel { ...@@ -84,6 +86,8 @@ export class Channel {
this.#totalSize = this.#metaSize + this.#size; this.#totalSize = this.#metaSize + this.#size;
this.#endPos = 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(0, this.#metaSize);
this.#view.setUint32(4, this.#metaSize); this.#view.setUint32(4, this.#metaSize);
} }
...@@ -92,6 +96,27 @@ export class Channel { ...@@ -92,6 +96,27 @@ export class Channel {
return this.#view.getUint32(0); 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 /* Semantic: Is able to write 'size' of datas
* into #shMem. */ * into #shMem. */
#isAbleToWrite(size) { #isAbleToWrite(size) {
......
import { WW } from '../src/WW.js'; import { WW } from '../src/WW.js';
import '../src/res.js';
// For Webpack 5 // For Webpack 5
let url = new URL('../resources/worker.js', import.meta.url); let url = new URL('../resources/worker.js', import.meta.url);
......
...@@ -14,9 +14,10 @@ module.exports = { ...@@ -14,9 +14,10 @@ module.exports = {
{ {
test: /\.(js|jsx)$/, test: /\.(js|jsx)$/,
exclude: /node_modules/, exclude: /node_modules/,
use: { use: ['babel-loader']
loader: "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