📄 ptt_glibc-2.4.patch
字号:
if (IS_DETACHED (pd))+ { /* We cannot wait for the thread. */+#ifdef PTT_LIBPTHREAD+ /* THREAD_JOIN_OUT */+ PTT_TRACE (PTT_LEVEL_THREAD_IO, TR_THREAD_14, EINVAL);+#endif /* PTT_LIBPTHREAD */ return EINVAL;+ } self = THREAD_SELF; if (pd == self@@ -55,6 +72,7 @@ && (pd->cancelhandling & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK | TERMINATED_BITMASK)) == 0))+ { /* This is a deadlock situation. The threads are waiting for each other to finish. Note that this is a "may" error. To be 100% sure we catch this error we would have to lock the data@@ -62,15 +80,26 @@ two threads are really caught in this situation they will deadlock. It is the programmer's problem to figure this out. */+#ifdef PTT_LIBPTHREAD+ /* THREAD_JOIN_OUT */+ PTT_TRACE (PTT_LEVEL_THREAD_IO, TR_THREAD_14, EDEADLK); +#endif /* PTT_LIBPTHREAD */ return EDEADLK;+ } /* Wait for the thread to finish. If it is already locked something is wrong. There can only be one waiter. */ if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid, self, NULL), 0))+ { /* There is already somebody waiting for the thread. */+#ifdef PTT_LIBPTHREAD+ /* THREAD_JOIN_OUT */+ PTT_TRACE (PTT_LEVEL_THREAD_IO, TR_THREAD_14, EINVAL);+#endif /* PTT_LIBPTHREAD */ return EINVAL;+ } /* During the wait we change to asynchronous cancellation. If we@@ -82,10 +111,20 @@ int oldtype = CANCEL_ASYNC (); +#ifdef PTT_LIBPTHREAD+ /* THREAD_STATE_WAIT */+ PTT_TRACE (PTT_LEVEL_THREAD, TR_THREAD_2);+#endif /* PTT_LIBPTHREAD */+ /* Wait for the child. */ lll_wait_tid (pd->tid); +#ifdef PTT_LIBPTHREAD+ /* THREAD_STATE_WAKE, THREAD_JOIN */+ PTT_TRACE (PTT_LEVEL_THREAD, TR_THREAD_15, pd, pd->result);+#endif /* PTT_LIBPTHREAD */+ /* Restore cancellation mode. */ CANCEL_RESET (oldtype); @@ -104,5 +143,9 @@ /* Free the TCB. */ __free_tcb (pd); +#ifdef PTT_LIBPTHREAD+ /* THREAD_JOIN_OUT */+ PTT_TRACE (PTT_LEVEL_THREAD_IO, TR_THREAD_14, 0);+#endif /* PTT_LIBPTHREAD */ return 0; }diff -Naur ori_glibc/nptl/pthread_mutex_destroy.c new_glibc/nptl/pthread_mutex_destroy.c--- ori_glibc/nptl/pthread_mutex_destroy.c 2006-04-04 15:07:36.000000000 +0200+++ new_glibc/nptl/pthread_mutex_destroy.c 2006-05-10 12:42:04.000000000 +0200@@ -25,6 +25,11 @@ __pthread_mutex_destroy (mutex) pthread_mutex_t *mutex; {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_DESTROY_IN */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_1, mutex);+#endif /* PTT_LIBPTHREAD */+ if (mutex->__data.__nusers != 0) { if ((mutex->__data.__kind & PTHREAD_MUTEX_ROBUST_PRIVATE_NP) != 0@@ -32,6 +37,10 @@ && mutex->__data.__nusers == 1) goto dead_robust_mutex; +#ifdef PTT_LIBPTHREAD+ /* MUTEX_DESTROY_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_2, mutex, EBUSY);+#endif /* PTT_LIBPTHREAD */ return EBUSY; } @@ -39,6 +48,10 @@ dead_robust_mutex: mutex->__data.__kind = -1; +#ifdef PTT_LIBPTHREAD+ /* MUTEX_DESTROY, MUTEX_DESTROY_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_3, mutex, mutex, 0);+#endif /* PTT_LIBPTHREAD */ return 0; } strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)diff -Naur ori_glibc/nptl/pthread_mutex_init.c new_glibc/nptl/pthread_mutex_init.c--- ori_glibc/nptl/pthread_mutex_init.c 2006-04-04 15:07:38.000000000 +0200+++ new_glibc/nptl/pthread_mutex_init.c 2006-05-10 11:45:59.000000000 +0200@@ -36,6 +36,17 @@ const pthread_mutexattr_t *mutexattr; { const struct pthread_mutexattr *imutexattr;+ +#ifdef PTT_LIBPTHREAD+ /* MUTEX_INIT_IN */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_4, mutex, mutexattr); ++ if(sizeof (pthread_mutex_t) > __SIZEOF_PTHREAD_MUTEX_T)+ {+ /* MUTEX_INIT_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_5, mutex, -1);+ }+#endif /* PTT_LIBPTHREAD */ assert (sizeof (pthread_mutex_t) <= __SIZEOF_PTHREAD_MUTEX_T); @@ -88,6 +99,12 @@ // mutex->__spins = 0; already done by memset // mutex->__next = NULL; already done by memset +#ifdef PTT_LIBPTHREAD+ /* MUTEX_INIT, MUTEX_INIT_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_6, mutex, 0, 0,+ mutex->__data.__kind, mutex, 0);+#endif /* PTT_LIBPTHREAD */+ return 0; } strong_alias (__pthread_mutex_init, pthread_mutex_init)diff -Naur ori_glibc/nptl/pthread_mutex_lock.c new_glibc/nptl/pthread_mutex_lock.c--- ori_glibc/nptl/pthread_mutex_lock.c 2006-04-04 15:07:41.000000000 +0200+++ new_glibc/nptl/pthread_mutex_lock.c 2006-05-11 09:19:11.000000000 +0200@@ -35,6 +35,17 @@ __pthread_mutex_lock (mutex) pthread_mutex_t *mutex; {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_IN */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_7, mutex);++ if(sizeof (mutex->__size) < sizeof (mutex->__data))+ {+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, -1); + }+#endif /* PTT_LIBPTHREAD */+ assert (sizeof (mutex->__size) >= sizeof (mutex->__data)); int oldval;@@ -50,34 +61,84 @@ { /* Just bump the counter. */ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))+ { /* Overflow of the counter. */+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EAGAIN);+#endif /* PTT_LIBPTHREAD */ return EAGAIN;+ } ++mutex->__data.__count; +#ifdef PTT_LIBPTHREAD+ /* MUTEX_COUNT_INC, MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_9, mutex,+ mutex->__data.__count, mutex, 0);+#endif /* PTT_LIBPTHREAD */+ return 0; } /* We have to get the mutex. */+#ifdef PTT_LIBPTHREAD+ /* MUTEX_STATE_REQUIRE, THREAD_STATE_WAIT_MUTEX */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_10, mutex, mutex->__data.__lock,+ mutex);+#endif /* PTT_LIBPTHREAD */+ LLL_MUTEX_LOCK (mutex->__data.__lock); +#ifdef PTT_LIBPTHREAD+ /* THREAD_STATE_WAKE_MUTEX, MUTEX_STATE_TAKEN */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_11, mutex, mutex,+ mutex->__data.__lock);+#endif /* PTT_LIBPTHREAD */+ assert (mutex->__data.__owner == 0); mutex->__data.__count = 1;+ +#ifdef PTT_LIBPTHREAD+ /* MUTEX_COUNT_INC */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_12, mutex, mutex->__data.__count);+#endif /* PTT_LIBPTHREAD */+ break; /* Error checking mutex. */ case PTHREAD_MUTEX_ERRORCHECK_NP: /* Check whether we already hold the mutex. */ if (__builtin_expect (mutex->__data.__owner == id, 0))+ {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EDEADLK);+#endif /* PTT_LIBPTHREAD */ return EDEADLK;+ } /* FALLTHROUGH */ case PTHREAD_MUTEX_TIMED_NP: simple: /* Normal mutex. */+ +#ifdef PTT_LIBPTHREAD+ /* MUTEX_STATE_REQUIRE, THREAD_STATE_WAIT_MUTEX */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_10, mutex, mutex->__data.__lock,+ mutex);+#endif /* PTT_LIBPTHREAD */+ LLL_MUTEX_LOCK (mutex->__data.__lock); assert (mutex->__data.__owner == 0);+ +#ifdef PTT_LIBPTHREAD+ /* THREAD_STATE_WAKE_MUTEX, MUTEX_STATE_TAKEN */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_11, mutex, mutex,+ mutex->__data.__lock);+#endif /* PTT_LIBPTHREAD */+ break; case PTHREAD_MUTEX_ADAPTIVE_NP:@@ -93,7 +154,20 @@ { if (cnt++ >= max_cnt) {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_STATE_REQUIRE, THREAD_STATE_WAIT_MUTEX */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_10, mutex,+ mutex->__data.__lock, mutex);+#endif /* PTT_LIBPTHREAD */+ LLL_MUTEX_LOCK (mutex->__data.__lock);+ +#ifdef PTT_LIBPTHREAD+ /* THREAD_STATE_WAKE_MUTEX, MUTEX_STATE_TAKEN */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_11, mutex, mutex,+ mutex->__data.__lock); +#endif /* PTT_LIBPTHREAD */+ break; } @@ -146,6 +220,10 @@ --mutex->__data.__nusers; #endif +#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EOWNERDEAD);+#endif /* PTT_LIBPTHREAD */ return EOWNERDEAD; } @@ -156,18 +234,34 @@ { if (mutex->__data.__kind == PTHREAD_MUTEX_ROBUST_PRIVATE_ERRORCHECK_NP)+ {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EDEADLK);+#endif /* PTT_LIBPTHREAD */ return EDEADLK;+ } if (mutex->__data.__kind == PTHREAD_MUTEX_ROBUST_PRIVATE_RECURSIVE_NP) { /* Just bump the counter. */ if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))+ { /* Overflow of the counter. */+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EAGAIN);+#endif /* PTT_LIBPTHREAD */ return EAGAIN;+ } ++mutex->__data.__count; +#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, 0);+#endif /* PTT_LIBPTHREAD */ return 0; } }@@ -191,15 +285,32 @@ default: /* Correct code cannot set any other type. */+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EINVAL);+#endif /* PTT_LIBPTHREAD */ return EINVAL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -