Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/browser/async_virtual_2.cpp
4150 views
1
// Copyright 2015 The Emscripten Authors. All rights reserved.
2
// Emscripten is available under two separate licenses, the MIT license and the
3
// University of Illinois/NCSA Open Source License. Both these licenses can be
4
// found in the LICENSE file.
5
6
#include <emscripten.h>
7
#include <stdio.h>
8
9
class DOS_Device {
10
int devnum;
11
public:
12
DOS_Device() { devnum = 0; }
13
virtual bool Read(unsigned char * data,unsigned short * size);
14
};
15
16
DOS_Device *Devices[10];
17
18
bool __attribute__((noinline)) DOS_Device::Read(unsigned char * data,unsigned short * size) {
19
printf("DOS_Device::Read (this = %ld)\n", (long)this);
20
return Devices[devnum]->Read(data,size);
21
}
22
23
class device_CON : public DOS_Device {
24
public:
25
bool Read(unsigned char * data,unsigned short * size);
26
};
27
28
bool device_CON::Read(unsigned char * data,unsigned short * size) {
29
printf("device_CON::Read (this = %ld) Sleep--> \n", (long)this);
30
EM_ASM({
31
Module.the_this = $0;
32
out('first this ' + Module.the_this);
33
}, this);
34
emscripten_sleep(1000);
35
EM_ASM({
36
out('second this ' + $0);
37
assert(Module.the_this === $0, 'this must be unchanged');
38
}, this);
39
printf("<--Sleep (this = %ld)\n", (long)this);
40
return true;
41
}
42
43
int main(void) {
44
device_CON con;
45
Devices[0] = &con;
46
DOS_Device dev;
47
dev.Read(0,0);
48
return 0;
49
}
50
51
52