From f79611d255626123e863cc5653b5285c01e69036 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 11 Aug 2006 12:42:06 +0000 Subject: Increased width for sender column in log message, and added additional check in pj_thread_register() git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@672 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/os_core_unix.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'pjlib/src/pj/os_core_unix.c') diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c index 1fa8d474..5fd630c1 100644 --- a/pjlib/src/pj/os_core_unix.c +++ b/pjlib/src/pj/os_core_unix.c @@ -43,12 +43,17 @@ #define THIS_FILE "os_core_unix.c" +#define SIGNATURE1 0xDEAFBEEF +#define SIGNATURE2 0xDEADC0DE + struct pj_thread_t { char obj_name[PJ_MAX_OBJ_NAME]; pthread_t thread; pj_thread_proc *proc; void *arg; + pj_uint32_t signature1; + pj_uint32_t signature2; pj_mutex_t *suspended_mutex; @@ -192,7 +197,7 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name, return PJ_EBUG; } - /* If a thread descriptor has been registered before, just return it. */ + /* Warn if this thread has been registered before */ if (pj_thread_local_get (thread_tls_id) != 0) { // 2006-02-26 bennylp: // This wouldn't work in all cases!. @@ -205,9 +210,18 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name, "thread")); } + /* On the other hand, also warn if the thread descriptor buffer seem to + * have been used to register other threads. + */ + pj_assert(thread->signature1 != SIGNATURE1 || + thread->signature2 != SIGNATURE2 || + (thread->thread == pthread_self())); + /* Initialize and set the thread entry. */ pj_bzero(desc, sizeof(struct pj_thread_t)); thread->thread = pthread_self(); + thread->signature1 = SIGNATURE1; + thread->signature2 = SIGNATURE2; if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1) pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name), @@ -217,8 +231,10 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name, "thr%p", (void*)thread->thread); rc = pj_thread_local_set(thread_tls_id, thread); - if (rc != PJ_SUCCESS) + if (rc != PJ_SUCCESS) { + pj_bzero(desc, sizeof(struct pj_thread_t)); return rc; + } #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 thread->stk_start = &stack_ptr; -- cgit v1.2.3