diff options
author | Not Zed <NotZed@Ximian.com> | 2002-05-06 19:46:36 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2002-05-06 19:46:36 +0800 |
commit | 95f58c95b6915c7003a52a652fa6aff2bb86b613 (patch) | |
tree | 7b45a7441f1abfe2da6879ce29840d7702f69dc3 | |
parent | 7719a8ad66b24d15a511e1b6c648dda4e36a6973 (diff) | |
download | gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.tar gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.tar.gz gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.tar.bz2 gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.tar.lz gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.tar.xz gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.tar.zst gsoc2013-evolution-95f58c95b6915c7003a52a652fa6aff2bb86b613.zip |
Destroy our mutex too. (e_thread_new): Add thread to a new list of all
2002-05-06 Not Zed <NotZed@Ximian.com>
* e-msgport.c (e_thread_destroy): Destroy our mutex too.
(e_thread_new): Add thread to a new list of all threads.
(e_thread_destroy): Remove thread from list of all threads.
(e_thread_busy): New function, returh true if we're busy somewhere
processing work.
svn path=/trunk/; revision=16683
-rw-r--r-- | e-util/ChangeLog | 8 | ||||
-rw-r--r-- | e-util/e-msgport.c | 46 | ||||
-rw-r--r-- | e-util/e-msgport.h | 1 |
3 files changed, 55 insertions, 0 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 4b76ec6458..e6c3ddb2b8 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,11 @@ +2002-05-06 Not Zed <NotZed@Ximian.com> + + * e-msgport.c (e_thread_destroy): Destroy our mutex too. + (e_thread_new): Add thread to a new list of all threads. + (e_thread_destroy): Remove thread from list of all threads. + (e_thread_busy): New function, returh true if we're busy somewhere + processing work. + 2002-04-19 Jeffrey Stedfast <fejj@ximian.com> * e-passwords.c (e_passwords_get_password): Don't leak the base64 diff --git a/e-util/e-msgport.c b/e-util/e-msgport.c index 2bb4311b18..e04fa8dc9a 100644 --- a/e-util/e-msgport.c +++ b/e-util/e-msgport.c @@ -248,6 +248,9 @@ struct _thread_info { }; struct _EThread { + struct _EThread *next; + struct _EThread *prev; + EMsgPort *server_port; EMsgPort *reply_port; pthread_mutex_t mutex; @@ -268,6 +271,10 @@ struct _EThread { void *lost_data; }; +/* All active threads */ +static EDList ethread_list = E_DLIST_INITIALISER(ethread_list); +static pthread_mutex_t ethread_lock = PTHREAD_MUTEX_INITIALIZER; + #define E_THREAD_NONE ((pthread_t)~0) #define E_THREAD_QUIT_REPLYPORT ((struct _EMsgPort *)~0) @@ -317,6 +324,10 @@ EThread *e_thread_new(e_thread_t type) e->id = E_THREAD_NONE; e->queue_limit = INT_MAX; + pthread_mutex_lock(ðread_lock); + e_dlist_addtail(ðread_list, (EDListNode *)e); + pthread_mutex_unlock(ðread_lock); + return e; } @@ -393,6 +404,11 @@ void e_thread_destroy(EThread *e) return; } + pthread_mutex_lock(ðread_lock); + e_dlist_remove((EDListNode *)e); + pthread_mutex_unlock(ðread_lock); + + pthread_mutex_destroy(&e->mutex); e_msgport_destroy(e->server_port); g_free(e); } @@ -437,6 +453,36 @@ void e_thread_set_msg_received(EThread *e, EThreadFunc received, void *data) pthread_mutex_unlock(&e->mutex); } +/* find out if we're busy doing any work, e==NULL, check for all work */ +int e_thread_busy(EThread *e) +{ + int busy = FALSE; + + if (e == NULL) { + pthread_mutex_lock(ðread_lock); + e = (EThread *)ethread_list.head; + while (e->next && !busy) { + busy = e_thread_busy(e); + e = e->next; + } + pthread_mutex_unlock(ðread_lock); + } else { + pthread_mutex_lock(&e->mutex); + switch (e->type) { + case E_THREAD_QUEUE: + case E_THREAD_DROP: + busy = e->waiting != 1 && e->id != E_THREAD_NONE; + break; + case E_THREAD_NEW: + busy = e->waiting != g_list_length(e->id_list); + break; + } + pthread_mutex_unlock(&e->mutex); + } + + return busy; +} + static void thread_destroy_msg(EThread *e, EMsg *m) { diff --git a/e-util/e-msgport.h b/e-util/e-msgport.h index d181ac7fb7..03dc514b07 100644 --- a/e-util/e-msgport.h +++ b/e-util/e-msgport.h @@ -64,6 +64,7 @@ void e_thread_set_msg_destroy(EThread *e, EThreadFunc destroy, void *data); void e_thread_set_reply_port(EThread *e, EMsgPort *reply_port); void e_thread_set_msg_received(EThread *e, EThreadFunc received, void *data); void e_thread_put(EThread *e, EMsg *msg); +int e_thread_busy(EThread *e); /* sigh, another mutex interface, this one allows different mutex types, portably */ typedef struct _EMutex EMutex; |