Changeset 4434


Ignore:
Timestamp:
Mar 11, 2013 5:27:23 AM (11 years ago)
Author:
bennylp
Message:

Fixed #1638: more group lock fixes, this time for ioqueue_epoll

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c

    r4359 r4434  
    3636#include <pj/sock.h> 
    3737#include <pj/compat/socket.h> 
     38#include <pj/rand.h> 
    3839 
    3940#if !defined(PJ_LINUX_KERNEL) || PJ_LINUX_KERNEL==0 
     
    350351 * Register a socket to ioqueue. 
    351352 */ 
    352 PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool, 
     353PJ_DEF(pj_status_t) pj_ioqueue_register_sock2(pj_pool_t *pool, 
    353354                                              pj_ioqueue_t *ioqueue, 
    354355                                              pj_sock_t sock, 
     356                                              pj_grp_lock_t *grp_lock, 
    355357                                              void *user_data, 
    356358                                              const pj_ioqueue_callback *cb, 
     
    404406#endif 
    405407 
    406     rc = ioqueue_init_key(pool, ioqueue, key, sock, user_data, cb); 
     408    rc = ioqueue_init_key(pool, ioqueue, key, sock, grp_lock, user_data, cb); 
    407409    if (rc != PJ_SUCCESS) { 
    408410        key = NULL; 
     
    438440 
    439441on_return: 
     442    if (rc != PJ_SUCCESS) { 
     443        if (key->grp_lock) 
     444            pj_grp_lock_dec_ref_dbg(key->grp_lock, "ioqueue", 0); 
     445    } 
    440446    *p_key = key; 
    441447    pj_lock_release(ioqueue->lock); 
    442448     
    443449    return rc; 
     450} 
     451 
     452PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool, 
     453                                              pj_ioqueue_t *ioqueue, 
     454                                              pj_sock_t sock, 
     455                                              void *user_data, 
     456                                              const pj_ioqueue_callback *cb, 
     457                                              pj_ioqueue_key_t **p_key) 
     458{ 
     459    return pj_ioqueue_register_sock2(pool, ioqueue, sock, NULL, user_data, 
     460                                     cb, p_key); 
    444461} 
    445462 
     
    498515     * deadlock. 
    499516     */ 
    500     pj_lock_acquire(key->lock); 
     517    pj_ioqueue_lock_key(key); 
    501518 
    502519    /* Also lock ioqueue */ 
     
    532549 
    533550    /* Done. */ 
    534     pj_lock_release(key->lock); 
     551    if (key->grp_lock) { 
     552        /* just dec_ref and unlock. we will set grp_lock to NULL 
     553         * elsewhere */ 
     554        pj_grp_lock_t *grp_lock = key->grp_lock; 
     555        // Don't set grp_lock to NULL otherwise the other thread 
     556        // will crash. Just leave it as dangling pointer, but this 
     557        // should be safe 
     558        //key->grp_lock = NULL; 
     559        pj_grp_lock_dec_ref_dbg(grp_lock, "ioqueue", 0); 
     560        pj_grp_lock_release(grp_lock); 
     561    } else { 
     562        pj_ioqueue_unlock_key(key); 
     563    } 
    535564#else 
     565    if (key->grp_lock) { 
     566        /* set grp_lock to NULL and unlock */ 
     567        pj_grp_lock_t *grp_lock = key->grp_lock; 
     568        // Don't set grp_lock to NULL otherwise the other thread 
     569        // will crash. Just leave it as dangling pointer, but this 
     570        // should be safe 
     571        //key->grp_lock = NULL; 
     572        pj_grp_lock_dec_ref_dbg(grp_lock, "ioqueue", 0); 
     573        pj_grp_lock_release(grp_lock); 
     574    } else { 
     575        pj_ioqueue_unlock_key(key); 
     576    } 
     577 
    536578    pj_lock_destroy(key->lock); 
    537579#endif 
     
    593635        if (PJ_TIME_VAL_GTE(now, h->free_time)) { 
    594636            pj_list_erase(h); 
     637            // Don't set grp_lock to NULL otherwise the other thread 
     638            // will crash. Just leave it as dangling pointer, but this 
     639            // should be safe 
     640            //h->grp_lock = NULL; 
    595641            pj_list_push_back(&ioqueue->free_list, h); 
    596642        } 
     
    710756        } 
    711757    } 
     758    for (i=0; i<processed; ++i) { 
     759        if (queue[i].key->grp_lock) 
     760            pj_grp_lock_add_ref_dbg(queue[i].key->grp_lock, "ioqueue", 0); 
     761    } 
     762 
     763    PJ_RACE_ME(5); 
     764 
    712765    pj_lock_release(ioqueue->lock); 
     766 
     767    PJ_RACE_ME(5); 
    713768 
    714769    /* Now process the events. */ 
     
    732787        decrement_counter(queue[i].key); 
    733788#endif 
     789 
     790        if (queue[i].key->grp_lock) 
     791            pj_grp_lock_dec_ref_dbg(queue[i].key->grp_lock, 
     792                                    "ioqueue", 0); 
    734793    } 
    735794 
Note: See TracChangeset for help on using the changeset viewer.