Index: include/pthread.h =================================================================== RCS file: /home/ncvs/src/include/pthread.h,v retrieving revision 1.41 diff -u -r1.41 pthread.h --- include/pthread.h 29 Oct 2007 21:01:47 -0000 1.41 +++ include/pthread.h 17 Dec 2007 02:56:00 -0000 @@ -135,6 +135,10 @@ #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK +struct _pthread_cleanup_info { + __uintptr_t pthread_cleanup_pad[8]; +}; + /* * Thread function prototype definitions: */ @@ -162,8 +166,19 @@ int *); int pthread_barrierattr_init(pthread_barrierattr_t *); int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); -void pthread_cleanup_pop(int); -void pthread_cleanup_push(void (*) (void *), void *); + +#define pthread_cleanup_push(cleanup_routine, cleanup_arg) \ + { \ + struct _pthread_cleanup_info __cleanup_info; \ + __pthread_cleanup_push_imp(cleanup_routine, cleanup_arg,\ + &__cleanup_info); \ + { + +#define pthread_cleanup_pop(execute) \ + } \ + __pthread_cleanup_pop_imp(execute); \ + } + int pthread_condattr_destroy(pthread_condattr_t *); int pthread_condattr_getclock(const pthread_condattr_t *, clockid_t *); @@ -267,6 +282,10 @@ const struct sched_param *); int pthread_getconcurrency(void); int pthread_setconcurrency(int); + +void __pthread_cleanup_push_imp(void (*)(void *), void *, + struct _pthread_cleanup_info *); +void __pthread_cleanup_pop_imp(int); __END_DECLS #endif Index: lib/libc/include/namespace.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/namespace.h,v retrieving revision 1.20 diff -u -r1.20 namespace.h --- lib/libc/include/namespace.h 28 Mar 2006 18:48:49 -0000 1.20 +++ lib/libc/include/namespace.h 17 Dec 2007 02:56:00 -0000 @@ -112,8 +112,6 @@ #define pthread_barrierattr_init _pthread_barrierattr_init #define pthread_barrierattr_setpshared _pthread_barrierattr_setpshared #define pthread_cancel _pthread_cancel -#define pthread_cleanup_pop _pthread_cleanup_pop -#define pthread_cleanup_push _pthread_cleanup_push #define pthread_cond_broadcast _pthread_cond_broadcast #define pthread_cond_destroy _pthread_cond_destroy #define pthread_cond_init _pthread_cond_init Index: lib/libc/include/un-namespace.h =================================================================== RCS file: /home/ncvs/src/lib/libc/include/un-namespace.h,v retrieving revision 1.17 diff -u -r1.17 un-namespace.h --- lib/libc/include/un-namespace.h 28 Mar 2006 18:48:49 -0000 1.17 +++ lib/libc/include/un-namespace.h 17 Dec 2007 02:56:00 -0000 @@ -93,8 +93,6 @@ #undef pthread_barrierattr_init #undef pthread_barrierattr_setpshared #undef pthread_cancel -#undef pthread_cleanup_pop -#undef pthread_cleanup_push #undef pthread_cond_broadcast #undef pthread_cond_destroy #undef pthread_cond_init Index: lib/libkse/kse.map =================================================================== RCS file: /home/ncvs/src/lib/libkse/kse.map,v retrieving revision 1.2 diff -u -r1.2 kse.map --- lib/libkse/kse.map 27 Nov 2007 03:16:43 -0000 1.2 +++ lib/libkse/kse.map 17 Dec 2007 02:56:00 -0000 @@ -6,6 +6,8 @@ FBSD_1.0 { global: __error; + __pthread_cleanup_pop_imp; + __pthread_cleanup_push_imp; accept; aio_suspend; close; Index: lib/libkse/thread/thr_clean.c =================================================================== RCS file: /home/ncvs/src/lib/libkse/thread/thr_clean.c,v retrieving revision 1.14 diff -u -r1.14 thr_clean.c --- lib/libkse/thread/thr_clean.c 16 Dec 2007 23:29:55 -0000 1.14 +++ lib/libkse/thread/thr_clean.c 17 Dec 2007 02:56:01 -0000 @@ -37,23 +37,41 @@ #include "un-namespace.h" #include "thr_private.h" +/* old binary compatible interfaces */ __weak_reference(_pthread_cleanup_push, pthread_cleanup_push); __weak_reference(_pthread_cleanup_pop, pthread_cleanup_pop); +/* new pthread cleanup implementation */ +__weak_reference(_pthread_cleanup_pop, __pthread_cleanup_pop_imp); + void -_pthread_cleanup_push(void (*routine) (void *), void *routine_arg) +__pthread_cleanup_push_imp(void (*routine)(void *), void *arg, + struct _pthread_cleanup_info *info) { struct pthread *curthread = _get_curthread(); - struct pthread_cleanup *new; + struct pthread_cleanup *newbuf; + + newbuf = (void *)info; + newbuf->routine = routine; + newbuf->routine_arg = arg; + newbuf->onheap = 0; + newbuf->prev = curthread->cleanup; + curthread->cleanup = newbuf; +} - if ((new = (struct pthread_cleanup *) - malloc(sizeof(struct pthread_cleanup))) != NULL) { - new->routine = routine; - new->routine_arg = routine_arg; - new->onstack = 0; - new->next = curthread->cleanup; +void +_pthread_cleanup_push(void (*routine) (void *), void *arg) +{ + struct pthread *curthread = _get_curthread(); + struct pthread_cleanup *newbuf; - curthread->cleanup = new; + if ((newbuf = (struct pthread_cleanup *) + malloc(sizeof(struct _pthread_cleanup_info))) != NULL) { + newbuf->routine = routine; + newbuf->routine_arg = arg; + newbuf->onheap = 1; + newbuf->prev = curthread->cleanup; + curthread->cleanup = newbuf; } } @@ -64,11 +82,10 @@ struct pthread_cleanup *old; if ((old = curthread->cleanup) != NULL) { - curthread->cleanup = old->next; - if (execute) { + curthread->cleanup = old->prev; + if (execute) old->routine(old->routine_arg); - } - if (old->onstack == 0) + if (old->onheap) free(old); } } Index: lib/libkse/thread/thr_private.h =================================================================== RCS file: /home/ncvs/src/lib/libkse/thread/thr_private.h,v retrieving revision 1.133 diff -u -r1.133 thr_private.h --- lib/libkse/thread/thr_private.h 16 Dec 2007 23:29:56 -0000 1.133 +++ lib/libkse/thread/thr_private.h 17 Dec 2007 02:56:01 -0000 @@ -416,10 +416,10 @@ * Cleanup definitions. */ struct pthread_cleanup { - struct pthread_cleanup *next; - void (*routine) (void *); + struct pthread_cleanup *prev; + void (*routine)(void *); void *routine_arg; - int onstack; + int onheap; }; #define THR_CLEANUP_PUSH(td, func, arg) { \ @@ -427,12 +427,12 @@ \ __cup.routine = func; \ __cup.routine_arg = arg; \ - __cup.onstack = 1; \ - __cup.next = (td)->cleanup; \ + __cup.onheap = 0; \ + __cup.prev = (td)->cleanup; \ (td)->cleanup = &__cup; #define THR_CLEANUP_POP(td, exec) \ - (td)->cleanup = __cup.next; \ + (td)->cleanup = __cup.prev; \ if ((exec) != 0) \ __cup.routine(__cup.routine_arg); \ } @@ -836,7 +836,7 @@ int rtld_bits; /* Cleanup handlers Link List */ - struct pthread_cleanup *cleanup; + struct pthread_cleanup *cleanup; const char *fname; /* Ptr to source file name */ int lineno; /* Source line number. */ }; @@ -1123,6 +1123,8 @@ void _pq_insert_tail(struct pq_queue *pq, struct pthread *); struct pthread *_pq_first(struct pq_queue *pq); struct pthread *_pq_first_debug(struct pq_queue *pq); +void _pthread_cleanup_push(void (*)(void *), void *); +void _pthread_cleanup_pop(int); void *_pthread_getspecific(pthread_key_t); int _pthread_key_create(pthread_key_t *, void (*) (void *)); int _pthread_key_delete(pthread_key_t); Index: lib/libthr/pthread.map =================================================================== RCS file: /home/ncvs/src/lib/libthr/pthread.map,v retrieving revision 1.20 diff -u -r1.20 pthread.map --- lib/libthr/pthread.map 14 Dec 2007 06:25:57 -0000 1.20 +++ lib/libthr/pthread.map 17 Dec 2007 02:56:01 -0000 @@ -8,6 +8,8 @@ FBSD_1.0 { global: __error; + __pthread_cleanup_pop_imp; + __pthread_cleanup_push_imp; accept; aio_suspend; close; Index: lib/libthr/thread/thr_clean.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_clean.c,v retrieving revision 1.5 diff -u -r1.5 thr_clean.c --- lib/libthr/thread/thr_clean.c 12 Jan 2007 07:26:20 -0000 1.5 +++ lib/libthr/thread/thr_clean.c 17 Dec 2007 02:56:01 -0000 @@ -38,23 +38,44 @@ #include "thr_private.h" +#undef pthread_cleanup_push +#undef pthread_cleanup_pop + +/* old binary compatible interfaces */ __weak_reference(_pthread_cleanup_push, pthread_cleanup_push); __weak_reference(_pthread_cleanup_pop, pthread_cleanup_pop); +/* new pthread cleanup implementation */ +__weak_reference(_pthread_cleanup_pop, __pthread_cleanup_pop_imp); + void -_pthread_cleanup_push(void (*routine) (void *), void *routine_arg) +__pthread_cleanup_push_imp(void (*routine)(void *), void *arg, + struct _pthread_cleanup_info *info) { struct pthread *curthread = _get_curthread(); - struct pthread_cleanup *new; + struct pthread_cleanup *newbuf; + + newbuf = (void *)info; + newbuf->routine = routine; + newbuf->routine_arg = arg; + newbuf->onheap = 0; + newbuf->prev = curthread->cleanup; + curthread->cleanup = newbuf; +} - if ((new = (struct pthread_cleanup *) - malloc(sizeof(struct pthread_cleanup))) != NULL) { - new->routine = routine; - new->routine_arg = routine_arg; - new->onstack = 0; - new->next = curthread->cleanup; +void +_pthread_cleanup_push(void (*routine) (void *), void *arg) +{ + struct pthread *curthread = _get_curthread(); + struct pthread_cleanup *newbuf; - curthread->cleanup = new; + if ((newbuf = (struct pthread_cleanup *) + malloc(sizeof(struct _pthread_cleanup_info))) != NULL) { + newbuf->routine = routine; + newbuf->routine_arg = arg; + newbuf->onheap = 1; + newbuf->prev = curthread->cleanup; + curthread->cleanup = newbuf; } } @@ -65,11 +86,10 @@ struct pthread_cleanup *old; if ((old = curthread->cleanup) != NULL) { - curthread->cleanup = old->next; - if (execute) { + curthread->cleanup = old->prev; + if (execute) old->routine(old->routine_arg); - } - if (old->onstack == 0) + if (old->onheap) free(old); } } Index: lib/libthr/thread/thr_exit.c =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_exit.c,v retrieving revision 1.23 diff -u -r1.23 thr_exit.c --- lib/libthr/thread/thr_exit.c 12 Jan 2007 07:26:20 -0000 1.23 +++ lib/libthr/thread/thr_exit.c 17 Dec 2007 02:56:01 -0000 @@ -100,7 +100,7 @@ /* Save the return value: */ curthread->ret = status; while (curthread->cleanup != NULL) { - pthread_cleanup_pop(1); + _pthread_cleanup_pop(1); } /* Check if there is thread specific data: */ Index: lib/libthr/thread/thr_private.h =================================================================== RCS file: /home/ncvs/src/lib/libthr/thread/thr_private.h,v retrieving revision 1.81 diff -u -r1.81 thr_private.h --- lib/libthr/thread/thr_private.h 14 Dec 2007 06:25:57 -0000 1.81 +++ lib/libthr/thread/thr_private.h 17 Dec 2007 02:56:01 -0000 @@ -183,10 +183,10 @@ * Cleanup definitions. */ struct pthread_cleanup { - struct pthread_cleanup *next; - void (*routine)(void *args); + struct pthread_cleanup *prev; + void (*routine)(void *); void *routine_arg; - int onstack; + int onheap; }; #define THR_CLEANUP_PUSH(td, func, arg) { \ @@ -194,12 +194,12 @@ \ __cup.routine = func; \ __cup.routine_arg = arg; \ - __cup.onstack = 1; \ - __cup.next = (td)->cleanup; \ + __cup.onheap = 0; \ + __cup.prev = (td)->cleanup; \ (td)->cleanup = &__cup; #define THR_CLEANUP_POP(td, exec) \ - (td)->cleanup = __cup.next; \ + (td)->cleanup = __cup.prev; \ if ((exec) != 0) \ __cup.routine(__cup.routine_arg); \ } @@ -659,6 +659,9 @@ void _thread_bp_death(void); int _sched_yield(void); +void _pthread_cleanup_push(void (*)(void *), void *); +void _pthread_cleanup_pop(int); + /* #include */ #ifdef _SYS_FCNTL_H_ int __sys_fcntl(int, int, ...);