@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/api.js +4 -2
- package/build.env +1 -1
- package/moddable/modules/data/base64/base64.js +28 -0
- package/moddable/modules/data/base64/manifest.json +11 -0
- package/moddable/modules/data/base64/modBase64.c +188 -0
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
- package/moddable/modules/data/crc/crc.c +205 -0
- package/moddable/modules/data/crc/crc.js +36 -0
- package/moddable/modules/data/crc/manifest.json +8 -0
- package/moddable/modules/data/hex/hex.js +28 -0
- package/moddable/modules/data/hex/manifest.json +11 -0
- package/moddable/modules/data/hex/modHex.c +139 -0
- package/moddable/modules/data/logical/logical.js +32 -0
- package/moddable/modules/data/logical/modLogical.c +98 -0
- package/moddable/modules/data/qrcode/manifest.json +9 -0
- package/moddable/modules/data/qrcode/qrcode.c +93 -0
- package/moddable/modules/data/qrcode/qrcode.js +23 -0
- package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
- package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
- package/moddable/modules/data/text/decoder/manifest.json +8 -0
- package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
- package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
- package/moddable/modules/data/text/encoder/manifest.json +8 -0
- package/moddable/modules/data/text/encoder/textencoder.c +232 -0
- package/moddable/modules/data/text/encoder/textencoder.js +24 -0
- package/moddable/modules/data/tinyint/tinyint.c +150 -0
- package/moddable/modules/data/tinyint/tinyint.js +53 -0
- package/moddable/modules/data/url/manifest.json +17 -0
- package/moddable/modules/data/url/url.c +1959 -0
- package/moddable/modules/data/url/url.js +210 -0
- package/moddable/modules/data/wavreader/manifest.json +8 -0
- package/moddable/modules/data/wavreader/wavreader.js +128 -0
- package/moddable/modules/data/zlib/deflate.c +161 -0
- package/moddable/modules/data/zlib/deflate.js +63 -0
- package/moddable/modules/data/zlib/inflate.c +145 -0
- package/moddable/modules/data/zlib/inflate.js +66 -0
- package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
- package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
- package/moddable/modules/data/zlib/miniz.c +4924 -0
- package/moddable/xs/includes/xs.d.ts +73 -0
- package/moddable/xs/includes/xs.h +1533 -0
- package/moddable/xs/includes/xsmc.h +206 -0
- package/moddable/xs/makefiles/lin/makefile +33 -0
- package/moddable/xs/makefiles/lin/xsc.mk +118 -0
- package/moddable/xs/makefiles/lin/xsid.mk +90 -0
- package/moddable/xs/makefiles/lin/xsl.mk +168 -0
- package/moddable/xs/makefiles/lin/xst.mk +201 -0
- package/moddable/xs/makefiles/mac/makefile +33 -0
- package/moddable/xs/makefiles/mac/xsc.mk +130 -0
- package/moddable/xs/makefiles/mac/xsid.mk +102 -0
- package/moddable/xs/makefiles/mac/xsl.mk +177 -0
- package/moddable/xs/makefiles/mac/xst.mk +203 -0
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
- package/moddable/xs/makefiles/win/build.bat +26 -0
- package/moddable/xs/makefiles/win/xsc.mak +142 -0
- package/moddable/xs/makefiles/win/xsid.mak +113 -0
- package/moddable/xs/makefiles/win/xsl.mak +186 -0
- package/moddable/xs/makefiles/win/xst.mak +195 -0
- package/moddable/xs/platforms/lin_xs.h +99 -0
- package/moddable/xs/platforms/mac_xs.h +97 -0
- package/moddable/xs/platforms/wasm_xs.h +79 -0
- package/moddable/xs/platforms/win_xs.h +104 -0
- package/moddable/xs/platforms/xsHost.h +63 -0
- package/moddable/xs/platforms/xsPlatform.h +618 -0
- package/moddable/xs/sources/xsAPI.c +2555 -0
- package/moddable/xs/sources/xsAll.c +294 -0
- package/moddable/xs/sources/xsAll.h +2741 -0
- package/moddable/xs/sources/xsArguments.c +222 -0
- package/moddable/xs/sources/xsArray.c +2657 -0
- package/moddable/xs/sources/xsAtomics.c +844 -0
- package/moddable/xs/sources/xsBigInt.c +1859 -0
- package/moddable/xs/sources/xsBoolean.c +109 -0
- package/moddable/xs/sources/xsCode.c +4493 -0
- package/moddable/xs/sources/xsCommon.c +1710 -0
- package/moddable/xs/sources/xsCommon.h +1142 -0
- package/moddable/xs/sources/xsDataView.c +2890 -0
- package/moddable/xs/sources/xsDate.c +1541 -0
- package/moddable/xs/sources/xsDebug.c +2710 -0
- package/moddable/xs/sources/xsDefaults.c +134 -0
- package/moddable/xs/sources/xsError.c +353 -0
- package/moddable/xs/sources/xsFunction.c +776 -0
- package/moddable/xs/sources/xsGenerator.c +865 -0
- package/moddable/xs/sources/xsGlobal.c +839 -0
- package/moddable/xs/sources/xsJSON.c +1091 -0
- package/moddable/xs/sources/xsLexical.c +1969 -0
- package/moddable/xs/sources/xsLockdown.c +933 -0
- package/moddable/xs/sources/xsMapSet.c +1649 -0
- package/moddable/xs/sources/xsMarshall.c +1020 -0
- package/moddable/xs/sources/xsMath.c +624 -0
- package/moddable/xs/sources/xsMemory.c +1941 -0
- package/moddable/xs/sources/xsModule.c +3101 -0
- package/moddable/xs/sources/xsNumber.c +560 -0
- package/moddable/xs/sources/xsObject.c +1102 -0
- package/moddable/xs/sources/xsPlatforms.c +480 -0
- package/moddable/xs/sources/xsProfile.c +577 -0
- package/moddable/xs/sources/xsPromise.c +1199 -0
- package/moddable/xs/sources/xsProperty.c +636 -0
- package/moddable/xs/sources/xsProxy.c +1014 -0
- package/moddable/xs/sources/xsRegExp.c +1168 -0
- package/moddable/xs/sources/xsRun.c +4889 -0
- package/moddable/xs/sources/xsScope.c +1293 -0
- package/moddable/xs/sources/xsScript.c +288 -0
- package/moddable/xs/sources/xsScript.h +1186 -0
- package/moddable/xs/sources/xsSnapshot.c +2161 -0
- package/moddable/xs/sources/xsSnapshot.h +51 -0
- package/moddable/xs/sources/xsSourceMap.c +218 -0
- package/moddable/xs/sources/xsString.c +3332 -0
- package/moddable/xs/sources/xsSymbol.c +503 -0
- package/moddable/xs/sources/xsSyntaxical.c +4193 -0
- package/moddable/xs/sources/xsTree.c +1893 -0
- package/moddable/xs/sources/xsType.c +1488 -0
- package/moddable/xs/sources/xsdtoa.c +6672 -0
- package/moddable/xs/sources/xsmc.c +340 -0
- package/moddable/xs/sources/xsre.c +7578 -0
- package/package.json +37 -20
- package/scripts/get_xsnap_version.sh +14 -0
- package/scripts/test-package.sh +21 -0
- package/src/avaAssertXS.js +6 -2
- package/src/avaHandler.cjs +2 -5
- package/src/avaXS.js +7 -8
- package/src/build.js +161 -28
- package/src/replay.js +0 -3
- package/src/xsnap.js +105 -91
- package/src/xsrepl.js +2 -3
- package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
- package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
- package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
- package/xsnap-native/xsnap/sources/xsnap.c +717 -0
- package/xsnap-native/xsnap/sources/xsnap.h +142 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
- package/CHANGELOG.md +0 -654
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-2017 Moddable Tech, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the Moddable SDK Runtime.
|
|
5
|
+
*
|
|
6
|
+
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU Lesser General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include "xsAll.h"
|
|
22
|
+
|
|
23
|
+
static txInteger fxCheckAtomicsIndex(txMachine* the, txInteger index, txInteger length);
|
|
24
|
+
static txSlot* fxCheckAtomicsTypedArray(txMachine* the, txBoolean onlyInt32);
|
|
25
|
+
static txSlot* fxCheckAtomicsArrayBuffer(txMachine* the, txSlot* slot, txBoolean onlyShared);
|
|
26
|
+
static void* fxCheckAtomicsArrayBufferDetached(txMachine* the, txSlot* slot, txBoolean mutable);
|
|
27
|
+
static txSlot* fxCheckSharedArrayBuffer(txMachine* the, txSlot* slot, txString which);
|
|
28
|
+
static void fxPushAtomicsValue(txMachine* the, int i, txID id);
|
|
29
|
+
|
|
30
|
+
#define mxAtomicsHead0(TYPE,TO) \
|
|
31
|
+
TYPE result = 0; \
|
|
32
|
+
txBoolean lock = host->kind == XS_HOST_KIND; \
|
|
33
|
+
void* data = (lock) ? host->value.host.data : fxCheckAtomicsArrayBufferDetached(the, host, XS_IMMUTABLE); \
|
|
34
|
+
TYPE* address = (TYPE*)(((txByte*)data) + offset)
|
|
35
|
+
|
|
36
|
+
#define mxAtomicsHead1(TYPE,TO) \
|
|
37
|
+
TYPE result = 0; \
|
|
38
|
+
TYPE value = (TYPE)TO(the, slot); \
|
|
39
|
+
txBoolean lock = host->kind == XS_HOST_KIND; \
|
|
40
|
+
void* data = (lock) ? host->value.host.data : fxCheckAtomicsArrayBufferDetached(the, host, XS_MUTABLE); \
|
|
41
|
+
TYPE* address = (TYPE*)(((txByte*)data) + offset)
|
|
42
|
+
|
|
43
|
+
#define mxAtomicsHead2(TYPE,TO) \
|
|
44
|
+
TYPE result = (TYPE)TO(the, slot + 1); \
|
|
45
|
+
TYPE value = (TYPE)TO(the, slot); \
|
|
46
|
+
txBoolean lock = host->kind == XS_HOST_KIND; \
|
|
47
|
+
void* data = (lock) ? host->value.host.data : fxCheckAtomicsArrayBufferDetached(the, host, XS_MUTABLE); \
|
|
48
|
+
TYPE* address = (TYPE*)(((txByte*)data) + offset)
|
|
49
|
+
|
|
50
|
+
#ifdef mxUseGCCAtomics
|
|
51
|
+
#define mxAtomicsCompareExchange() __atomic_compare_exchange(address, &result, &value, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
|
|
52
|
+
#define mxAtomicsLoad() __atomic_load(address, &result, __ATOMIC_SEQ_CST)
|
|
53
|
+
#define mxAtomicsAdd() result = __atomic_fetch_add(address, value, __ATOMIC_SEQ_CST)
|
|
54
|
+
#define mxAtomicsAnd() result = __atomic_fetch_and(address, value, __ATOMIC_SEQ_CST)
|
|
55
|
+
#define mxAtomicsExchange() __atomic_exchange(address, &value, &result, __ATOMIC_SEQ_CST)
|
|
56
|
+
#define mxAtomicsOr() result = __atomic_fetch_or(address, value, __ATOMIC_SEQ_CST)
|
|
57
|
+
#define mxAtomicsStore() __atomic_store(address, &value, __ATOMIC_SEQ_CST)
|
|
58
|
+
#define mxAtomicsSub() result = __atomic_fetch_sub(address, value, __ATOMIC_SEQ_CST)
|
|
59
|
+
#define mxAtomicsXor() result = __atomic_fetch_xor(address, value, __ATOMIC_SEQ_CST)
|
|
60
|
+
#else
|
|
61
|
+
#define mxAtomicsCompareExchange() if (lock) fxLockSharedChunk(data); if (*address == result) *address = value; else result = *address; if (lock) fxUnlockSharedChunk(data)
|
|
62
|
+
#define mxAtomicsLoad() if (lock) fxLockSharedChunk(data); result = *address; if (lock) fxUnlockSharedChunk(data)
|
|
63
|
+
#define mxAtomicsAdd() if (lock) fxLockSharedChunk(data); result = *address; *address = result + value; if (lock) fxUnlockSharedChunk(data)
|
|
64
|
+
#define mxAtomicsAnd() if (lock) fxLockSharedChunk(data); result = *address; *address = result & value; if (lock) fxUnlockSharedChunk(data)
|
|
65
|
+
#define mxAtomicsExchange() if (lock) fxLockSharedChunk(data); result = *address; *address = value; if (lock) fxUnlockSharedChunk(data)
|
|
66
|
+
#define mxAtomicsOr() if (lock) fxLockSharedChunk(data); result = *address; *address = result | value; if (lock) fxUnlockSharedChunk(data)
|
|
67
|
+
#define mxAtomicsStore() if (lock) fxLockSharedChunk(data); *address = value; if (lock) fxUnlockSharedChunk(data)
|
|
68
|
+
#define mxAtomicsSub() if (lock) fxLockSharedChunk(data); result = *address; *address = result - value; if (lock) fxUnlockSharedChunk(data)
|
|
69
|
+
#define mxAtomicsXor() if (lock) fxLockSharedChunk(data); result = *address; *address = result ^ value; if (lock) fxUnlockSharedChunk(data)
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
#define mxAtomicsTail() \
|
|
73
|
+
slot->kind = XS_INTEGER_KIND; \
|
|
74
|
+
slot->value.integer = result
|
|
75
|
+
|
|
76
|
+
#define mxAtomicsTailBigInt64() \
|
|
77
|
+
fxFromBigInt64(the, slot, result)
|
|
78
|
+
|
|
79
|
+
#define mxAtomicsTailBigUint64() \
|
|
80
|
+
fxFromBigUint64(the, slot, result)
|
|
81
|
+
|
|
82
|
+
#define mxAtomicsTailOverflow() \
|
|
83
|
+
if (result <= 0x7FFFFFFF) { \
|
|
84
|
+
slot->kind = XS_INTEGER_KIND; \
|
|
85
|
+
slot->value.integer = result; \
|
|
86
|
+
} \
|
|
87
|
+
else { \
|
|
88
|
+
slot->kind = XS_NUMBER_KIND; \
|
|
89
|
+
slot->value.number = result; \
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#define mxAtomicsTailWait() \
|
|
93
|
+
return (result != value) ? -1 : fxWaitSharedChunk(the, address, timeout)
|
|
94
|
+
|
|
95
|
+
#define mxAtomicsDeclarations(onlyInt32, onlyShared) \
|
|
96
|
+
txSlot* dispatch = fxCheckAtomicsTypedArray(the, onlyInt32); \
|
|
97
|
+
txSlot* view = dispatch->next; \
|
|
98
|
+
txSlot* buffer = view->next; \
|
|
99
|
+
txSlot* host = fxCheckAtomicsArrayBuffer(the, buffer, onlyShared); \
|
|
100
|
+
txU2 shift = dispatch->value.typedArray.dispatch->shift; \
|
|
101
|
+
txInteger index = fxCheckAtomicsIndex(the, 1, fxGetDataViewSize(the, view, buffer) >> shift); \
|
|
102
|
+
txInteger offset = view->value.dataView.offset + (index << shift)
|
|
103
|
+
|
|
104
|
+
void fxInt8Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsAdd(); mxAtomicsTail(); }
|
|
105
|
+
void fxInt16Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsAdd(); mxAtomicsTail(); }
|
|
106
|
+
void fxInt32Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsAdd(); mxAtomicsTail(); }
|
|
107
|
+
void fxInt64Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsAdd(); mxAtomicsTailBigInt64(); }
|
|
108
|
+
void fxUint8Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsAdd(); mxAtomicsTail(); }
|
|
109
|
+
void fxUint16Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsAdd(); mxAtomicsTail(); }
|
|
110
|
+
void fxUint32Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsAdd(); mxAtomicsTailOverflow(); }
|
|
111
|
+
void fxUint64Add(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsAdd(); mxAtomicsTailBigUint64(); }
|
|
112
|
+
|
|
113
|
+
void fxInt8And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsAnd(); mxAtomicsTail(); }
|
|
114
|
+
void fxInt16And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsAnd(); mxAtomicsTail(); }
|
|
115
|
+
void fxInt32And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsAnd(); mxAtomicsTail(); }
|
|
116
|
+
void fxInt64And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsAnd(); mxAtomicsTailBigInt64(); }
|
|
117
|
+
void fxUint8And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsAnd(); mxAtomicsTail(); }
|
|
118
|
+
void fxUint16And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsAnd(); mxAtomicsTail(); }
|
|
119
|
+
void fxUint32And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsAnd(); mxAtomicsTailOverflow(); }
|
|
120
|
+
void fxUint64And(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsAnd(); mxAtomicsTailBigUint64(); }
|
|
121
|
+
|
|
122
|
+
void fxInt8CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txS1, fxToInteger); mxAtomicsCompareExchange(); mxAtomicsTail(); }
|
|
123
|
+
void fxInt16CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txS2, fxToInteger); mxAtomicsCompareExchange(); mxAtomicsTail(); }
|
|
124
|
+
void fxInt32CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txS4, fxToInteger); mxAtomicsCompareExchange(); mxAtomicsTail(); }
|
|
125
|
+
void fxInt64CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txS8, fxToBigInt64); mxAtomicsCompareExchange(); mxAtomicsTailBigInt64(); }
|
|
126
|
+
void fxUint8CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txU1, fxToUnsigned); mxAtomicsCompareExchange(); mxAtomicsTail(); }
|
|
127
|
+
void fxUint16CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txU2, fxToUnsigned); mxAtomicsCompareExchange(); mxAtomicsTail(); }
|
|
128
|
+
void fxUint32CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txU4, fxToUnsigned); mxAtomicsCompareExchange(); mxAtomicsTailOverflow(); }
|
|
129
|
+
void fxUint64CompareExchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead2(txU8, fxToBigUint64); mxAtomicsCompareExchange(); mxAtomicsTailBigUint64(); }
|
|
130
|
+
|
|
131
|
+
void fxInt8Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsExchange(); mxAtomicsTail(); }
|
|
132
|
+
void fxInt16Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsExchange(); mxAtomicsTail(); }
|
|
133
|
+
void fxInt32Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsExchange(); mxAtomicsTail(); }
|
|
134
|
+
void fxInt64Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsExchange(); mxAtomicsTailBigInt64(); }
|
|
135
|
+
void fxUint8Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsExchange(); mxAtomicsTail(); }
|
|
136
|
+
void fxUint16Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsExchange(); mxAtomicsTail(); }
|
|
137
|
+
void fxUint32Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsExchange(); mxAtomicsTailOverflow(); }
|
|
138
|
+
void fxUint64Exchange(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsExchange(); mxAtomicsTailBigUint64(); }
|
|
139
|
+
|
|
140
|
+
void fxInt8Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txS1, fxToInteger); mxAtomicsLoad(); mxAtomicsTail(); }
|
|
141
|
+
void fxInt16Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txS2, fxToInteger); mxAtomicsLoad(); mxAtomicsTail(); }
|
|
142
|
+
void fxInt32Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txS4, fxToInteger); mxAtomicsLoad(); mxAtomicsTail(); }
|
|
143
|
+
void fxInt64Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txS8, fxToBigInt64); mxAtomicsLoad(); mxAtomicsTailBigInt64(); }
|
|
144
|
+
void fxUint8Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txU1, fxToUnsigned); mxAtomicsLoad(); mxAtomicsTail(); }
|
|
145
|
+
void fxUint16Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txU2, fxToUnsigned); mxAtomicsLoad(); mxAtomicsTail(); }
|
|
146
|
+
void fxUint32Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txU4, fxToUnsigned); mxAtomicsLoad(); mxAtomicsTailOverflow(); }
|
|
147
|
+
void fxUint64Load(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead0(txU8, fxToBigUint64); mxAtomicsLoad(); mxAtomicsTailBigUint64(); }
|
|
148
|
+
|
|
149
|
+
void fxInt8Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsOr(); mxAtomicsTail(); }
|
|
150
|
+
void fxInt16Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsOr(); mxAtomicsTail(); }
|
|
151
|
+
void fxInt32Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsOr(); mxAtomicsTail(); }
|
|
152
|
+
void fxInt64Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsOr(); mxAtomicsTailBigInt64(); }
|
|
153
|
+
void fxUint8Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsOr(); mxAtomicsTail(); }
|
|
154
|
+
void fxUint16Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsOr(); mxAtomicsTail(); }
|
|
155
|
+
void fxUint32Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsOr(); mxAtomicsTailOverflow(); }
|
|
156
|
+
void fxUint64Or(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsOr(); mxAtomicsTailBigUint64(); }
|
|
157
|
+
|
|
158
|
+
void fxInt8Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsStore(); mxAtomicsTail(); }
|
|
159
|
+
void fxInt16Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsStore(); mxAtomicsTail(); }
|
|
160
|
+
void fxInt32Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsStore(); mxAtomicsTail(); }
|
|
161
|
+
void fxInt64Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsStore(); mxAtomicsTailBigInt64(); }
|
|
162
|
+
void fxUint8Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsStore(); mxAtomicsTail(); }
|
|
163
|
+
void fxUint16Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsStore(); mxAtomicsTail(); }
|
|
164
|
+
void fxUint32Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsStore(); mxAtomicsTailOverflow(); }
|
|
165
|
+
void fxUint64Store(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsStore(); mxAtomicsTailBigUint64(); }
|
|
166
|
+
|
|
167
|
+
void fxInt8Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsSub(); mxAtomicsTail(); }
|
|
168
|
+
void fxInt16Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsSub(); mxAtomicsTail(); }
|
|
169
|
+
void fxInt32Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsSub(); mxAtomicsTail(); }
|
|
170
|
+
void fxInt64Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsSub(); mxAtomicsTailBigInt64(); }
|
|
171
|
+
void fxUint8Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsSub(); mxAtomicsTail(); }
|
|
172
|
+
void fxUint16Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsSub(); mxAtomicsTail(); }
|
|
173
|
+
void fxUint32Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsSub(); mxAtomicsTailOverflow(); }
|
|
174
|
+
void fxUint64Sub(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsSub(); mxAtomicsTailBigUint64(); }
|
|
175
|
+
|
|
176
|
+
void fxInt8Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS1, fxToInteger); mxAtomicsXor(); mxAtomicsTail(); }
|
|
177
|
+
void fxInt16Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS2, fxToInteger); mxAtomicsXor(); mxAtomicsTail(); }
|
|
178
|
+
void fxInt32Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsXor(); mxAtomicsTail(); }
|
|
179
|
+
void fxInt64Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsXor(); mxAtomicsTailBigInt64(); }
|
|
180
|
+
void fxUint8Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU1, fxToUnsigned); mxAtomicsXor(); mxAtomicsTail(); }
|
|
181
|
+
void fxUint16Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU2, fxToUnsigned); mxAtomicsXor(); mxAtomicsTail(); }
|
|
182
|
+
void fxUint32Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU4, fxToUnsigned); mxAtomicsXor(); mxAtomicsTailOverflow(); }
|
|
183
|
+
void fxUint64Xor(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, int endian) { mxAtomicsHead1(txU8, fxToBigUint64); mxAtomicsXor(); mxAtomicsTailBigUint64(); }
|
|
184
|
+
|
|
185
|
+
txInteger fxInt32Wait(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, txNumber timeout) { mxAtomicsHead1(txS4, fxToInteger); mxAtomicsLoad(); mxAtomicsTailWait(); }
|
|
186
|
+
txInteger fxInt64Wait(txMachine* the, txSlot* host, txInteger offset, txSlot* slot, txNumber timeout) { mxAtomicsHead1(txS8, fxToBigInt64); mxAtomicsLoad(); mxAtomicsTailWait(); }
|
|
187
|
+
|
|
188
|
+
void fxBuildAtomics(txMachine* the)
|
|
189
|
+
{
|
|
190
|
+
txSlot* slot;
|
|
191
|
+
|
|
192
|
+
mxPush(mxObjectPrototype);
|
|
193
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
194
|
+
slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_SharedArrayBuffer_prototype_get_byteLength), C_NULL, mxID(_byteLength), XS_DONT_ENUM_FLAG);
|
|
195
|
+
slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_SharedArrayBuffer_prototype_get_growable), C_NULL, mxID(_growable), XS_DONT_ENUM_FLAG);
|
|
196
|
+
slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_SharedArrayBuffer_prototype_get_maxByteLength), C_NULL, mxID(_maxByteLength), XS_DONT_ENUM_FLAG);
|
|
197
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_SharedArrayBuffer_prototype_grow), 1, mxID(_grow), XS_DONT_ENUM_FLAG);
|
|
198
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_SharedArrayBuffer_prototype_slice), 2, mxID(_slice), XS_DONT_ENUM_FLAG);
|
|
199
|
+
slot = fxNextStringXProperty(the, slot, "SharedArrayBuffer", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
200
|
+
mxSharedArrayBufferPrototype = *the->stack;
|
|
201
|
+
slot = fxBuildHostConstructor(the, mxCallback(fx_SharedArrayBuffer), 1, mxID(_SharedArrayBuffer));
|
|
202
|
+
mxSharedArrayBufferConstructor = *the->stack;
|
|
203
|
+
slot = fxLastProperty(the, slot);
|
|
204
|
+
slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_species_get), C_NULL, mxID(_Symbol_species), XS_DONT_ENUM_FLAG);
|
|
205
|
+
mxPop();
|
|
206
|
+
|
|
207
|
+
mxPush(mxObjectPrototype);
|
|
208
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
209
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_add), 3, mxID(_add), XS_DONT_ENUM_FLAG);
|
|
210
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_and), 3, mxID(_and), XS_DONT_ENUM_FLAG);
|
|
211
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_compareExchange), 4, mxID(_compareExchange), XS_DONT_ENUM_FLAG);
|
|
212
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_exchange), 3, mxID(_exchange), XS_DONT_ENUM_FLAG);
|
|
213
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_isLockFree), 1, mxID(_isLockFree), XS_DONT_ENUM_FLAG);
|
|
214
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_load), 2, mxID(_load), XS_DONT_ENUM_FLAG);
|
|
215
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_or), 3, mxID(_or), XS_DONT_ENUM_FLAG);
|
|
216
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_notify), 3, mxID(_notify), XS_DONT_ENUM_FLAG);
|
|
217
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_store), 3, mxID(_store), XS_DONT_ENUM_FLAG);
|
|
218
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_sub), 3, mxID(_sub), XS_DONT_ENUM_FLAG);
|
|
219
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_wait), 4, mxID(_wait), XS_DONT_ENUM_FLAG);
|
|
220
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_notify), 3, mxID(_wake), XS_DONT_ENUM_FLAG);
|
|
221
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Atomics_xor), 3, mxID(_xor), XS_DONT_ENUM_FLAG);
|
|
222
|
+
slot = fxNextStringXProperty(the, slot, "Atomics", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
223
|
+
mxPull(mxAtomicsObject);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
txSlot* fxCheckAtomicsArrayBuffer(txMachine* the, txSlot* slot, txBoolean onlyShared)
|
|
227
|
+
{
|
|
228
|
+
if ((!slot) || (!mxIsReference(slot)))
|
|
229
|
+
mxTypeError("typedArray.buffer is no object");
|
|
230
|
+
slot = slot->value.reference->next;
|
|
231
|
+
if (slot && (slot->kind == XS_HOST_KIND) && (slot->value.host.variant.destructor == fxReleaseSharedChunk))
|
|
232
|
+
return slot;
|
|
233
|
+
if (onlyShared)
|
|
234
|
+
mxTypeError("typedArray.buffer is no SharedArrayBuffer");
|
|
235
|
+
if (slot && (slot->flag & XS_INTERNAL_FLAG) && (slot->kind == XS_ARRAY_BUFFER_KIND)) {
|
|
236
|
+
if (slot->value.arrayBuffer.address == C_NULL)
|
|
237
|
+
mxTypeError("typedArray.buffer is detached");
|
|
238
|
+
return slot;
|
|
239
|
+
}
|
|
240
|
+
mxTypeError("typedArray.buffer is no SharedArrayBuffer, no ArrayBuffer");
|
|
241
|
+
return C_NULL;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
void* fxCheckAtomicsArrayBufferDetached(txMachine* the, txSlot* slot, txBoolean mutable)
|
|
245
|
+
{
|
|
246
|
+
if (slot->value.arrayBuffer.address == C_NULL)
|
|
247
|
+
mxTypeError("typedArray.buffer is detached");
|
|
248
|
+
if (mutable && (slot->flag & XS_DONT_SET_FLAG))
|
|
249
|
+
mxTypeError("typedArray.buffer is read-only");
|
|
250
|
+
return slot->value.arrayBuffer.address;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
txInteger fxCheckAtomicsIndex(txMachine* the, txInteger i, txInteger length)
|
|
254
|
+
{
|
|
255
|
+
txNumber index = (mxArgc > i) ? c_trunc(fxToNumber(the, mxArgv(i))) : C_NAN;
|
|
256
|
+
if (c_isnan(index))
|
|
257
|
+
index = 0;
|
|
258
|
+
if (index < 0)
|
|
259
|
+
mxRangeError("invalid index");
|
|
260
|
+
else if (index >= length)
|
|
261
|
+
mxRangeError("invalid index");
|
|
262
|
+
return (txInteger)index;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
txSlot* fxCheckAtomicsTypedArray(txMachine* the, txBoolean onlyInt32)
|
|
266
|
+
{
|
|
267
|
+
txSlot* slot = (mxArgc > 0) ? mxArgv(0) : C_NULL;
|
|
268
|
+
txID id;
|
|
269
|
+
if ((!slot) || (!mxIsReference(slot)))
|
|
270
|
+
mxTypeError("typedArray is no object");
|
|
271
|
+
slot = slot->value.reference->next;
|
|
272
|
+
if ((!slot) || ((slot->kind != XS_TYPED_ARRAY_KIND)))
|
|
273
|
+
mxTypeError("typedArray is no TypedArray");
|
|
274
|
+
id = slot->value.typedArray.dispatch->constructorID;
|
|
275
|
+
if (onlyInt32) {
|
|
276
|
+
if ((id != _Int32Array) && (id != _BigInt64Array))
|
|
277
|
+
mxTypeError("typedArray is no Int32Array");
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
if (id == _Float32Array)
|
|
281
|
+
mxTypeError("typedArray is Float32Array");
|
|
282
|
+
else if (id == _Float64Array)
|
|
283
|
+
mxTypeError("typedArray is Float64Array");
|
|
284
|
+
else if (id == _Uint8ClampedArray)
|
|
285
|
+
mxTypeError("typedArray is Uint8ClampedArray");
|
|
286
|
+
}
|
|
287
|
+
return slot;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
txSlot* fxCheckSharedArrayBuffer(txMachine* the, txSlot* slot, txString which)
|
|
291
|
+
{
|
|
292
|
+
if ((!slot) || (!mxIsReference(slot)))
|
|
293
|
+
mxTypeError("%s is no object", which);
|
|
294
|
+
slot = slot->value.reference->next;
|
|
295
|
+
if ((!slot) || (slot->kind != XS_HOST_KIND) || (slot->value.host.variant.destructor != fxReleaseSharedChunk))
|
|
296
|
+
mxTypeError("%s is no SharedArrayBuffer", which);
|
|
297
|
+
return slot;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
void fxPushAtomicsValue(txMachine* the, int i, txID id)
|
|
301
|
+
{
|
|
302
|
+
txSlot* slot;
|
|
303
|
+
if (mxArgc > i)
|
|
304
|
+
mxPushSlot(mxArgv(i));
|
|
305
|
+
else
|
|
306
|
+
mxPushUndefined();
|
|
307
|
+
slot = the->stack;
|
|
308
|
+
if ((id == _BigInt64Array) || (id == _BigUint64Array))
|
|
309
|
+
fxBigIntCoerce(the, slot);
|
|
310
|
+
else {
|
|
311
|
+
txNumber value;
|
|
312
|
+
fxNumberCoerce(the, slot);
|
|
313
|
+
value = c_trunc(slot->value.number);
|
|
314
|
+
if (c_isnan(value) || (value == -0))
|
|
315
|
+
value = 0;
|
|
316
|
+
slot->value.number = value;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
void fx_SharedArrayBuffer(txMachine* the)
|
|
322
|
+
{
|
|
323
|
+
txSlot* instance;
|
|
324
|
+
txInteger byteLength;
|
|
325
|
+
txInteger maxByteLength = -1;
|
|
326
|
+
txSlot* property;
|
|
327
|
+
if (mxIsUndefined(mxTarget))
|
|
328
|
+
mxTypeError("call: SharedArrayBuffer");
|
|
329
|
+
mxPushSlot(mxTarget);
|
|
330
|
+
fxGetPrototypeFromConstructor(the, &mxSharedArrayBufferPrototype);
|
|
331
|
+
byteLength = fxCheckAtomicsIndex(the, 0, 0x7FFFFFFF);
|
|
332
|
+
if ((mxArgc > 1) && mxIsReference(mxArgv(1))) {
|
|
333
|
+
mxPushSlot(mxArgv(1));
|
|
334
|
+
mxGetID(mxID(_maxByteLength));
|
|
335
|
+
mxPullSlot(mxArgv(1));
|
|
336
|
+
maxByteLength = fxArgToByteLength(the, 1, -1);
|
|
337
|
+
}
|
|
338
|
+
if (maxByteLength >= 0) {
|
|
339
|
+
if (byteLength > maxByteLength)
|
|
340
|
+
mxRangeError("byteLength > maxByteLength");
|
|
341
|
+
}
|
|
342
|
+
instance = fxNewSlot(the);
|
|
343
|
+
instance->kind = XS_INSTANCE_KIND;
|
|
344
|
+
instance->value.instance.garbage = C_NULL;
|
|
345
|
+
instance->value.instance.prototype = the->stack->value.reference;
|
|
346
|
+
the->stack->value.reference = instance;
|
|
347
|
+
the->stack->kind = XS_REFERENCE_KIND;
|
|
348
|
+
property = instance->next = fxNewSlot(the);
|
|
349
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
350
|
+
property->kind = XS_HOST_KIND;
|
|
351
|
+
property->value.host.data = fxCreateSharedChunk(byteLength);
|
|
352
|
+
if (!property->value.host.data)
|
|
353
|
+
mxRangeError("cannot allocate SharedArrayBuffer");
|
|
354
|
+
property->value.host.variant.destructor = fxReleaseSharedChunk;
|
|
355
|
+
property = property->next = fxNewSlot(the);
|
|
356
|
+
property->flag = XS_INTERNAL_FLAG;
|
|
357
|
+
property->kind = XS_BUFFER_INFO_KIND;
|
|
358
|
+
property->value.bufferInfo.length = byteLength;
|
|
359
|
+
property->value.bufferInfo.maxLength = maxByteLength;
|
|
360
|
+
mxPullSlot(mxResult);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
void fx_SharedArrayBuffer_prototype_get_byteLength(txMachine* the)
|
|
364
|
+
{
|
|
365
|
+
txSlot* host = fxCheckSharedArrayBuffer(the, mxThis, "this");
|
|
366
|
+
txSlot* bufferInfo = host->next;
|
|
367
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
368
|
+
mxResult->value.integer = bufferInfo->value.bufferInfo.length;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
void fx_SharedArrayBuffer_prototype_get_growable(txMachine* the)
|
|
372
|
+
{
|
|
373
|
+
txSlot* host = fxCheckSharedArrayBuffer(the, mxThis, "this");
|
|
374
|
+
txSlot* bufferInfo = host->next;
|
|
375
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
376
|
+
mxResult->value.boolean = (bufferInfo->value.bufferInfo.maxLength >= 0) ? 1 : 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
void fx_SharedArrayBuffer_prototype_get_maxByteLength(txMachine* the)
|
|
380
|
+
{
|
|
381
|
+
txSlot* host = fxCheckSharedArrayBuffer(the, mxThis, "this");
|
|
382
|
+
txSlot* bufferInfo = host->next;
|
|
383
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
384
|
+
if (bufferInfo->value.bufferInfo.maxLength >= 0)
|
|
385
|
+
mxResult->value.integer = bufferInfo->value.bufferInfo.maxLength;
|
|
386
|
+
else
|
|
387
|
+
mxResult->value.integer = bufferInfo->value.bufferInfo.length;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
void fx_SharedArrayBuffer_prototype_grow(txMachine* the)
|
|
391
|
+
{
|
|
392
|
+
txSlot* host = fxCheckSharedArrayBuffer(the, mxThis, "this");
|
|
393
|
+
txSlot* bufferInfo = host->next;
|
|
394
|
+
txInteger maxByteLength, oldByteLength, newByteLength;
|
|
395
|
+
maxByteLength = bufferInfo->value.bufferInfo.maxLength;
|
|
396
|
+
if (maxByteLength < 0)
|
|
397
|
+
mxTypeError("not resizable");
|
|
398
|
+
oldByteLength = bufferInfo->value.bufferInfo.length;
|
|
399
|
+
newByteLength = fxArgToByteLength(the, 0, 0);
|
|
400
|
+
if (newByteLength < oldByteLength)
|
|
401
|
+
mxRangeError("newLength < byteLength");
|
|
402
|
+
if (newByteLength > maxByteLength)
|
|
403
|
+
mxRangeError("newLength > maxByteLength");
|
|
404
|
+
mxRangeError("cannot grow SharedArrayBuffer");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
void fx_SharedArrayBuffer_prototype_slice(txMachine* the)
|
|
408
|
+
{
|
|
409
|
+
txSlot* host = fxCheckSharedArrayBuffer(the, mxThis, "this");
|
|
410
|
+
txSlot* bufferInfo = host->next;
|
|
411
|
+
txInteger length = bufferInfo->value.bufferInfo.length;
|
|
412
|
+
txInteger start = (txInteger)fxArgToIndex(the, 0, 0, length);
|
|
413
|
+
txInteger stop = (txInteger)fxArgToIndex(the, 1, length, length);
|
|
414
|
+
txSlot* result;
|
|
415
|
+
if (stop < start)
|
|
416
|
+
stop = start;
|
|
417
|
+
length = stop - start;
|
|
418
|
+
mxPushSlot(mxThis);
|
|
419
|
+
mxGetID(mxID(_constructor));
|
|
420
|
+
fxToSpeciesConstructor(the, &mxSharedArrayBufferConstructor);
|
|
421
|
+
mxNew();
|
|
422
|
+
mxPushInteger(length);
|
|
423
|
+
mxRunCount(1);
|
|
424
|
+
mxPullSlot(mxResult);
|
|
425
|
+
result = fxCheckSharedArrayBuffer(the, mxResult, "result");
|
|
426
|
+
if (result == host)
|
|
427
|
+
mxTypeError("same SharedArrayBuffer instance");
|
|
428
|
+
bufferInfo = result->next;
|
|
429
|
+
if (bufferInfo->value.bufferInfo.length < length)
|
|
430
|
+
mxTypeError("smaller SharedArrayBuffer instance");
|
|
431
|
+
c_memcpy(result->value.host.data, ((txByte*)host->value.host.data + start), stop - start);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
void fx_Atomics_add(txMachine* the)
|
|
435
|
+
{
|
|
436
|
+
mxAtomicsDeclarations(0, 0);
|
|
437
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
438
|
+
(*dispatch->value.typedArray.atomics->add)(the, host, offset, the->stack, 0);
|
|
439
|
+
mxPullSlot(mxResult);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
void fx_Atomics_and(txMachine* the)
|
|
443
|
+
{
|
|
444
|
+
mxAtomicsDeclarations(0, 0);
|
|
445
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
446
|
+
(*dispatch->value.typedArray.atomics->and)(the, host, offset, the->stack, 0);
|
|
447
|
+
mxPullSlot(mxResult);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
void fx_Atomics_compareExchange(txMachine* the)
|
|
451
|
+
{
|
|
452
|
+
mxAtomicsDeclarations(0, 0);
|
|
453
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
454
|
+
fxPushAtomicsValue(the, 3, dispatch->value.typedArray.dispatch->constructorID);
|
|
455
|
+
(*dispatch->value.typedArray.atomics->compareExchange)(the, host, offset, the->stack, 0);
|
|
456
|
+
mxPullSlot(mxResult);
|
|
457
|
+
mxPop();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
void fx_Atomics_exchange(txMachine* the)
|
|
461
|
+
{
|
|
462
|
+
mxAtomicsDeclarations(0, 0);
|
|
463
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
464
|
+
(*dispatch->value.typedArray.atomics->exchange)(the, host, offset, the->stack, 0);
|
|
465
|
+
mxPullSlot(mxResult);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
void fx_Atomics_isLockFree(txMachine* the)
|
|
469
|
+
{
|
|
470
|
+
txInteger size = (mxArgc > 0) ? fxToInteger(the, mxArgv(0)) : 0;
|
|
471
|
+
mxResult->value.boolean = (size == 4) ? 1 : 0;
|
|
472
|
+
mxResult->kind = XS_BOOLEAN_KIND;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
void fx_Atomics_load(txMachine* the)
|
|
476
|
+
{
|
|
477
|
+
mxAtomicsDeclarations(0, 0);
|
|
478
|
+
(*dispatch->value.typedArray.atomics->load)(the, host, offset, mxResult, 0);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
void fx_Atomics_or(txMachine* the)
|
|
482
|
+
{
|
|
483
|
+
mxAtomicsDeclarations(0, 0);
|
|
484
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
485
|
+
(*dispatch->value.typedArray.atomics->or)(the, host, offset, the->stack, 0);
|
|
486
|
+
mxPullSlot(mxResult);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
void fx_Atomics_notify(txMachine* the)
|
|
490
|
+
{
|
|
491
|
+
mxAtomicsDeclarations(1, 0);
|
|
492
|
+
txInteger count = ((mxArgc > 2) && !mxIsUndefined(mxArgv(2))) ? fxToInteger(the, mxArgv(2)) : 20;
|
|
493
|
+
if (count < 0)
|
|
494
|
+
count = 0;
|
|
495
|
+
if (host->kind == XS_ARRAY_BUFFER_KIND) {
|
|
496
|
+
mxResult->value.integer = 0;
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
mxResult->value.integer = fxNotifySharedChunk(the, host->value.host.data, offset, count);
|
|
500
|
+
}
|
|
501
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
void fx_Atomics_store(txMachine* the)
|
|
505
|
+
{
|
|
506
|
+
mxAtomicsDeclarations(0, 0);
|
|
507
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
508
|
+
*mxResult = *the->stack;
|
|
509
|
+
(*dispatch->value.typedArray.atomics->store)(the, host, offset, the->stack, 0);
|
|
510
|
+
mxPop();
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
void fx_Atomics_sub(txMachine* the)
|
|
514
|
+
{
|
|
515
|
+
mxAtomicsDeclarations(0, 0);
|
|
516
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
517
|
+
(*dispatch->value.typedArray.atomics->sub)(the, host, offset, the->stack, 0);
|
|
518
|
+
mxPullSlot(mxResult);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
void fx_Atomics_wait(txMachine* the)
|
|
522
|
+
{
|
|
523
|
+
mxAtomicsDeclarations(1, 1);
|
|
524
|
+
txNumber timeout;
|
|
525
|
+
txInteger result;
|
|
526
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
527
|
+
timeout = (mxArgc > 3) ? fxToNumber(the, mxArgv(3)) : C_NAN;
|
|
528
|
+
if (c_isnan(timeout))
|
|
529
|
+
timeout = C_INFINITY;
|
|
530
|
+
else if (timeout < 0)
|
|
531
|
+
timeout = 0;
|
|
532
|
+
fxLinkSharedChunk(the);
|
|
533
|
+
result = (*dispatch->value.typedArray.atomics->wait)(the, host, offset, the->stack, timeout);
|
|
534
|
+
fxUnlinkSharedChunk(the);
|
|
535
|
+
if (result < 0)
|
|
536
|
+
mxResult->value.string = "not-equal";
|
|
537
|
+
else if (result > 0)
|
|
538
|
+
mxResult->value.string = "ok";
|
|
539
|
+
else
|
|
540
|
+
mxResult->value.string = "timed-out";
|
|
541
|
+
mxResult->kind = XS_STRING_X_KIND;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
void fx_Atomics_xor(txMachine* the)
|
|
545
|
+
{
|
|
546
|
+
mxAtomicsDeclarations(0, 0);
|
|
547
|
+
fxPushAtomicsValue(the, 2, dispatch->value.typedArray.dispatch->constructorID);
|
|
548
|
+
(*dispatch->value.typedArray.atomics->xor)(the, host, offset, the->stack, 0);
|
|
549
|
+
mxPullSlot(mxResult);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
#ifdef mxUseDefaultSharedChunks
|
|
553
|
+
|
|
554
|
+
#if defined(mxUsePOSIXThreads)
|
|
555
|
+
#define mxThreads 1
|
|
556
|
+
typedef pthread_cond_t txCondition;
|
|
557
|
+
typedef pthread_mutex_t txMutex;
|
|
558
|
+
typedef pthread_t txThread;
|
|
559
|
+
#define mxCreateCondition(CONDITION) pthread_cond_init(CONDITION,NULL)
|
|
560
|
+
#define mxCreateMutex(MUTEX) pthread_mutex_init(MUTEX,NULL)
|
|
561
|
+
#define mxCurrentThread() pthread_self()
|
|
562
|
+
#define mxDeleteCondition(CONDITION) pthread_cond_destroy(CONDITION)
|
|
563
|
+
#define mxDeleteMutex(MUTEX) pthread_mutex_destroy(MUTEX)
|
|
564
|
+
#define mxLockMutex(MUTEX) pthread_mutex_lock(MUTEX)
|
|
565
|
+
#define mxUnlockMutex(MUTEX) pthread_mutex_unlock(MUTEX)
|
|
566
|
+
#define mxWakeCondition(CONDITION) pthread_cond_signal(CONDITION)
|
|
567
|
+
#elif defined(mxUseFreeRTOSTasks)
|
|
568
|
+
#define mxThreads 1
|
|
569
|
+
|
|
570
|
+
#include "FreeRTOS.h"
|
|
571
|
+
#include "freertos/queue.h"
|
|
572
|
+
#include "freertos/semphr.h"
|
|
573
|
+
|
|
574
|
+
typedef TaskHandle_t txCondition;
|
|
575
|
+
typedef struct {
|
|
576
|
+
QueueHandle_t handle;
|
|
577
|
+
StaticSemaphore_t buffer;
|
|
578
|
+
} txMutex;
|
|
579
|
+
typedef TaskHandle_t txThread;
|
|
580
|
+
#define mxCreateCondition(CONDITION) *(CONDITION) = xTaskGetCurrentTaskHandle()
|
|
581
|
+
#define mxCreateMutex(MUTEX) (MUTEX)->handle = xSemaphoreCreateMutexStatic(&((MUTEX)->buffer))
|
|
582
|
+
#define mxCurrentThread() xTaskGetCurrentTaskHandle()
|
|
583
|
+
#define mxDeleteCondition(CONDITION) *(CONDITION) = NULL
|
|
584
|
+
#define mxDeleteMutex(MUTEX) vSemaphoreDelete((MUTEX)->handle)
|
|
585
|
+
#define mxLockMutex(MUTEX) xSemaphoreTake((MUTEX)->handle, portMAX_DELAY)
|
|
586
|
+
#define mxUnlockMutex(MUTEX) xSemaphoreGive((MUTEX)->handle)
|
|
587
|
+
#define mxWakeCondition(CONDITION) xTaskNotifyGive(*(CONDITION));
|
|
588
|
+
#elif mxWindows
|
|
589
|
+
#define mxThreads 1
|
|
590
|
+
typedef CONDITION_VARIABLE txCondition;
|
|
591
|
+
typedef CRITICAL_SECTION txMutex;
|
|
592
|
+
typedef DWORD txThread;
|
|
593
|
+
#define mxCreateCondition(CONDITION) InitializeConditionVariable(CONDITION)
|
|
594
|
+
#define mxCreateMutex(MUTEX) InitializeCriticalSection(MUTEX)
|
|
595
|
+
#define mxCurrentThread() GetCurrentThreadId()
|
|
596
|
+
#define mxDeleteCondition(CONDITION) (void)(CONDITION)
|
|
597
|
+
#define mxDeleteMutex(MUTEX) DeleteCriticalSection(MUTEX)
|
|
598
|
+
#define mxLockMutex(MUTEX) EnterCriticalSection(MUTEX)
|
|
599
|
+
#define mxUnlockMutex(MUTEX) LeaveCriticalSection(MUTEX)
|
|
600
|
+
#define mxWakeCondition(CONDITION) WakeConditionVariable(CONDITION)
|
|
601
|
+
#else
|
|
602
|
+
#define mxThreads 0
|
|
603
|
+
typedef void* txThread;
|
|
604
|
+
#define mxCurrentThread() C_NULL
|
|
605
|
+
#endif
|
|
606
|
+
|
|
607
|
+
typedef struct sxSharedCluster txSharedCluster;
|
|
608
|
+
typedef struct sxSharedChunk txSharedChunk;
|
|
609
|
+
|
|
610
|
+
struct sxSharedCluster {
|
|
611
|
+
txThread mainThread;
|
|
612
|
+
txSize usage;
|
|
613
|
+
#if mxThreads
|
|
614
|
+
txMachine* waiterLink;
|
|
615
|
+
txMutex waiterMutex;
|
|
616
|
+
#endif
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
struct sxSharedChunk {
|
|
620
|
+
#if mxThreads && !defined(mxUseGCCAtomics)
|
|
621
|
+
txMutex mutex;
|
|
622
|
+
#endif
|
|
623
|
+
txSize size;
|
|
624
|
+
txSize usage;
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
txSharedCluster* gxSharedCluster = C_NULL;
|
|
628
|
+
|
|
629
|
+
void fxInitializeSharedCluster()
|
|
630
|
+
{
|
|
631
|
+
if (gxSharedCluster) {
|
|
632
|
+
gxSharedCluster->usage++;
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
gxSharedCluster = c_calloc(sizeof(txSharedCluster), 1);
|
|
636
|
+
if (gxSharedCluster) {
|
|
637
|
+
gxSharedCluster->mainThread = mxCurrentThread();
|
|
638
|
+
gxSharedCluster->usage++;
|
|
639
|
+
#if mxThreads
|
|
640
|
+
mxCreateMutex(&gxSharedCluster->waiterMutex);
|
|
641
|
+
#endif
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
void fxTerminateSharedCluster()
|
|
647
|
+
{
|
|
648
|
+
if (gxSharedCluster) {
|
|
649
|
+
gxSharedCluster->usage--;
|
|
650
|
+
if (gxSharedCluster->usage == 0) {
|
|
651
|
+
#if mxThreads
|
|
652
|
+
mxDeleteMutex(&gxSharedCluster->waiterMutex);
|
|
653
|
+
#endif
|
|
654
|
+
c_free(gxSharedCluster);
|
|
655
|
+
gxSharedCluster = C_NULL;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
void* fxCreateSharedChunk(txInteger size)
|
|
661
|
+
{
|
|
662
|
+
txSharedChunk* chunk = c_malloc(sizeof(txSharedChunk) + size);
|
|
663
|
+
if (chunk) {
|
|
664
|
+
void* data = (((txByte*)chunk) + sizeof(txSharedChunk));
|
|
665
|
+
#if mxThreads && !defined(mxUseGCCAtomics)
|
|
666
|
+
mxCreateMutex(&(chunk->mutex));
|
|
667
|
+
#endif
|
|
668
|
+
chunk->size = size;
|
|
669
|
+
chunk->usage = 1;
|
|
670
|
+
c_memset(data, 0, size);
|
|
671
|
+
return data;
|
|
672
|
+
}
|
|
673
|
+
return C_NULL;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
void fxLinkSharedChunk(txMachine* the)
|
|
677
|
+
{
|
|
678
|
+
if (gxSharedCluster && (gxSharedCluster->mainThread != mxCurrentThread())) {
|
|
679
|
+
#if mxThreads
|
|
680
|
+
txMachine** machineAddress;
|
|
681
|
+
txMachine* machine;
|
|
682
|
+
mxLockMutex(&gxSharedCluster->waiterMutex);
|
|
683
|
+
machineAddress = &gxSharedCluster->waiterLink;
|
|
684
|
+
while ((machine = *machineAddress))
|
|
685
|
+
machineAddress = (txMachine**)&machine->waiterLink;
|
|
686
|
+
*machineAddress = the;
|
|
687
|
+
#endif
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
mxTypeError("main thread cannot wait");
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
void fxLockSharedChunk(void* data)
|
|
695
|
+
{
|
|
696
|
+
#if mxThreads && !defined(mxUseGCCAtomics)
|
|
697
|
+
txSharedChunk* chunk = (txSharedChunk*)(((txByte*)data) - sizeof(txSharedChunk));
|
|
698
|
+
mxLockMutex(&(chunk->mutex));
|
|
699
|
+
#endif
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
txInteger fxMeasureSharedChunk(void* data)
|
|
703
|
+
{
|
|
704
|
+
txSharedChunk* chunk = (txSharedChunk*)(((txByte*)data) - sizeof(txSharedChunk));
|
|
705
|
+
return chunk->size;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
txInteger fxNotifySharedChunk(txMachine* the, void* data, txInteger offset, txInteger count)
|
|
709
|
+
{
|
|
710
|
+
txInteger* address = (txInteger*)((txByte*)data + offset);
|
|
711
|
+
txInteger result = 0;
|
|
712
|
+
if (gxSharedCluster) {
|
|
713
|
+
#if mxThreads
|
|
714
|
+
txMachine* machine;
|
|
715
|
+
mxLockMutex(&gxSharedCluster->waiterMutex);
|
|
716
|
+
machine = gxSharedCluster->waiterLink;
|
|
717
|
+
while (machine) {
|
|
718
|
+
if (machine->waiterData == address) {
|
|
719
|
+
if (count == 0)
|
|
720
|
+
break;
|
|
721
|
+
count--;
|
|
722
|
+
machine->waiterData = C_NULL;
|
|
723
|
+
mxWakeCondition((txCondition*)machine->waiterCondition);
|
|
724
|
+
result++;
|
|
725
|
+
}
|
|
726
|
+
machine = machine->waiterLink;
|
|
727
|
+
}
|
|
728
|
+
mxUnlockMutex(&gxSharedCluster->waiterMutex);
|
|
729
|
+
#endif
|
|
730
|
+
}
|
|
731
|
+
return result;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
void* fxRetainSharedChunk(void* data)
|
|
735
|
+
{
|
|
736
|
+
txSharedChunk* chunk = (txSharedChunk*)(((txByte*)data) - sizeof(txSharedChunk));
|
|
737
|
+
txS4 result = 0;
|
|
738
|
+
txS4 value = 1;
|
|
739
|
+
txS4* address = &(chunk->usage);
|
|
740
|
+
#ifndef mxUseGCCAtomics
|
|
741
|
+
txBoolean lock = 1;
|
|
742
|
+
#endif
|
|
743
|
+
mxAtomicsAdd();
|
|
744
|
+
if (result == 0)
|
|
745
|
+
return C_NULL;
|
|
746
|
+
return data;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
void fxReleaseSharedChunk(void* data)
|
|
750
|
+
{
|
|
751
|
+
txSharedChunk* chunk = (txSharedChunk*)(((txByte*)data) - sizeof(txSharedChunk));
|
|
752
|
+
txS4 result = 0;
|
|
753
|
+
txS4 value = 1;
|
|
754
|
+
txS4* address = &(chunk->usage);
|
|
755
|
+
#ifndef mxUseGCCAtomics
|
|
756
|
+
txBoolean lock = 1;
|
|
757
|
+
#endif
|
|
758
|
+
mxAtomicsSub();
|
|
759
|
+
if (result == 1) {
|
|
760
|
+
c_free(chunk);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
void fxUnlockSharedChunk(void* data)
|
|
765
|
+
{
|
|
766
|
+
#if mxThreads && !defined(mxUseGCCAtomics)
|
|
767
|
+
txSharedChunk* chunk = (txSharedChunk*)(((txByte*)data) - sizeof(txSharedChunk));
|
|
768
|
+
mxUnlockMutex(&(chunk->mutex));
|
|
769
|
+
#endif
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
void fxUnlinkSharedChunk(txMachine* the)
|
|
773
|
+
{
|
|
774
|
+
#if mxThreads
|
|
775
|
+
txMachine** machineAddress;
|
|
776
|
+
txMachine* machine;
|
|
777
|
+
machineAddress = &gxSharedCluster->waiterLink;
|
|
778
|
+
while ((machine = *machineAddress)) {
|
|
779
|
+
if (machine == the) {
|
|
780
|
+
*machineAddress = the->waiterLink;
|
|
781
|
+
the->waiterLink = C_NULL;
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
machineAddress = (txMachine**)&machine->waiterLink;
|
|
785
|
+
}
|
|
786
|
+
mxUnlockMutex(&gxSharedCluster->waiterMutex);
|
|
787
|
+
#endif
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
txInteger fxWaitSharedChunk(txMachine* the, void* address, txNumber timeout)
|
|
791
|
+
{
|
|
792
|
+
txInteger result = 1;
|
|
793
|
+
#if mxThreads
|
|
794
|
+
txCondition condition;
|
|
795
|
+
mxCreateCondition(&condition);
|
|
796
|
+
the->waiterCondition = &condition;
|
|
797
|
+
the->waiterData = address;
|
|
798
|
+
if (timeout == C_INFINITY) {
|
|
799
|
+
#if defined(mxUsePOSIXThreads)
|
|
800
|
+
while (the->waiterData == address)
|
|
801
|
+
pthread_cond_wait(&condition, &gxSharedCluster->waiterMutex);
|
|
802
|
+
#elif defined(mxUseFreeRTOSTasks)
|
|
803
|
+
mxUnlockMutex(&gxSharedCluster->waiterMutex);
|
|
804
|
+
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
|
805
|
+
mxLockMutex(&gxSharedCluster->waiterMutex);
|
|
806
|
+
#else
|
|
807
|
+
while (the->waiterData == address)
|
|
808
|
+
SleepConditionVariableCS(&condition, &gxSharedCluster->waiterMutex, INFINITE);
|
|
809
|
+
#endif
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
#if defined(mxUsePOSIXThreads)
|
|
813
|
+
struct timespec ts;
|
|
814
|
+
timeout += fxDateNow();
|
|
815
|
+
ts.tv_sec = c_floor(timeout / 1000);
|
|
816
|
+
ts.tv_nsec = c_fmod(timeout, 1000) * 1000000;
|
|
817
|
+
while (the->waiterData == address) {
|
|
818
|
+
result = (pthread_cond_timedwait(&condition, &gxSharedCluster->waiterMutex, &ts) == ETIMEDOUT) ? 0 : 1;
|
|
819
|
+
if (!result)
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
#elif defined(mxUseFreeRTOSTasks)
|
|
823
|
+
mxUnlockMutex(&gxSharedCluster->waiterMutex);
|
|
824
|
+
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(timeout));
|
|
825
|
+
mxLockMutex(&gxSharedCluster->waiterMutex);
|
|
826
|
+
result = (the->waiterData == address) ? 0 : 1;
|
|
827
|
+
#else
|
|
828
|
+
timeout += fxDateNow();
|
|
829
|
+
while (the->waiterData == address) {
|
|
830
|
+
result = (SleepConditionVariableCS(&condition, &gxSharedCluster->waiterMutex, (DWORD)(timeout - fxDateNow()))) ? 1 : 0;
|
|
831
|
+
if (!result)
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
#endif
|
|
835
|
+
}
|
|
836
|
+
the->waiterCondition = C_NULL;
|
|
837
|
+
mxDeleteCondition(&condition);
|
|
838
|
+
#endif
|
|
839
|
+
return result;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
#endif /* mxUseDefaultSharedChunks */
|
|
843
|
+
|
|
844
|
+
|