summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-08-11 12:42:06 +0000
committerBenny Prijono <bennylp@teluu.com>2006-08-11 12:42:06 +0000
commitf79611d255626123e863cc5653b5285c01e69036 (patch)
tree0e6b856d7820b74504e193ccbcb378b2e861fdab /pjlib
parentd09368727007e87aaf50271297bfc1ce0d1a47a7 (diff)
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
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/src/pj/log.c2
-rw-r--r--pjlib/src/pj/os_core_unix.c20
2 files changed, 19 insertions, 3 deletions
diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c
index e81fe29f..d1bef5c4 100644
--- a/pjlib/src/pj/log.c
+++ b/pjlib/src/pj/log.c
@@ -115,7 +115,7 @@ PJ_DEF(void) pj_log( const char *sender, int level,
pre += pj_utoa_pad(ptime.msec, pre, 3, '0');
}
if (log_decor & PJ_LOG_HAS_SENDER) {
- enum { SENDER_WIDTH = 12 };
+ enum { SENDER_WIDTH = 14 };
int sender_len = strlen(sender);
*pre++ = ' ';
if (sender_len <= SENDER_WIDTH) {
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;