summaryrefslogtreecommitdiff
path: root/src/search.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-03 19:49:00 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-03 19:49:00 +0100
commit7e0a7cea406d4dd4733dfa834ac7c41ce848e658 (patch)
tree3b4332bffdda99c76bc9cf819c4eb30543eb2c0a /src/search.cpp
parent15d0d75368775796a52383d17ebabff76813f31f (diff)
move shared search code out of platform
Diffstat (limited to 'src/search.cpp')
-rw-r--r--src/search.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/search.cpp b/src/search.cpp
index b8db23f..76d46f3 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -328,6 +328,27 @@ finish_early:;
return 0;
}
+static void *_ts_list_files_thread(void *args)
+{
+ ts_search_result *info = (ts_search_result *)args;
+ ts_platform_list_files_block(info, nullptr);
+ info->done_finding_files = true;
+
+ // Use this thread to cleanup.
+ while (!info->search_completed) {
+ if (info->completed_match_threads == info->max_ts_thread_count) {
+ info->search_completed = true; // No memory is written after this point.
+ }
+ }
+ return 0;
+}
+
+static void _ts_list_files(ts_search_result* result)
+{
+ ts_thread thr = ts_thread_start(_ts_list_files_thread, (void*)result);
+ ts_thread_detach(&thr);
+}
+
void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query)
{
if (current_search_result)
@@ -339,7 +360,7 @@ void ts_start_search(utf8_int8_t *path, utf8_int8_t *filter, utf8_int8_t *query)
snprintf(new_result->directory_to_search, MAX_INPUT_LENGTH, "%s", path);
snprintf(new_result->search_text, MAX_INPUT_LENGTH, "%s", query);
- ts_platform_list_files(new_result);
+ _ts_list_files(new_result);
for (int i = 0; i < new_result->max_ts_thread_count; i++)
{
ts_thread thr = ts_thread_start(_ts_search_thread, new_result);