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:
Sam Clegg 2020-08-28 02:54:30 -07:00 коммит произвёл GitHub
Родитель 44170cec01
Коммит d7ef8f38fe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 19 добавлений и 27 удалений

Просмотреть файл

@ -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