Trying to improve threading, thread queue
This commit is contained in:
@@ -55,21 +55,8 @@ struct TimeFile {
|
||||
|
||||
struct ParseThreadIO {
|
||||
Array<String> input_files;
|
||||
|
||||
// output
|
||||
Arena *arena;
|
||||
Array<TimeFile> time_files;
|
||||
};
|
||||
|
||||
void ParseThreadEntry(ParseThreadIO *io) {
|
||||
io->arena = AllocArena();
|
||||
io->time_files.allocator = *io->arena;
|
||||
For(io->input_files) {
|
||||
Array<TimeString> time_strings = ParseSrtFile(io->arena, it);
|
||||
io->time_files.add({time_strings, it});
|
||||
}
|
||||
}
|
||||
|
||||
struct XToTimeString {
|
||||
String string; // String inside transcript arena
|
||||
uint16_t hour;
|
||||
@@ -77,9 +64,28 @@ struct XToTimeString {
|
||||
uint16_t second;
|
||||
String filepath;
|
||||
};
|
||||
Arena XArena;
|
||||
|
||||
void AddFolder(String folder, Array<String> *filenames, Array<XToTimeString> *x_to_time_string) {
|
||||
Arena XArena;
|
||||
std::mutex XArenaAddMutex;
|
||||
Array<XToTimeString> XToTime;
|
||||
|
||||
WORK_FUNCTION(ParseFilesWork) {
|
||||
ParseThreadIO *io = (ParseThreadIO *)data;
|
||||
ForItem(it_time_file, io->input_files) {
|
||||
Scratch scratch;
|
||||
Array<TimeString> time_strings = ParseSrtFile(scratch, it_time_file);
|
||||
|
||||
XArenaAddMutex.lock();
|
||||
For(time_strings) {
|
||||
String s = Copy(XArena, it.string);
|
||||
s.data[s.len] = ' ';
|
||||
XToTime.add({s, it.hour, it.minute, it.second, it_time_file});
|
||||
}
|
||||
XArenaAddMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void XAddFolder(String folder, Array<String> *filenames) {
|
||||
Scratch scratch;
|
||||
|
||||
Array<String> srt_files = {scratch};
|
||||
@@ -91,11 +97,10 @@ void AddFolder(String folder, Array<String> *filenames, Array<XToTimeString> *x_
|
||||
}
|
||||
}
|
||||
|
||||
int64_t thread_count = 16;
|
||||
Array<std::thread *> threads = {scratch};
|
||||
int64_t files_per_thread = srt_files.len / thread_count;
|
||||
int64_t remainder = srt_files.len % thread_count;
|
||||
int64_t fi = 0;
|
||||
int64_t thread_count = 16;
|
||||
int64_t files_per_thread = srt_files.len / thread_count;
|
||||
int64_t remainder = srt_files.len % thread_count;
|
||||
int64_t fi = 0;
|
||||
|
||||
Array<ParseThreadIO> io = {scratch};
|
||||
io.reserve(thread_count);
|
||||
@@ -108,28 +113,14 @@ void AddFolder(String folder, Array<String> *filenames, Array<XToTimeString> *x_
|
||||
|
||||
ParseThreadIO *i = io.alloc();
|
||||
i->input_files = files;
|
||||
threads.add(new std::thread(ParseThreadEntry, i));
|
||||
PushWork(&MainWorkQueue, (void *)i, ParseFilesWork);
|
||||
}
|
||||
|
||||
For(threads) {
|
||||
it->join();
|
||||
delete it;
|
||||
}
|
||||
|
||||
ForItem(it_io, io) {
|
||||
ForItem(it_time_file, it_io.time_files) {
|
||||
For(it_time_file.time_strings) {
|
||||
String s = Copy(XArena, it.string);
|
||||
s.data[s.len] = ' ';
|
||||
x_to_time_string->add({s, it.hour, it.minute, it.second, it_time_file.file});
|
||||
}
|
||||
}
|
||||
Release(it_io.arena);
|
||||
}
|
||||
WaitUntilCompletion(&MainWorkQueue);
|
||||
}
|
||||
|
||||
XToTimeString *FindItem(Array<XToTimeString> &x_to_time_string, String string) {
|
||||
For(x_to_time_string) {
|
||||
XToTimeString *XFindItem(String string) {
|
||||
For(XToTime) {
|
||||
uintptr_t begin = (uintptr_t)(it.string.data);
|
||||
uintptr_t end = (uintptr_t)(it.string.data + it.string.len);
|
||||
uintptr_t needle = (uintptr_t)string.data;
|
||||
|
||||
Reference in New Issue
Block a user