Changeset 5055

Show
Ignore:
Timestamp:
12/02/07 20:54:01 (1 year ago)
Author:
morris
Message:

Reorganise thread local data so that the thread is stored separately from the user hash, this lets us log from dealloc methods of objects that are released in the hash

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/thread/wi-thread.c

    r4623 r5055  
    7070#ifdef WI_PTHREADS 
    7171static pthread_key_t                                    _wi_thread_hash_key; 
     72static pthread_key_t                                    _wi_thread_thread_key; 
     73#else 
     74static wi_hash_t                                                *_wi_thread_hash; 
     75static wi_thread_t                                              *_wi_thread_thread; 
    7276#endif 
    7377 
     
    9296void wi_thread_initialize(void) { 
    9397#ifdef WI_PTHREADS 
    94         pthread_key_create(&_wi_thread_hash_key, wi_release); 
     98        pthread_key_create(&_wi_thread_hash_key, NULL); 
     99        pthread_key_create(&_wi_thread_thread_key, NULL); 
    95100#endif 
    96101 
     
    180185static void * _wi_thread_trampoline(void *arg) { 
    181186        void                                    **vector = (void **) arg; 
     187        wi_hash_t                               *hash; 
    182188        wi_thread_func_t                *function; 
    183189        wi_runtime_instance_t   *argument; 
     
    189195         
    190196        wi_thread_enter_thread(); 
    191  
     197         
    192198        (*function)(argument); 
    193199         
    194200        wi_thread_exit_thread(); 
    195  
     201         
    196202        wi_release(argument); 
    197203         
     
    204210void wi_thread_enter_thread(void) { 
    205211        wi_thread_t             *thread; 
     212        wi_pool_t               *pool; 
    206213         
    207214        thread = _wi_thread_init(_wi_thread_alloc()); 
     215 
    208216#ifdef WI_PTHREADS 
    209217        thread->thread = pthread_self(); 
    210218#endif 
    211         wi_hash_set_data_for_key(wi_thread_hash(), thread, WI_STR(_WI_THREAD_KEY)); 
    212         wi_release(thread); 
     219 
     220#ifdef WI_PTHREADS 
     221        pthread_setspecific(_wi_thread_thread_key, thread); 
     222#else 
     223        _wi_thread_thread = thread; 
     224#endif 
    213225         
    214226        wi_error_enter_thread(); 
     
    218230 
    219231void wi_thread_exit_thread(void) { 
     232        wi_hash_t               *hash; 
     233        wi_thread_t             *thread; 
     234         
    220235        wi_socket_exit_thread(); 
     236         
     237        wi_release(wi_thread_hash()); 
     238        wi_release(wi_thread_current_thread()); 
    221239} 
    222240 
     
    226244 
    227245wi_thread_t * wi_thread_current_thread(void) { 
    228         return wi_hash_data_for_key(wi_thread_hash(), WI_STR(_WI_THREAD_KEY)); 
     246#ifdef WI_PTHREADS 
     247        return pthread_getspecific(_wi_thread_thread_key); 
     248#else 
     249        return _wi_thread_thread; 
     250#endif 
    229251} 
    230252 
     
    245267        return hash; 
    246268#else 
    247         static wi_hash_t        *hash; 
    248          
    249         if(!hash) 
    250                 hash = wi_hash_init(wi_hash_alloc()); 
    251          
    252         return hash; 
     269        if(!_wi_thread_hash) 
     270                _wi_thread_hash = wi_hash_init(wi_hash_alloc()); 
     271         
     272        return _wi_thread_hash; 
    253273#endif 
    254274}