Changeset 4592

Show
Ignore:
Timestamp:
11/05/08 17:21:57 (2 months ago)
Author:
martin
Message:

use read-write locks in crypto factory for parallelization

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/libstrongswan/crypto/crypto_factory.c

    r4307 r4592  
    7979     
    8080    /** 
    81      * mutex to lock access to modules 
    82      */ 
    83     mutex_t *mutex
     81     * rwlock to lock access to modules 
     82     */ 
     83    rwlock_t *lock
    8484}; 
    8585 
     
    9494    crypter_t *crypter = NULL; 
    9595 
    96     this->mutex->lock(this->mutex); 
     96    this->lock->read_lock(this->lock); 
    9797    enumerator = this->crypters->create_enumerator(this->crypters); 
    9898    while (enumerator->enumerate(enumerator, &entry)) 
     
    108108    } 
    109109    enumerator->destroy(enumerator); 
    110     this->mutex->unlock(this->mutex); 
     110    this->lock->unlock(this->lock); 
    111111    return crypter; 
    112112} 
     
    122122    signer_t *signer = NULL; 
    123123 
    124     this->mutex->lock(this->mutex); 
     124    this->lock->read_lock(this->lock); 
    125125    enumerator = this->signers->create_enumerator(this->signers); 
    126126    while (enumerator->enumerate(enumerator, &entry)) 
     
    136136    } 
    137137    enumerator->destroy(enumerator); 
    138     this->mutex->unlock(this->mutex); 
     138    this->lock->unlock(this->lock); 
    139139 
    140140    return signer; 
     
    151151    hasher_t *hasher = NULL; 
    152152 
    153     this->mutex->lock(this->mutex); 
     153    this->lock->read_lock(this->lock); 
    154154    enumerator = this->hashers->create_enumerator(this->hashers); 
    155155    while (enumerator->enumerate(enumerator, &entry)) 
     
    165165    } 
    166166    enumerator->destroy(enumerator); 
    167     this->mutex->unlock(this->mutex); 
     167    this->lock->unlock(this->lock); 
    168168    return hasher; 
    169169} 
     
    179179    prf_t *prf = NULL; 
    180180 
    181     this->mutex->lock(this->mutex); 
     181    this->lock->read_lock(this->lock); 
    182182    enumerator = this->prfs->create_enumerator(this->prfs); 
    183183    while (enumerator->enumerate(enumerator, &entry)) 
     
    193193    } 
    194194    enumerator->destroy(enumerator); 
    195     this->mutex->unlock(this->mutex); 
     195    this->lock->unlock(this->lock); 
    196196    return prf; 
    197197} 
     
    207207    rng_constructor_t constr = NULL; 
    208208 
    209     this->mutex->lock(this->mutex); 
     209    this->lock->read_lock(this->lock); 
    210210    enumerator = this->rngs->create_enumerator(this->rngs); 
    211211    while (enumerator->enumerate(enumerator, &entry)) 
     
    222222    } 
    223223    enumerator->destroy(enumerator); 
    224     this->mutex->unlock(this->mutex); 
     224    this->lock->unlock(this->lock); 
    225225    if (constr) 
    226226    { 
     
    240240    diffie_hellman_t *diffie_hellman = NULL; 
    241241 
    242     this->mutex->lock(this->mutex); 
     242    this->lock->read_lock(this->lock); 
    243243    enumerator = this->dhs->create_enumerator(this->dhs); 
    244244    while (enumerator->enumerate(enumerator, &entry)) 
     
    254254    } 
    255255    enumerator->destroy(enumerator); 
    256     this->mutex->unlock(this->mutex); 
     256    this->lock->unlock(this->lock); 
    257257    return diffie_hellman; 
    258258} 
     
    269269    entry->algo = algo; 
    270270    entry->create_crypter = create; 
    271     this->mutex->lock(this->mutex); 
     271    this->lock->write_lock(this->lock); 
    272272    this->crypters->insert_last(this->crypters, entry); 
    273     this->mutex->unlock(this->mutex); 
     273    this->lock->unlock(this->lock); 
    274274} 
    275275 
     
    283283    enumerator_t *enumerator; 
    284284     
    285     this->mutex->lock(this->mutex); 
     285    this->lock->write_lock(this->lock); 
    286286    enumerator = this->crypters->create_enumerator(this->crypters); 
    287287    while (enumerator->enumerate(enumerator, &entry)) 
     
    294294    } 
    295295    enumerator->destroy(enumerator); 
    296     this->mutex->unlock(this->mutex); 
     296    this->lock->unlock(this->lock); 
    297297} 
    298298 
     
    307307    entry->algo = algo; 
    308308    entry->create_signer = create; 
    309     this->mutex->lock(this->mutex); 
     309    this->lock->write_lock(this->lock); 
    310310    this->signers->insert_last(this->signers, entry); 
    311     this->mutex->unlock(this->mutex); 
     311    this->lock->unlock(this->lock); 
    312312} 
    313313 
     
    321321    enumerator_t *enumerator; 
    322322     
    323     this->mutex->lock(this->mutex); 
     323    this->lock->write_lock(this->lock); 
    324324    enumerator = this->signers->create_enumerator(this->signers); 
    325325    while (enumerator->enumerate(enumerator, &entry)) 
     
    332332    } 
    333333    enumerator->destroy(enumerator); 
    334     this->mutex->unlock(this->mutex); 
     334    this->lock->unlock(this->lock); 
    335335} 
    336336 
     
    345345    entry->algo = algo; 
    346346    entry->create_hasher = create; 
    347     this->mutex->lock(this->mutex); 
     347    this->lock->write_lock(this->lock); 
    348348    this->hashers->insert_last(this->hashers, entry); 
    349     this->mutex->unlock(this->mutex); 
     349    this->lock->unlock(this->lock); 
    350350} 
    351351 
     
    359359    enumerator_t *enumerator; 
    360360     
    361     this->mutex->lock(this->mutex); 
     361    this->lock->write_lock(this->lock); 
    362362    enumerator = this->hashers->create_enumerator(this->hashers); 
    363363    while (enumerator->enumerate(enumerator, &entry)) 
     
    370370    } 
    371371    enumerator->destroy(enumerator); 
    372     this->mutex->unlock(this->mutex); 
     372    this->lock->unlock(this->lock); 
    373373} 
    374374 
     
    383383    entry->algo = algo; 
    384384    entry->create_prf = create; 
    385     this->mutex->lock(this->mutex); 
     385    this->lock->write_lock(this->lock); 
    386386    this->prfs->insert_last(this->prfs, entry); 
    387     this->mutex->unlock(this->mutex); 
     387    this->lock->unlock(this->lock); 
    388388} 
    389389 
     
    396396    enumerator_t *enumerator; 
    397397     
    398     this->mutex->lock(this->mutex); 
     398    this->lock->write_lock(this->lock); 
    399399    enumerator = this->prfs->create_enumerator(this->prfs); 
    400400    while (enumerator->enumerate(enumerator, &entry)) 
     
    407407    } 
    408408    enumerator->destroy(enumerator); 
    409     this->mutex->unlock(this->mutex); 
     409    this->lock->unlock(this->lock); 
    410410} 
    411411 
     
    420420    entry->algo = quality; 
    421421    entry->create_rng = create; 
    422     this->mutex->lock(this->mutex); 
     422    this->lock->write_lock(this->lock); 
    423423    this->rngs->insert_last(this->rngs, entry); 
    424     this->mutex->unlock(this->mutex); 
     424    this->lock->unlock(this->lock); 
    425425} 
    426426 
     
    433433    enumerator_t *enumerator; 
    434434     
    435     this->mutex->lock(this->mutex); 
     435    this->lock->write_lock(this->lock); 
    436436    enumerator = this->rngs->create_enumerator(this->rngs); 
    437437    while (enumerator->enumerate(enumerator, &entry)) 
     
    444444    } 
    445445    enumerator->destroy(enumerator); 
    446     this->mutex->unlock(this->mutex); 
     446    this->lock->unlock(this->lock); 
    447447} 
    448448 
     
    457457    entry->algo = group; 
    458458    entry->create_dh = create; 
    459     this->mutex->lock(this->mutex); 
     459    this->lock->write_lock(this->lock); 
    460460    this->dhs->insert_last(this->dhs, entry); 
    461     this->mutex->unlock(this->mutex); 
     461    this->lock->unlock(this->lock); 
    462462} 
    463463 
     
    470470    enumerator_t *enumerator; 
    471471     
    472     this->mutex->lock(this->mutex); 
     472    this->lock->write_lock(this->lock); 
    473473    enumerator = this->dhs->create_enumerator(this->dhs); 
    474474    while (enumerator->enumerate(enumerator, &entry)) 
     
    481481    } 
    482482    enumerator->destroy(enumerator); 
    483     this->mutex->unlock(this->mutex); 
     483    this->lock->unlock(this->lock); 
    484484} 
    485485 
     
    512512                                       linked_list_t *list, void *filter) 
    513513{ 
    514     this->mutex->lock(this->mutex); 
     514    this->lock->read_lock(this->lock); 
    515515    return enumerator_create_filter( 
    516516                enumerator_create_filter( 
    517517                    list->create_enumerator(list), (void*)unique_check, 
    518518                    linked_list_create(), (void*)list->destroy), 
    519                 filter, this->mutex, (void*)this->mutex->unlock); 
     519                filter, this->lock, (void*)this->lock->unlock); 
    520520} 
    521521 
     
    616616    this->rngs->destroy_function(this->rngs, free); 
    617617    this->dhs->destroy_function(this->dhs, free); 
    618     this->mutex->destroy(this->mutex); 
     618    this->lock->destroy(this->lock); 
    619619    free(this); 
    620620} 
     
    658658    this->rngs = linked_list_create(); 
    659659    this->dhs = linked_list_create(); 
    660     this->mutex = mutex_create(MUTEX_RECURSIVE); 
     660    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    661661     
    662662    return &this->public;