Move static allocation for fetch queue from JS to C++ code (#12049)
This avoids the runtime allocation on the JS side. See: #12040
This commit is contained in:
Родитель
44170cec01
Коммит
d7ef8f38fe
|
@ -12,13 +12,7 @@ var LibraryFetch = {
|
|||
#else
|
||||
$Fetch__postset: 'Fetch.staticInit();',
|
||||
#endif
|
||||
$fetchWorkQueue: '0',
|
||||
$Fetch: Fetch,
|
||||
_emscripten_get_fetch_work_queue__deps: ['$fetchWorkQueue'],
|
||||
_emscripten_get_fetch_work_queue: function() {
|
||||
if (!fetchWorkQueue) fetchWorkQueue = _malloc(12);
|
||||
return fetchWorkQueue;
|
||||
},
|
||||
_emscripten_fetch_get_response_headers_length: _fetch_get_response_headers_length,
|
||||
_emscripten_fetch_get_response_headers: _fetch_get_response_headers,
|
||||
_emscripten_fetch_free: _fetch_free,
|
||||
|
@ -35,7 +29,7 @@ var LibraryFetch = {
|
|||
#if FETCH_SUPPORT_INDEXEDDB
|
||||
'$__emscripten_fetch_cache_data', '$__emscripten_fetch_load_cached_data', '$__emscripten_fetch_delete_cached_data',
|
||||
#endif
|
||||
'_emscripten_get_fetch_work_queue', 'emscripten_is_main_browser_thread']
|
||||
'emscripten_is_main_browser_thread']
|
||||
};
|
||||
|
||||
mergeInto(LibraryManager.library, LibraryFetch);
|
||||
|
|
|
@ -18,37 +18,35 @@ extern "C" {
|
|||
// Uncomment the following and clear the cache with emcc --clear-cache to rebuild this file to
|
||||
// enable internal debugging. #define FETCH_DEBUG
|
||||
|
||||
struct __emscripten_fetch_queue {
|
||||
static void fetch_free(emscripten_fetch_t* fetch);
|
||||
|
||||
// APIs defined in JS
|
||||
void emscripten_start_fetch(emscripten_fetch_t* fetch);
|
||||
int32_t _emscripten_fetch_get_response_headers_length(int32_t fetchID);
|
||||
int32_t _emscripten_fetch_get_response_headers(int32_t fetchID, int32_t dst, int32_t dstSizeBytes);
|
||||
void _emscripten_fetch_free(unsigned int);
|
||||
|
||||
struct emscripten_fetch_queue {
|
||||
emscripten_fetch_t** queuedOperations;
|
||||
int numQueuedItems;
|
||||
int queueSize;
|
||||
};
|
||||
|
||||
static void fetch_free(emscripten_fetch_t* fetch);
|
||||
emscripten_fetch_queue* _emscripten_get_fetch_queue() {
|
||||
static thread_local emscripten_fetch_queue g_queue;
|
||||
|
||||
extern "C" {
|
||||
void emscripten_start_fetch(emscripten_fetch_t* fetch);
|
||||
__emscripten_fetch_queue* _emscripten_get_fetch_work_queue();
|
||||
|
||||
__emscripten_fetch_queue* _emscripten_get_fetch_queue() {
|
||||
__emscripten_fetch_queue* queue = _emscripten_get_fetch_work_queue();
|
||||
if (!queue->queuedOperations) {
|
||||
queue->queueSize = 64;
|
||||
queue->numQueuedItems = 0;
|
||||
queue->queuedOperations =
|
||||
(emscripten_fetch_t**)malloc(sizeof(emscripten_fetch_t*) * queue->queueSize);
|
||||
if (!g_queue.queuedOperations) {
|
||||
g_queue.queueSize = 64;
|
||||
g_queue.numQueuedItems = 0;
|
||||
g_queue.queuedOperations =
|
||||
(emscripten_fetch_t**)malloc(sizeof(emscripten_fetch_t*) * g_queue.queueSize);
|
||||
}
|
||||
return queue;
|
||||
}
|
||||
|
||||
int32_t _emscripten_fetch_get_response_headers_length(int32_t fetchID);
|
||||
int32_t _emscripten_fetch_get_response_headers(int32_t fetchID, int32_t dst, int32_t dstSizeBytes);
|
||||
void _emscripten_fetch_free(unsigned int);
|
||||
return &g_queue;
|
||||
}
|
||||
|
||||
void emscripten_proxy_fetch(emscripten_fetch_t* fetch) {
|
||||
// TODO: mutex lock
|
||||
__emscripten_fetch_queue* queue = _emscripten_get_fetch_queue();
|
||||
emscripten_fetch_queue* queue = _emscripten_get_fetch_queue();
|
||||
// TODO handle case when queue->numQueuedItems >= queue->queueSize
|
||||
queue->queuedOperations[queue->numQueuedItems++] = fetch;
|
||||
#ifdef FETCH_DEBUG
|
||||
|
|
Загрузка…
Ссылка в новой задаче