diff options
Diffstat (limited to 'source/myhtml/thread.c')
-rw-r--r-- | source/myhtml/thread.c | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/source/myhtml/thread.c b/source/myhtml/thread.c index f9238c5..9109dd6 100644 --- a/source/myhtml/thread.c +++ b/source/myhtml/thread.c @@ -18,6 +18,8 @@ #include "myhtml/thread.h" +#ifndef MyHTML_BUILD_WITHOUT_THREADS + #if defined(IS_OS_WINDOWS) /*********************************************************************************** * @@ -234,7 +236,7 @@ void myhtml_thread_nanosleep(const struct timespec *tomeout) } #endif /* !defined(IS_OS_WINDOWS) */ - +#endif /* MyHTML_BUILD_WITHOUT_THREADS */ /* * @@ -247,6 +249,21 @@ mythread_t * mythread_create(void) return calloc(1, sizeof(mythread_t)); } +#ifdef MyHTML_BUILD_WITHOUT_THREADS + +myhtml_status_t mythread_init(mythread_t *mythread, const char *sem_prefix, size_t thread_count, size_t queue_size) +{ + myhtml_status_t status; + mythread->queue = mythread_queue_create(4096, &status); + + if(mythread->queue == NULL) + return status; + + return MyHTML_STATUS_OK; +} + +#else /* MyHTML_BUILD_WITHOUT_THREADS */ + myhtml_status_t mythread_init(mythread_t *mythread, const char *sem_prefix, size_t thread_count, size_t queue_size) { mythread->batch_count = 0; @@ -303,6 +320,8 @@ myhtml_status_t mythread_init(mythread_t *mythread, const char *sem_prefix, size return MyHTML_STATUS_OK; } +#endif /* MyHTML_BUILD_WITHOUT_THREADS */ + void mythread_clean(mythread_t *mythread) { mythread->sys_last_error = 0; @@ -310,6 +329,8 @@ void mythread_clean(mythread_t *mythread) if(mythread->queue) mythread_queue_clean(mythread->queue); +#ifndef MyHTML_BUILD_WITHOUT_THREADS + size_t idx; for (idx = mythread->pth_list_root; idx < mythread->pth_list_length; idx++) { mythread->pth_list[idx].data.use = 0; @@ -318,13 +339,17 @@ void mythread_clean(mythread_t *mythread) for (idx = 0; idx < mythread->batch_count; idx++) { mythread->pth_list[( mythread->batch_first_id + idx )].data.use = idx; } + +#endif /* MyHTML_BUILD_WITHOUT_THREADS */ } -mythread_t * mythread_destroy(mythread_t *mythread, mybool_t self_destroy) +mythread_t * mythread_destroy(mythread_t *mythread, bool self_destroy) { if(mythread == NULL) return NULL; +#ifndef MyHTML_BUILD_WITHOUT_THREADS + myhtml_thread_attr_destroy(mythread); if(mythread->pth_list) { @@ -353,6 +378,8 @@ mythread_t * mythread_destroy(mythread_t *mythread, mybool_t self_destroy) mythread->sem_prefix_length = 0; } +#endif /* MyHTML_BUILD_WITHOUT_THREADS */ + if(mythread->queue) mythread_queue_destroy(mythread->queue); @@ -364,6 +391,8 @@ mythread_t * mythread_destroy(mythread_t *mythread, mybool_t self_destroy) return mythread; } +#ifndef MyHTML_BUILD_WITHOUT_THREADS + mythread_id_t _myhread_create_stream_raw(mythread_t *mythread, mythread_f func, void *work_func, myhtml_status_t *status, size_t total_count) { mythread->sys_last_error = 0; @@ -429,15 +458,15 @@ mythread_id_t myhread_create_batch(mythread_t *mythread, mythread_f func, myhtml size_t start = mythread->pth_list_length; *status = MyHTML_STATUS_OK; - mybool_t init_first = myfalse; + bool init_first = false; for (size_t i = 0; i < count; i++) { mythread_id_t curr_id = _myhread_create_stream_raw(mythread, func, mythread_function_batch, status, count); - if(init_first == myfalse) { + if(init_first == false) { mythread->batch_first_id = curr_id; - init_first = mytrue; + init_first = true; } if(*status) @@ -468,6 +497,8 @@ mythread_id_t myhread_create_batch(mythread_t *mythread, mythread_f func, myhtml return mythread->batch_first_id; } +#endif /* MyHTML_BUILD_WITHOUT_THREADS */ + // mythread queue functions mythread_queue_t * mythread_queue_create(size_t size, myhtml_status_t *status) { @@ -565,6 +596,16 @@ mythread_queue_node_t * mythread_queue_get_current_node(mythread_queue_t* queue) return &queue->nodes[queue->nodes_pos][queue->nodes_length]; } +mythread_queue_node_t * mythread_queue_get_first_node(mythread_queue_t* queue) +{ + return &queue->nodes[0][0]; +} + +size_t mythread_queue_count_used_node(mythread_queue_t* queue) +{ + return queue->nodes_uses; +} + mythread_queue_node_t * mythread_queue_node_malloc(mythread_queue_t* queue, const char* text, size_t begin, myhtml_status_t *status) { queue->nodes_length++; @@ -615,6 +656,19 @@ mythread_queue_node_t * mythread_queue_node_malloc(mythread_queue_t* queue, cons return qnode; } +#ifdef MyHTML_BUILD_WITHOUT_THREADS + +void mythread_stream_quit_all(mythread_t *mythread) {} +void mythread_batch_quit_all(mythread_t *mythread) {} +void mythread_stream_pause_all(mythread_t *mythread) {} +void mythread_batch_pause_all(mythread_t *mythread) {} +void mythread_resume_all(mythread_t *mythread) {} +void mythread_wait_all(mythread_t *mythread) {} +void mythread_function_batch(void *arg) {} +void mythread_function_stream(void *arg) {} + +#else /* MyHTML_BUILD_WITHOUT_THREADS */ + // mythread functions void mythread_stream_quit_all(mythread_t *mythread) { @@ -747,4 +801,6 @@ void mythread_function_stream(void *arg) while (1); } +#endif /* MyHTML_BUILD_WITHOUT_THREADS */ + |