Remodel threading to use a global thread pool so it never block on the main thread. Bump emscripten to 3.1.65

This commit is contained in:
msqr1
2024-08-26 22:37:35 -07:00
parent 53262fe7f3
commit c4ff62fa31
14 changed files with 111 additions and 81 deletions

View File

@@ -1,13 +1,14 @@
#pragma once
#include <thread>
#include <filesystem>
#include <functional>
#include <variant>
#include <fstream>
#include <emscripten/em_asm.h>
#include <emscripten/atomic.h>
#include <emscripten/console.h>
namespace fs = std::filesystem;
struct AudioData {
float* data;
int len;
@@ -21,5 +22,26 @@ enum UntarStatus {
FailedWrite,
FailedClose
};
struct ThreadPool;
struct Thread {
std::thread handle;
std::function<void()> fn;
void startup(ThreadPool* pool);
};
struct ThreadPool {
bool qLock{true}; // True is locked, false is unlocked
bool done{};
std::queue<std::function<void()>> taskQ;
#ifndef MAX_THREADS
#define MAX_THREADS 1
#endif
std::array<Thread, MAX_THREADS> threads;
#undef MAX_THREADS
ThreadPool();
~ThreadPool();
void exec(std::function<void()> fn);
};
extern ThreadPool globalPool;
void fireEv(int index, const char* content, const char* type = nullptr);
int untar(unsigned char* tar, int tarSize, const std::string& storepath);