commit 6663dcd6c28d26681d8363b1f84febff26b96ae2
parent 8bf9f72a28d5544361b6351dad6d82e720274fcd
Author: klewer-martin <martin.cachari@gmail.com>
Date: Fri, 15 Apr 2022 01:26:41 -0300
Function wait_main_thread() deprecated
Diffstat:
4 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/main.c b/main.c
@@ -9,6 +9,8 @@
#define WELCOME_MSG_TIME 5
+/* TODO: support restart even if the sorting algorithm didn't finish */
+
void check_events(Drw *, SAV *);
void *routine_wrapper(void *);
@@ -40,6 +42,7 @@ int main (void) {
/* selecting the sorting algorithms */
sav->sort_algo = QUICK_SORT;
+ /* TODO: this thread should be called if the user wants to begin sorting the array */
/* start sorting thread */
pthread_create(&p1, NULL, &routine_wrapper, (void *)sav);
@@ -50,15 +53,14 @@ int main (void) {
/* main loop */
while(sav->status != STOP) {
check_events(drw, sav);
+ drw_array_graph(drw, sav);
+ drw_status_bar(drw, sav);
+ SDL_RenderPresent(drw->rend);
if(sav->status == WELCOME)
if((((tc = clock()) - ti) / CLOCKS_PER_SEC) > WELCOME_MSG_TIME)
sav->status = START;
- drw_array_graph(drw, sav);
- drw_status_bar(drw, sav);
- SDL_RenderPresent(drw->rend);
-
if((sav->sort_status == SORTED) && (sav->status == RESTART)) {
/* this state can only be achived if p1 ended */
shuffle(sav->arr);
@@ -69,6 +71,7 @@ int main (void) {
pthread_create(&p1, NULL, &routine_wrapper, (void *)sav);
}
}
+
end:
pthread_join(p1, NULL);
diff --git a/sort.c b/sort.c
@@ -142,11 +142,8 @@ void merge(SAV *sav, int low, int middle, int high) {
}
end:
- while(i < n1)
- sav->arr->v[k++] = B[i++];
-
- while (j < n2)
- sav->arr->v[k++] = C[j++];
+ while(i < n1) sav->arr->v[k++] = B[i++];
+ while(j < n2) sav->arr->v[k++] = C[j++];
}
void merge_sort(SAV *sav, int low, int high) {
diff --git a/sort.h b/sort.h
@@ -24,7 +24,6 @@ static void (*sort_handler[ALGORITHMS_COUNT])(SAV *) = {
&quick_sort_wrapper
};
-/* static const char *algo_strings[ALGORITHMS_COUNT]; */
static const char *algo_strings[ALGORITHMS_COUNT] = {
"bubble",
"insertion",
diff --git a/util.c b/util.c
@@ -1,12 +1,5 @@
#include "util.h"
-void wait_main_thread(status_t *st) {
- if((*st != STOP) && (*st != PAUSE)) *st = UPDATE;
-
- /* wait 'til main thread changes st value to RUN */
- while((*st == UPDATE) || (*st == PAUSE));
-}
-
void end(const char *msg) {
fprintf(stderr, "%s\n", msg);
exit(1);