From 70633a48ae5eac06db19663744373e013c2727c8 Mon Sep 17 00:00:00 2001 From: lexborisov Date: Tue, 14 Mar 2017 23:23:43 +0300 Subject: [PATCH] Can build Modest finder without threads --- include/modest/finder/thread.h | 3 ++ source/modest/finder/thread.c | 84 +++++++++++++++++++++++++++++++++- source/modest/finder/thread.h | 3 ++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/include/modest/finder/thread.h b/include/modest/finder/thread.h index df67be8..0f9afd6 100644 --- a/include/modest/finder/thread.h +++ b/include/modest/finder/thread.h @@ -91,7 +91,10 @@ modest_finder_thread_t * modest_finder_thread_destroy(modest_finder_thread_t* fi mystatus_t modest_finder_thread_process(modest_t* modest, modest_finder_thread_t* finder_thread, myhtml_tree_node_t* scope_node, mycss_selectors_list_t* selector_list); +#ifndef MyCORE_BUILD_WITHOUT_THREADS void modest_finder_thread_wait_for_all_done(modest_finder_thread_t* finder_thread); +#endif + bool modest_finder_thread_spec_is_up(modest_style_raw_specificity_t* spec_f, modest_style_raw_specificity_t* spec_t); #ifdef __cplusplus diff --git a/source/modest/finder/thread.c b/source/modest/finder/thread.c index fa24bc8..49eb9d2 100644 --- a/source/modest/finder/thread.c +++ b/source/modest/finder/thread.c @@ -21,7 +21,12 @@ #include "modest/finder/thread.h" /* private functions */ +#ifndef MyCORE_BUILD_WITHOUT_THREADS static void modest_finder_thread_stream(mythread_id_t thread_id, void* arg); +#else +static void modest_finder_thread_stream_single(modest_finder_thread_t* finder_thread, mycss_selectors_list_t* selector_list); +#endif + static modest_finder_thread_context_t * modest_finder_thread_create_context(modest_finder_thread_t* finder_thread, size_t count); //static void modest_finder_thread_callback_found(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_list_t* selector_list, // mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec, void* ctx); @@ -34,6 +39,10 @@ modest_finder_thread_t * modest_finder_thread_create(void) mystatus_t modest_finder_thread_init(modest_finder_t* finder, modest_finder_thread_t* finder_thread, size_t thread_count) { +#ifdef MyCORE_BUILD_WITHOUT_THREADS + thread_count = 1; +#endif + finder_thread->finder = finder; /* objects for nodes */ @@ -133,7 +142,62 @@ void modest_finder_thread_collate_node(modest_t* modest, myhtml_tree_node_t* nod } } -#ifndef MyCORE_BUILD_WITHOUT_THREADS +#ifdef MyCORE_BUILD_WITHOUT_THREADS +mystatus_t modest_finder_thread_process(modest_t* modest, modest_finder_thread_t* finder_thread, + myhtml_tree_node_t* scope_node, mycss_selectors_list_t* selector_list) +{ + finder_thread->base_node = scope_node; + finder_thread->selector_list = selector_list; + + if(finder_thread->finder == NULL) + return MODEST_STATUS_ERROR; + + modest_finder_thread_stream_single(finder_thread, selector_list); + + /* calc result */ + modest_finder_thread_context_t* context = finder_thread->context_list; + myhtml_tree_node_t* node = scope_node; + + /* compare results */ + while(node) { + modest_finder_thread_entry_t* entry = context->entry; + + while(entry) { + if(entry->node == node) + { + if(entry->next) + entry->next->prev = entry->prev; + else + context->entry_last = entry->prev; + + if(entry->prev) + entry->prev->next = entry->next; + else + context->entry = entry->next; + + modest_finder_thread_collate_node(modest, node, entry); + } + + entry = entry->next; + } + + if(node->child) + node = node->child; + else { + while(node != scope_node && node->next == NULL) + node = node->parent; + + if(node == scope_node) + break; + + node = node->next; + } + } + + return MyCORE_STATUS_OK; +} + +#else /* end def MyCORE_BUILD_WITHOUT_THREADS */ mystatus_t modest_finder_thread_process(modest_t* modest, modest_finder_thread_t* finder_thread, myhtml_tree_node_t* scope_node, mycss_selectors_list_t* selector_list) { @@ -369,6 +433,24 @@ void modest_finder_thread_callback_found(modest_finder_t* finder, myhtml_tree_no } } +void modest_finder_thread_stream_single(modest_finder_thread_t* finder_thread, mycss_selectors_list_t* selector_list) +{ + modest_finder_thread_found_context_t found_ctx = {finder_thread, finder_thread->context_list}; + + while(selector_list) + { + for(size_t i = 0; i < selector_list->entries_list_length; i++) { + mycss_selectors_entries_list_t *entries = &selector_list->entries_list[i]; + mycss_selectors_specificity_t spec = entries->specificity; + + modest_finder_node_combinator_begin(finder_thread->finder, finder_thread->base_node, selector_list, + entries->entry, &spec, modest_finder_thread_callback_found, &found_ctx); + } + + selector_list = selector_list->next; + } +} + #ifndef MyCORE_BUILD_WITHOUT_THREADS void modest_finder_thread_stream(mythread_id_t thread_id, void* arg) { diff --git a/source/modest/finder/thread.h b/source/modest/finder/thread.h index 1e9b82e..e3bb405 100644 --- a/source/modest/finder/thread.h +++ b/source/modest/finder/thread.h @@ -91,7 +91,10 @@ modest_finder_thread_t * modest_finder_thread_destroy(modest_finder_thread_t* fi mystatus_t modest_finder_thread_process(modest_t* modest, modest_finder_thread_t* finder_thread, myhtml_tree_node_t* scope_node, mycss_selectors_list_t* selector_list); +#ifndef MyCORE_BUILD_WITHOUT_THREADS void modest_finder_thread_wait_for_all_done(modest_finder_thread_t* finder_thread); +#endif + bool modest_finder_thread_spec_is_up(modest_style_raw_specificity_t* spec_f, modest_style_raw_specificity_t* spec_t); #ifdef __cplusplus