Changeset a7d696f for libcfa/src
- Timestamp:
- Aug 3, 2022, 6:32:06 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 20be782
- Parents:
- 80d16f8
- git-author:
- z277zhu <z277zhu@…> (08/03/22 18:24:16)
- git-committer:
- z277zhu <z277zhu@…> (08/03/22 18:32:06)
- Location:
- libcfa/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r80d16f8 ra7d696f 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
r80d16f8 ra7d696f 21 21 #include <stdint.h> 22 22 #include <assert.h> 23 #include <pthread.h> 23 24 24 25 #define likely(x) __builtin_expect(!!(x), 1) … … 45 46 #endif 46 47 void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 48 int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); 49 int real_pthread_join(pthread_t _thread, void **retval); 50 pthread_t real_pthread_self(void); 51 int real_pthread_mutex_init(pthread_mutex_t *_mutex, const pthread_mutexattr_t *attr); 52 int real_pthread_mutex_destroy(pthread_mutex_t *_mutex); 53 int real_pthread_mutex_lock(pthread_mutex_t *_mutex); 54 int real_pthread_mutex_unlock(pthread_mutex_t *_mutex); 55 int real_pthread_mutex_trylock(pthread_mutex_t *_mutex); 56 int real_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); 57 int real_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *_mutex); 58 int real_pthread_cond_signal(pthread_cond_t *cond); 59 int real_pthread_cond_broadcast(pthread_cond_t *cond); 60 int real_pthread_cond_destroy(pthread_cond_t *cond); 61 int real_pthread_attr_init(pthread_attr_t *attr); 62 int real_pthread_attr_destroy(pthread_attr_t *attr); 63 int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize ); 64 int real_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize ); 47 65 #ifdef __cforall 48 66 } -
libcfa/src/concurrency/clib/cfathread.cfa
r80d16f8 ra7d696f 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/kernel/startup.cfa
r80d16f8 ra7d696f 218 218 ( this.runner ){}; 219 219 init( this, "Main Processor", *mainCluster, 0p ); 220 kernel_thread = pthread_self();220 kernel_thread = real_pthread_self(); 221 221 222 222 runner{ &this }; … … 769 769 pthread_attr_t attr; 770 770 771 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute771 check( real_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 772 772 773 773 size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE ); … … 796 796 #endif 797 797 798 check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );799 check( pthread_create( pthread, &attr, start, arg ), "pthread_create" );798 check( real_pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); 799 check( real_pthread_create( pthread, &attr, start, arg ), "pthread_create" ); 800 800 return stack; 801 801 } 802 802 803 803 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) { 804 int err = pthread_join( pthread, retval );804 int err = real_pthread_join( pthread, retval ); 805 805 if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err)); 806 806 … … 808 808 pthread_attr_t attr; 809 809 810 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute810 check( real_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute 811 811 812 812 size_t stacksize; 813 813 // default stack size, normally defined by shell limit 814 check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );814 check( real_pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" ); 815 815 assert( stacksize >= PTHREAD_STACK_MIN ); 816 816 stacksize += __page_size; -
libcfa/src/interpose.cfa
r80d16f8 ra7d696f 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_cond_init) pthread_cond_init; 117 typeof(pthread_cond_destroy) pthread_cond_destroy; 118 typeof(pthread_cond_signal) pthread_cond_signal; 119 typeof(pthread_cond_broadcast) pthread_cond_broadcast; 120 typeof(pthread_cond_wait) pthread_cond_wait; 121 typeof(pthread_mutex_init) pthread_mutex_init; 122 typeof(pthread_mutex_lock) pthread_mutex_lock; 123 typeof(pthread_mutex_trylock) pthread_mutex_trylock; 124 typeof(pthread_mutex_unlock) pthread_mutex_unlock; 125 typeof(pthread_mutex_destroy) pthread_mutex_destroy; 126 typeof(pthread_attr_init ) pthread_attr_init; 127 typeof(pthread_attr_setstack ) pthread_attr_setstack; 128 typeof(pthread_attr_destroy) pthread_attr_destroy; 129 typeof(pthread_attr_getstacksize) pthread_attr_getstacksize; 94 130 } __cabi_libc; 95 131 … … 107 143 INTERPOSE_LIBC( abort, version ); 108 144 INTERPOSE_LIBC( exit , version ); 145 INTERPOSE_LIBC( pthread_create , version ); 146 INTERPOSE_LIBC( pthread_join , version ); 147 INTERPOSE_LIBC( pthread_self , version ); 148 INTERPOSE_LIBC( pthread_mutex_init , version ); 149 INTERPOSE_LIBC( pthread_mutex_lock , version ); 150 INTERPOSE_LIBC( pthread_mutex_unlock , version ); 151 INTERPOSE_LIBC( pthread_mutex_destroy , version ); 152 INTERPOSE_LIBC( pthread_cond_init , version ); 153 INTERPOSE_LIBC( pthread_cond_destroy , version ); 154 INTERPOSE_LIBC( pthread_cond_signal , version ); 155 INTERPOSE_LIBC( pthread_cond_broadcast , version ); 156 INTERPOSE_LIBC( pthread_cond_wait , version ); 157 INTERPOSE_LIBC( pthread_attr_init , version ); 158 INTERPOSE_LIBC( pthread_attr_destroy , version ); 159 INTERPOSE_LIBC( pthread_attr_setstack , version ); 160 INTERPOSE_LIBC( pthread_attr_getstacksize , version ); 109 161 #pragma GCC diagnostic pop 110 162 … … 168 220 __cabi_libc.exit( status ); 169 221 } 222 223 libcfa_public int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg){ 224 return __cabi_libc.pthread_create(_thread, attr, start_routine, arg); 225 } 226 227 libcfa_public int real_pthread_join(pthread_t _thread, void **retval){ 228 return __cabi_libc.pthread_join(_thread, retval); 229 } 230 231 libcfa_public pthread_t real_pthread_self(void){ 232 return __cabi_libc.pthread_self(); 233 } 234 /* mutex Default attr is PTHREAD_MUTEX_RECURSIVE*/ 235 libcfa_public int real_pthread_mutex_init(pthread_mutex_t *_mutex, const pthread_mutexattr_t *attr){ 236 return __cabi_libc.pthread_mutex_init(_mutex, attr); 237 } 238 libcfa_public int real_pthread_mutex_destroy(pthread_mutex_t *_mutex){ 239 return __cabi_libc.pthread_mutex_destroy(_mutex); 240 } 241 libcfa_public int real_pthread_mutex_lock(pthread_mutex_t *_mutex){ 242 return __cabi_libc.pthread_mutex_lock(_mutex); 243 } 244 libcfa_public int real_pthread_mutex_unlock(pthread_mutex_t *_mutex){ 245 return __cabi_libc.pthread_mutex_unlock(_mutex); 246 } 247 libcfa_public int real_pthread_mutex_trylock(pthread_mutex_t *_mutex){ 248 return __cabi_libc.pthread_mutex_trylock(_mutex); 249 } 250 libcfa_public int real_pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr){ 251 return __cabi_libc.pthread_cond_init(cond, attr); 252 } 253 libcfa_public int real_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *_mutex){ 254 return __cabi_libc.pthread_cond_wait(cond, _mutex); 255 } 256 libcfa_public int real_pthread_cond_signal(pthread_cond_t *cond){ 257 return __cabi_libc.pthread_cond_signal(cond); 258 } 259 libcfa_public int real_pthread_cond_broadcast(pthread_cond_t *cond){ 260 return __cabi_libc.pthread_cond_broadcast(cond); 261 } 262 libcfa_public int real_pthread_cond_destroy(pthread_cond_t *cond){ 263 return __cabi_libc.pthread_cond_destroy(cond); 264 } 265 libcfa_public int real_pthread_attr_init(pthread_attr_t *attr){ 266 return __cabi_libc.pthread_attr_init(attr); 267 } 268 libcfa_public int real_pthread_attr_destroy(pthread_attr_t *attr){ 269 return __cabi_libc.pthread_attr_destroy(attr); 270 } 271 libcfa_public int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize ){ 272 return __cabi_libc.pthread_attr_setstack(attr, stackaddr, stacksize); 273 } 274 libcfa_public int pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize ){ 275 return __cabi_libc.pthread_attr_getstacksize(attr, stacksize); 276 } 277 170 278 } 171 279
Note: See TracChangeset
for help on using the changeset viewer.