diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index 6b8ccfd4ad9d866d1f6692854bc6eecc04f9120b..6ec3defe8b96ce5667fc47e791bc5cc82ecb62b1 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -147,8 +147,7 @@ sdl_thread__(struct poller_thread_arg *arg) LOG_INFO_SCT("WINDOW", "%s", "Started SDL thread"); loop: - if (SDL_PollEvent(&event)) - sched_yield(); + SDL_WaitEvent(&event); switch (event.type) { case SDL_QUIT: @@ -207,6 +206,8 @@ loop: SDL_GL_SwapWindow((SDL_Window *) sdl2->window); redraw = 0; } + + sched_yield(); goto loop; /* A loop without indentation. */ } diff --git a/src/mthread/mthread.c b/src/mthread/mthread.c index 898f840162173a99ee8d73b0f5fe9487daac7454..7f9dae67d25ae2a7e2469a2e98ebb680397dd3c7 100644 --- a/src/mthread/mthread.c +++ b/src/mthread/mthread.c @@ -9,7 +9,7 @@ #endif #ifdef TWO_LEVEL -#define MTHREAD_LWP 4 +#define MTHREAD_LWP 3 #else #define MTHREAD_LWP 1 #endif @@ -157,6 +157,8 @@ mthread_work_take(mthread_virtual_processor_t *vp) void __mthread_yield(mthread_virtual_processor_t *vp) { + sched_yield(); + struct mthread_s *current = (struct mthread_s *)vp->current; struct mthread_s *next = mthread_remove_first(&(vp->ready_list)); @@ -198,7 +200,6 @@ __mthread_yield(mthread_virtual_processor_t *vp) mthread_spinlock_unlock(vp->p); vp->p = NULL; } - } static void diff --git a/src/net/listen.c b/src/net/listen.c index 6fac8d90cf9ec101a37768a5f4ecf56ad96fe29d..9a6a226d9ee4ce6bfc0da82ba0a88919b54afa94 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -10,6 +10,7 @@ #include <sqlite3.h> +#include <sched.h> #include <assert.h> #include <arpa/inet.h> #include <errno.h> @@ -479,9 +480,9 @@ failure: } if (host) - LOG_ERROR_SCT("NETWORK", "Listening on %s:%s", host, port); + LOG_INFO_SCT("NETWORK", "Listening on %s:%s", host, port); else - LOG_ERROR_SCT("NETWORK", "Listening on port %s", port); + LOG_INFO_SCT("NETWORK", "Listening on port %s", port); return fd; } diff --git a/src/repo/async.c b/src/repo/async.c index d883b4ce515462a637295f7b49792724001ee736..0befc290a96332831bb553a1030b1498345242e9 100644 --- a/src/repo/async.c +++ b/src/repo/async.c @@ -178,6 +178,7 @@ try_later: LOG_ERROR("%s", "Failed to get the head of the input list"); end_loop: + mthread_yield(); sleep(1); } diff --git a/src/thread.c b/src/thread.c index 82112f27e2311403e46147250d14bebd6676f373..31fe55592ad5e40cf9c553e12cf945c406c1575a 100644 --- a/src/thread.c +++ b/src/thread.c @@ -29,7 +29,6 @@ int lkt_th_new(struct poller_thread *th, unsigned int init_sizes, void *(*func)(struct poller_thread_arg *), void *args) { - int ret = 1; mthread_mutex_t mtx1 = MTHREAD_MUTEX_INITIALIZER; mthread_mutex_t mtx2 = MTHREAD_MUTEX_INITIALIZER; struct poller_thread th_ = { @@ -53,16 +52,16 @@ lkt_th_new(struct poller_thread *th, unsigned int init_sizes, __args->arg = args; __args->arg->self = th; - ret = mthread_create(&(th->th), NULL, __start, __args); - - if (ret) - goto end; + if(!mthread_create(&(th->th), NULL, __start, __args)) { + LOG_INFO_SCT("THREAD", "%s", "Create a new poller thread"); + return 0; + } -end: - fprintf(stderr, " %c lkt_th_new: %s\n", - ret ? '!' : '*', - ret ? "Failed to create a new thread" : "Created a new thread"); - return ret; + else { +error: + LOG_ERROR_SCT("THREAD", "%s", "Failed to create a poller thread"); + return 1; + } out_of_memory: LOG_ERROR_SCT("MEMORY", "%s", "Out of memory"); @@ -70,8 +69,7 @@ out_of_memory: free((void *) th_.input_cells); if (th_.output_cells) free((void *) th_.output_cells); - ret = errno = ENOMEM; - goto end; + goto error; } int