From: Sebastian B. <sb...@us...> - 2013-12-13 21:49:47
|
Update of /cvsroot/simplemail/simplemail/gtk In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv25545/gtk Modified Files: subthreads.c Log Message: Store threads in a thread list. Index: subthreads.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/gtk/subthreads.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- subthreads.c 13 Dec 2013 21:40:11 -0000 1.14 +++ subthreads.c 13 Dec 2013 21:49:45 -0000 1.15 @@ -29,6 +29,7 @@ #include <glib.h> #include <gtk/gtk.h> +#include "lists.h" #include "support_indep.h" #include "subthreads.h" @@ -40,6 +41,12 @@ /* Sockets for IPC */ static int sockets[2]; +/** List of all threads */ +static struct list thread_list; + +/** Mutex for accessing thread list */ +static GMutex *thread_list_mutex; + struct ipc_message { int async; @@ -55,6 +62,7 @@ struct thread_s { + struct node node; GThread *thread; }; @@ -63,6 +71,8 @@ if (!g_thread_supported ()) g_thread_init (NULL); if (!(thread_cond = g_cond_new())) return 0; if (!(thread_mutex = g_mutex_new())) return 0; + list_init(&thread_list); + if (!(thread_list_mutex = g_mutex_new())) return 0; socketpair(PF_LOCAL,SOCK_DGRAM,0,sockets); @@ -71,6 +81,7 @@ void cleanup_threads(void) { + g_mutex_free(thread_list_mutex); } int thread_parent_task_can_contiue(void) @@ -121,13 +132,19 @@ thread_t thread_add(char *thread_name, int (*entry)(void *), void *eudata) { struct thread_s *t; + if (!(t = malloc(sizeof(*t)))) return NULL; + memset(t,0,sizeof(*t)); if ((t->thread = g_thread_create((GThreadFunc)entry,eudata,TRUE,NULL))) { g_mutex_lock(thread_mutex); g_cond_wait(thread_cond,thread_mutex); g_mutex_unlock(thread_mutex); + + g_mutex_lock(thread_list_mutex); + list_insert_tail(&thread_list, &t->node); + g_mutex_unlock(thread_list_mutex); return t; } return NULL; |