Changes in / [0bd46fd:7f6a7c9]
- Files:
-
- 15 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r0bd46fd r7f6a7c9 124 124 concurrency/monitor.hfa \ 125 125 concurrency/mutex.hfa \ 126 concurrency/thread.hfa 126 concurrency/thread.hfa 127 127 128 128 thread_libsrc = ${inst_thread_headers_src} ${inst_thread_headers_src:.hfa=.cfa} \ … … 145 145 concurrency/stats.cfa \ 146 146 concurrency/stats.hfa \ 147 concurrency/stats.hfa 147 concurrency/stats.hfa \ 148 concurrency/pthread.cfa 148 149 149 150 else -
libcfa/src/bits/defs.hfa
r0bd46fd r7f6a7c9 21 21 #include <stdint.h> 22 22 #include <assert.h> 23 #include <signal.h> 23 24 24 25 #define likely(x) __builtin_expect(!!(x), 1) … … 58 59 void abort( bool signalAbort, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )); 59 60 extern "C" { 60 #endif 61 void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 62 #ifdef __cforall 61 #include <pthread.h> 62 void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 63 int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); 64 int real_pthread_join(pthread_t _thread, void **retval); 65 pthread_t real_pthread_self(void); 66 int real_pthread_attr_init(pthread_attr_t *attr); 67 int real_pthread_attr_destroy(pthread_attr_t *attr); 68 int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize ); 69 int real_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize ); 70 int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value); 71 int real_pthread_sigmask( int how, const sigset_t *set, sigset_t *oset); 63 72 } 64 73 #endif -
libcfa/src/concurrency/clib/cfathread.cfa
r0bd46fd r7f6a7c9 172 172 173 173 pthread_attr_t attr; 174 if (int ret = pthread_attr_init(&attr); 0 != ret) {174 if (int ret = real_pthread_attr_init(&attr); 0 != ret) { 175 175 abort | "failed to create master epoll thread attr: " | ret | strerror(ret); 176 176 } 177 177 178 if (int ret = pthread_create(&master_poller, &attr, master_epoll, 0p); 0 != ret) {178 if (int ret = real_pthread_create(&master_poller, &attr, master_epoll, 0p); 0 != ret) { 179 179 abort | "failed to create master epoll thread: " | ret | strerror(ret); 180 180 } -
libcfa/src/concurrency/io.cfa
r0bd46fd r7f6a7c9 610 610 if( we ) { 611 611 sigval_t value = { PREEMPT_IO }; 612 pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);612 real_pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value); 613 613 } 614 614 -
libcfa/src/concurrency/io/setup.cfa
r0bd46fd r7f6a7c9 344 344 // iopoll.run = false; 345 345 // sigval val = { 1 }; 346 // pthread_sigqueue( iopoll.thrd, SIGUSR1, val );346 // real_pthread_sigqueue( iopoll.thrd, SIGUSR1, val ); 347 347 348 348 // // Make sure all this is done -
libcfa/src/concurrency/kernel/startup.cfa
r0bd46fd r7f6a7c9 219 219 ( this.runner ){}; 220 220 init( this, "Main Processor", *mainCluster, 0p ); 221 kernel_thread = pthread_self();221 kernel_thread = real_pthread_self(); 222 222 223 223 runner{ &this }; … … 280 280 } 281 281 282 extern "C"{ 283 void pthread_delete_kernel_threads_(); 284 } 285 286 282 287 static void __kernel_shutdown(void) { 283 288 if(!cfa_main_returned) return; 289 290 //delete kernel threads for pthread_concurrency 291 pthread_delete_kernel_threads_(); 292 284 293 /* paranoid */ verify( __preemption_enabled() ); 285 294 disable_interrupts(); … … 770 779 pthread_attr_t attr; 771 780 772 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute781 check( real_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 773 782 774 783 size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE ); … … 797 806 #endif 798 807 799 check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );800 check( pthread_create( pthread, &attr, start, arg ), "pthread_create" );808 check( real_pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 809 check( real_pthread_create( pthread, &attr, start, arg ), "pthread_create" ); 801 810 return stack; 802 811 } 803 812 804 813 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) { 805 int err = pthread_join( pthread, retval );814 int err = real_pthread_join( pthread, retval ); 806 815 if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err)); 807 816 … … 809 818 pthread_attr_t attr; 810 819 811 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute820 check( real_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 812 821 813 822 size_t stacksize; 814 823 // default stack size, normally defined by shell limit 815 check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );824 check( real_pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" ); 816 825 assert( stacksize >= PTHREAD_STACK_MIN ); 817 826 stacksize += __page_size; -
libcfa/src/concurrency/preemption.cfa
r0bd46fd r7f6a7c9 406 406 sigset_t oldset; 407 407 int ret; 408 ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset); // workaround trac#208: cast should be unnecessary408 ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset); // workaround trac#208: cast should be unnecessary 409 409 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 410 410 … … 439 439 sigaddset( &mask, sig ); 440 440 441 if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {441 if ( real_pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) { 442 442 abort( "internal error, pthread_sigmask" ); 443 443 } … … 450 450 sigaddset( &mask, sig ); 451 451 452 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {452 if ( real_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) { 453 453 abort( "internal error, pthread_sigmask" ); 454 454 } … … 458 458 static void preempt( processor * this ) { 459 459 sigval_t value = { PREEMPT_NORMAL }; 460 pthread_sigqueue( this->kernel_thread, SIGUSR1, value );460 real_pthread_sigqueue( this->kernel_thread, SIGUSR1, value ); 461 461 } 462 462 … … 469 469 sigset_t oldset; 470 470 int ret; 471 ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset); // workaround trac#208: cast should be unnecessary471 ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset); // workaround trac#208: cast should be unnecessary 472 472 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 473 473 … … 488 488 sigset_t oldset; 489 489 int ret; 490 ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset); // workaround trac#208: cast should be unnecessary490 ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset); // workaround trac#208: cast should be unnecessary 491 491 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 492 492 … … 559 559 sigval val; 560 560 val.sival_int = 0; 561 pthread_sigqueue( alarm_thread, SIGALRM, val );561 real_pthread_sigqueue( alarm_thread, SIGALRM, val ); 562 562 563 563 // Wait for the preemption thread to finish … … 633 633 static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" ); 634 634 #endif 635 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {635 if ( real_pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) { 636 636 abort( "internal error, sigprocmask" ); 637 637 } … … 661 661 sigset_t mask; 662 662 sigfillset(&mask); 663 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {663 if ( real_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) { 664 664 abort( "internal error, pthread_sigmask" ); 665 665 } -
libcfa/src/interpose.cfa
r0bd46fd r7f6a7c9 46 46 47 47 static void * library; 48 static void * pthread_library; 48 49 if ( ! library ) { 49 50 #if defined( RTLD_NEXT ) … … 58 59 #endif 59 60 } // if 61 if ( ! pthread_library ) { 62 #if defined( RTLD_NEXT ) 63 pthread_library = RTLD_NEXT; 64 #else 65 // missing RTLD_NEXT => must hard-code library name, assuming libstdc++ 66 pthread_library = dlopen( "libpthread.so", RTLD_LAZY ); 67 error = dlerror(); 68 if ( error ) { 69 abort( "interpose_symbol : failed to open libpthread, %s\n", error ); 70 } 71 #endif 72 } // if 60 73 61 74 union { generic_fptr_t fptr; void * ptr; } originalFunc; … … 72 85 73 86 error = dlerror(); 74 if ( error ) abort( "interpose_symbol : internal error, %s\n", error ); 87 if ( error ) { 88 originalFunc.ptr = dlsym( pthread_library, symbol ); 89 error = dlerror(); 90 if (error){ 91 abort( "interpose_symbol : internal error, %s\n", error ); 92 } // if 93 } // if 75 94 76 95 return originalFunc.fptr; … … 92 111 void (* exit)( int ) __attribute__(( __noreturn__ )); 93 112 void (* abort)( void ) __attribute__(( __noreturn__ )); 113 typeof(pthread_create) pthread_create; 114 typeof(pthread_join) pthread_join; 115 typeof(pthread_self) pthread_self; 116 typeof(pthread_attr_init) pthread_attr_init; 117 typeof(pthread_attr_setstack ) pthread_attr_setstack; 118 typeof(pthread_attr_destroy) pthread_attr_destroy; 119 typeof(pthread_attr_getstacksize) pthread_attr_getstacksize; 120 typeof(pthread_sigmask) pthread_sigmask; 121 typeof(pthread_sigqueue) pthread_sigqueue; 94 122 } __cabi_libc; 95 123 … … 107 135 INTERPOSE_LIBC( abort, version ); 108 136 INTERPOSE_LIBC( exit , version ); 137 INTERPOSE_LIBC( pthread_create , version ); 138 INTERPOSE_LIBC( pthread_join , version ); 139 INTERPOSE_LIBC( pthread_self , version ); 140 INTERPOSE_LIBC( pthread_attr_init , version ); 141 INTERPOSE_LIBC( pthread_attr_destroy , version ); 142 INTERPOSE_LIBC( pthread_attr_setstack , version ); 143 INTERPOSE_LIBC( pthread_attr_getstacksize , version ); 144 INTERPOSE_LIBC( pthread_sigmask , version ); 145 INTERPOSE_LIBC( pthread_sigqueue , version ); 109 146 #pragma GCC diagnostic pop 110 147 … … 167 204 libcfa_public void exit( int status ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) { 168 205 __cabi_libc.exit( status ); 206 } 207 208 libcfa_public int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg){ 209 return __cabi_libc.pthread_create(_thread, attr, start_routine, arg); 210 } 211 212 libcfa_public int real_pthread_join(pthread_t _thread, void **retval){ 213 return __cabi_libc.pthread_join(_thread, retval); 214 } 215 216 libcfa_public pthread_t real_pthread_self(void){ 217 return __cabi_libc.pthread_self(); 218 } 219 libcfa_public int real_pthread_attr_init(pthread_attr_t *attr){ 220 return __cabi_libc.pthread_attr_init(attr); 221 } 222 libcfa_public int real_pthread_attr_destroy(pthread_attr_t *attr){ 223 return __cabi_libc.pthread_attr_destroy(attr); 224 } 225 libcfa_public int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize ){ 226 return __cabi_libc.pthread_attr_setstack(attr, stackaddr, stacksize); 227 } 228 libcfa_public int read_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize ){ 229 return __cabi_libc.pthread_attr_getstacksize(attr, stacksize); 230 } 231 libcfa_public int real_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset){ 232 return __cabi_libc.pthread_sigmask(how, set, oldset); 233 } 234 libcfa_public int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value){ 235 return __cabi_libc.pthread_sigqueue(_thread, sig, value); 169 236 } 170 237 }
Note: See TracChangeset
for help on using the changeset viewer.