@@ -18,37 +18,35 @@ extern "C" {
18
18
// Uncomment the following and clear the cache with emcc --clear-cache to rebuild this file to
19
19
// enable internal debugging. #define FETCH_DEBUG
20
20
21
- struct __emscripten_fetch_queue {
21
+ static void fetch_free (emscripten_fetch_t * fetch);
22
+
23
+ // APIs defined in JS
24
+ void emscripten_start_fetch (emscripten_fetch_t * fetch);
25
+ int32_t _emscripten_fetch_get_response_headers_length (int32_t fetchID);
26
+ int32_t _emscripten_fetch_get_response_headers (int32_t fetchID, int32_t dst, int32_t dstSizeBytes);
27
+ void _emscripten_fetch_free (unsigned int );
28
+
29
+ struct emscripten_fetch_queue {
22
30
emscripten_fetch_t ** queuedOperations;
23
31
int numQueuedItems;
24
32
int queueSize;
25
33
};
26
34
27
- static void fetch_free (emscripten_fetch_t * fetch);
35
+ emscripten_fetch_queue* _emscripten_get_fetch_queue () {
36
+ static thread_local emscripten_fetch_queue g_queue;
28
37
29
- extern " C" {
30
- void emscripten_start_fetch (emscripten_fetch_t * fetch);
31
- __emscripten_fetch_queue* _emscripten_get_fetch_work_queue ();
32
-
33
- __emscripten_fetch_queue* _emscripten_get_fetch_queue () {
34
- __emscripten_fetch_queue* queue = _emscripten_get_fetch_work_queue ();
35
- if (!queue->queuedOperations ) {
36
- queue->queueSize = 64 ;
37
- queue->numQueuedItems = 0 ;
38
- queue->queuedOperations =
39
- (emscripten_fetch_t **)malloc (sizeof (emscripten_fetch_t *) * queue->queueSize );
38
+ if (!g_queue.queuedOperations ) {
39
+ g_queue.queueSize = 64 ;
40
+ g_queue.numQueuedItems = 0 ;
41
+ g_queue.queuedOperations =
42
+ (emscripten_fetch_t **)malloc (sizeof (emscripten_fetch_t *) * g_queue.queueSize );
40
43
}
41
- return queue;
42
- }
43
-
44
- int32_t _emscripten_fetch_get_response_headers_length (int32_t fetchID);
45
- int32_t _emscripten_fetch_get_response_headers (int32_t fetchID, int32_t dst, int32_t dstSizeBytes);
46
- void _emscripten_fetch_free (unsigned int );
44
+ return &g_queue;
47
45
}
48
46
49
47
void emscripten_proxy_fetch (emscripten_fetch_t * fetch) {
50
48
// TODO: mutex lock
51
- __emscripten_fetch_queue * queue = _emscripten_get_fetch_queue ();
49
+ emscripten_fetch_queue * queue = _emscripten_get_fetch_queue ();
52
50
// TODO handle case when queue->numQueuedItems >= queue->queueSize
53
51
queue->queuedOperations [queue->numQueuedItems ++] = fetch;
54
52
#ifdef FETCH_DEBUG
0 commit comments