📄 ptt_glibc-2.3.5.patch
字号:
if (INVALID_NOT_TERMINATED_TD_P (pd))+ { /* Not a valid thread handle. */+#ifdef PTT_LIBPTHREAD+ /* THREAD_JOIN_OUT */+ PTT_TRACE (PTT_LEVEL_THREAD_IO, TR_THREAD_14, ESRCH);+#endif /* PTT_LIBPTHREAD */ return ESRCH;+ } /* Is the thread joinable?. */ 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-03-31 10:28:23.000000000 +0200+++ new_glibc/nptl/pthread_mutex_destroy.c 2006-05-10 11:53:20.000000000 +0200@@ -25,8 +25,24 @@ __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)+ {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_DESTROY_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX, TR_MUTEX_2, mutex, EBUSY);+#endif /* PTT_LIBPTHREAD */ return EBUSY;+ }+ +#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; }diff -Naur ori_glibc/nptl/pthread_mutex_init.c new_glibc/nptl/pthread_mutex_init.c--- ori_glibc/nptl/pthread_mutex_init.c 2006-03-31 10:28:23.000000000 +0200+++ new_glibc/nptl/pthread_mutex_init.c 2006-05-10 11:47:13.000000000 +0200@@ -35,6 +35,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); @@ -52,6 +63,12 @@ // mutex->__nusers = 0; already done by memset // mutex->__spins = 0; 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-03-31 10:28:23.000000000 +0200+++ new_glibc/nptl/pthread_mutex_lock.c 2006-05-11 09:15:41.000000000 +0200@@ -33,6 +33,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)); pid_t id = THREAD_GETMEM (THREAD_SELF, tid);@@ -46,25 +57,62 @@ { /* 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 */+ 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 (mutex->__data.__owner == id)+ {+#ifdef PTT_LIBPTHREAD+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, EDEADLK);+#endif /* PTT_LIBPTHREAD */+ return EDEADLK;+ } /* FALLTHROUGH */ @@ -73,7 +121,21 @@ 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);+ +#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:@@ -89,7 +151,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; } @@ -105,12 +180,25 @@ } /* Record the ownership. */+#ifdef PTT_LIBPTHREAD+ if(mutex->__data.__owner != 0)+ {+ /* MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_8, mutex, -1); + }+#endif /* PTT_LIBPTHREAD */+ assert (mutex->__data.__owner == 0); mutex->__data.__owner = id; #ifndef NO_INCR ++mutex->__data.__nusers; #endif +#ifdef PTT_LIBPTHREAD+ /* MUTEX_OWNER_CHANGE, MUTEX_LOCK_OUT */+ PTT_TRACE (PTT_LEVEL_MUTEX_IO, TR_MUTEX_13, mutex, id, mutex, 0);+#endif /* PTT_LIBPTHREAD */+ return 0; } #ifndef __pthread_mutex_lockdiff -Naur ori_glibc/nptl/pthread_mutex_lock_nt.c new_glibc/nptl/pthread_mutex_lock_nt.c--- ori_glibc/nptl/pthread_mutex_lock_nt.c 1970-01-01 01:00:00.000000000 +0100+++ new_glibc/nptl/pthread_mutex_lock_nt.c 2006-03-31 10:28:32.000000000 +0200@@ -0,0 +1,35 @@+/* Copyright (C) 2004,2005,2006 Bull S.A.+ *+ * This library is free software; you can redistribute it and/or+ * modify it under the terms of the GNU Lesser General Public+ * License as published by the Free Software Foundation; either+ * version 2.1 of the License, or (at your option) any later version.+ *+ * This library is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+ * Lesser General Public License for more details.+ *+ * You should have received a copy of the GNU Lesser General Public+ * License along with this library; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ */++/* pthread_mutex_lock_nt: original pthread_mutex_lock (without traces) */++#ifdef PTT_LIBPTHREAD+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -