Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2ec50820 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Don't use mthread for the moment, use to much cpu

parent 2caaa0bc
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!67Resolve "Thread pool"
#pragma once #pragma once
#include <lektor/define.h> #include <lektor/define.h>
#include <mthread/mthread.h> #include <pthread.h>
#include <sys/types.h> #include <sys/types.h>
struct poller_thread { struct poller_thread {
...@@ -9,16 +9,16 @@ struct poller_thread { ...@@ -9,16 +9,16 @@ struct poller_thread {
volatile unsigned int input_len; volatile unsigned int input_len;
volatile unsigned int input_size; volatile unsigned int input_size;
volatile void *volatile *volatile input_cells; volatile void *volatile *volatile input_cells;
mthread_mutex_t input_lock; pthread_mutex_t input_lock;
mthread_t th; pthread_t th;
unsigned int initial_size; unsigned int initial_size;
/* The output pool. */ /* The output pool. */
volatile unsigned int output_len; volatile unsigned int output_len;
volatile unsigned int output_size; volatile unsigned int output_size;
volatile void *volatile *volatile output_cells; volatile void *volatile *volatile output_cells;
mthread_mutex_t output_lock; pthread_mutex_t output_lock;
}; };
struct poller_thread_arg { struct poller_thread_arg {
......
...@@ -57,7 +57,7 @@ main(int argc, char *argv[]) ...@@ -57,7 +57,7 @@ main(int argc, char *argv[])
normal_launch: normal_launch:
LOG_INFO("Lektor launched by user %s (shell: %s, home: %s)", pw->pw_name, pw->pw_shell, pw->pw_dir); LOG_INFO("Lektor launched by user %s (shell: %s, home: %s)", pw->pw_name, pw->pw_shell, pw->pw_dir);
mthread_init(); // mthread_init();
return lkt_listen(); return lkt_listen();
} }
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
static struct poller_thread repo_thread; static struct poller_thread repo_thread;
static mthread_mutex_t mtx = MTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static volatile int init = 0; static volatile int init = 0;
static volatile int stop = 0; static volatile int stop = 0;
static volatile int all_json = 0; static volatile int all_json = 0;
...@@ -22,14 +22,14 @@ int ...@@ -22,14 +22,14 @@ int
repo_join_thread(void) repo_join_thread(void)
{ {
int ret = 1; int ret = 1;
RETURN_IF(mthread_mutex_lock(&mtx), "Failed to lock mutex", 3); RETURN_IF(pthread_mutex_lock(&mtx), "Failed to lock mutex", 3);
GOTO_UNLESS(init, "Repo thread no launched, can't join", error); GOTO_UNLESS(init, "Repo thread no launched, can't join", error);
stop = 1; stop = 1;
GOTO_IF(mthread_join(repo_thread.th, NULL), "Failed to join repo thread", error); GOTO_IF(pthread_join(repo_thread.th, NULL), "Failed to join repo thread", error);
LOG_INFO("%s", "repo thread joined"); LOG_INFO("%s", "repo thread joined");
ret = 0; ret = 0;
error: error:
RETURN_IF(mthread_mutex_unlock(&mtx), "Failed to unlock mutex", 3); RETURN_IF(pthread_mutex_unlock(&mtx), "Failed to unlock mutex", 3);
return ret; return ret;
} }
...@@ -113,7 +113,7 @@ __repo_thread_function(struct poller_thread_arg *arg) ...@@ -113,7 +113,7 @@ __repo_thread_function(struct poller_thread_arg *arg)
LOG_INFO("%s", "Starting the repo thread"); LOG_INFO("%s", "Starting the repo thread");
for (;;) { for (;;) {
GOTO_IF(mthread_mutex_lock(&mtx), "Failed to lock mutex", end_loop); GOTO_IF(pthread_mutex_lock(&mtx), "Failed to lock mutex", end_loop);
if (all_json) { if (all_json) {
repo_get_alljson_sync(repo, &json); repo_get_alljson_sync(repo, &json);
...@@ -122,7 +122,7 @@ __repo_thread_function(struct poller_thread_arg *arg) ...@@ -122,7 +122,7 @@ __repo_thread_function(struct poller_thread_arg *arg)
} }
if (stop) { if (stop) {
if (mthread_mutex_unlock(&mtx)) if (pthread_mutex_unlock(&mtx))
LOG_ERROR("Failed to unlock mutex: %s", strerror(errno)); LOG_ERROR("Failed to unlock mutex: %s", strerror(errno));
break; break;
} }
...@@ -178,7 +178,7 @@ try_later: ...@@ -178,7 +178,7 @@ try_later:
LOG_ERROR("%s", "Failed to get the head of the input list"); LOG_ERROR("%s", "Failed to get the head of the input list");
end_loop: end_loop:
mthread_yield(); sched_yield();
sleep(1); sleep(1);
} }
...@@ -226,8 +226,8 @@ err: ...@@ -226,8 +226,8 @@ err:
inline int inline int
repo_get_allid_async(void) repo_get_allid_async(void)
{ {
RETURN_IF(mthread_mutex_lock(&mtx), "Failed to lock mutex", 3); RETURN_IF(pthread_mutex_lock(&mtx), "Failed to lock mutex", 3);
all_json = 1; all_json = 1;
RETURN_IF(mthread_mutex_unlock(&mtx), "Failed to lock mutex", 3); RETURN_IF(pthread_mutex_unlock(&mtx), "Failed to lock mutex", 3);
return 0; return 0;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <common/common.h> #include <common/common.h>
#include <lektor/thread.h> #include <lektor/thread.h>
#include <mthread/mthread.h> #include <pthread.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
...@@ -29,8 +29,8 @@ int ...@@ -29,8 +29,8 @@ int
lkt_th_new(struct poller_thread *th, unsigned int init_sizes, lkt_th_new(struct poller_thread *th, unsigned int init_sizes,
void *(*func)(struct poller_thread_arg *), void *args) void *(*func)(struct poller_thread_arg *), void *args)
{ {
mthread_mutex_t mtx1 = MTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mtx1 = PTHREAD_MUTEX_INITIALIZER;
mthread_mutex_t mtx2 = MTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mtx2 = PTHREAD_MUTEX_INITIALIZER;
struct poller_thread th_ = { struct poller_thread th_ = {
.initial_size = init_sizes, .initial_size = init_sizes,
.input_lock = mtx1, .input_lock = mtx1,
...@@ -52,7 +52,7 @@ lkt_th_new(struct poller_thread *th, unsigned int init_sizes, ...@@ -52,7 +52,7 @@ lkt_th_new(struct poller_thread *th, unsigned int init_sizes,
__args->arg = args; __args->arg = args;
__args->arg->self = th; __args->arg->self = th;
if(!mthread_create(&(th->th), NULL, __start, __args)) { if(!pthread_create(&(th->th), NULL, __start, __args)) {
LOG_INFO_SCT("THREAD", "%s", "Create a new poller thread"); LOG_INFO_SCT("THREAD", "%s", "Create a new poller thread");
return 0; return 0;
} }
...@@ -75,7 +75,7 @@ out_of_memory: ...@@ -75,7 +75,7 @@ out_of_memory:
int int
lkt_th_join(struct poller_thread *th, void **ret) lkt_th_join(struct poller_thread *th, void **ret)
{ {
int sta = mthread_join(th->th, ret); int sta = pthread_join(th->th, ret);
if (sta) if (sta)
LOG_ERROR("%s", "Failed to join thread"); LOG_ERROR("%s", "Failed to join thread");
...@@ -94,12 +94,12 @@ lkt_th_join(struct poller_thread *th, void **ret) ...@@ -94,12 +94,12 @@ lkt_th_join(struct poller_thread *th, void **ret)
static inline int static inline int
th_append(unsigned int *len, unsigned int *size, void ***cells, th_append(unsigned int *len, unsigned int *size, void ***cells,
mthread_mutex_t *lock, void *ptr) pthread_mutex_t *lock, void *ptr)
{ {
void *new; void *new;
int ret = 0; int ret = 0;
GOTO_IF(mthread_mutex_lock(lock), "Failed to lock", end); GOTO_IF(pthread_mutex_lock(lock), "Failed to lock", end);
if (*len == *size) { if (*len == *size) {
new = realloc((void *) *cells, (*len + *size) * sizeof(void *)); new = realloc((void *) *cells, (*len + *size) * sizeof(void *));
...@@ -117,16 +117,16 @@ th_append(unsigned int *len, unsigned int *size, void ***cells, ...@@ -117,16 +117,16 @@ th_append(unsigned int *len, unsigned int *size, void ***cells,
(*cells)[(*len)++] = ptr; (*cells)[(*len)++] = ptr;
ret = 0; ret = 0;
end: end:
RETURN_IF(mthread_mutex_unlock(lock), "Failed to lock", 1); RETURN_IF(pthread_mutex_unlock(lock), "Failed to lock", 1);
return ret; return ret;
} }
static inline int static inline int
th_pop(unsigned int *len, void **cells, mthread_mutex_t *lock, void **ptr) th_pop(unsigned int *len, void **cells, pthread_mutex_t *lock, void **ptr)
{ {
int ret = 1; int ret = 1;
GOTO_IF(mthread_mutex_lock(lock), "Failed to lock", end); GOTO_IF(pthread_mutex_lock(lock), "Failed to lock", end);
if (*len > 0) if (*len > 0)
*ptr = cells[--(*len)]; *ptr = cells[--(*len)];
...@@ -135,15 +135,15 @@ th_pop(unsigned int *len, void **cells, mthread_mutex_t *lock, void **ptr) ...@@ -135,15 +135,15 @@ th_pop(unsigned int *len, void **cells, mthread_mutex_t *lock, void **ptr)
ret = 0; ret = 0;
end: end:
RETURN_IF(mthread_mutex_unlock(lock), "Failed to lock", 1); RETURN_IF(pthread_mutex_unlock(lock), "Failed to lock", 1);
return ret; return ret;
} }
static inline int static inline int
th_head(unsigned int len, void **cells, mthread_mutex_t *lock, void **ptr) th_head(unsigned int len, void **cells, pthread_mutex_t *lock, void **ptr)
{ {
int ret = 1; int ret = 1;
GOTO_IF(mthread_mutex_lock(lock), "Failed to lock", end); GOTO_IF(pthread_mutex_lock(lock), "Failed to lock", end);
if (len > 0) if (len > 0)
*ptr = cells[len - 1]; *ptr = cells[len - 1];
...@@ -152,7 +152,7 @@ th_head(unsigned int len, void **cells, mthread_mutex_t *lock, void **ptr) ...@@ -152,7 +152,7 @@ th_head(unsigned int len, void **cells, mthread_mutex_t *lock, void **ptr)
ret = 0; ret = 0;
end: end:
RETURN_IF(mthread_mutex_unlock(lock), "Failed to lock", 1); RETURN_IF(pthread_mutex_unlock(lock), "Failed to lock", 1);
return ret; return ret;
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter