Changeset 4591

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

wrapped all pthread_rwlock_t in profilable rwlock_t

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/charon/credentials/credential_manager.c

    r4317 r4591  
    1616 */ 
    1717 
    18 /* some clibs need it for rwlocks */ 
    19 #define _GNU_SOURCE 
    2018#include <pthread.h> 
    2119 
     
    2321 
    2422#include <daemon.h> 
     23#include <utils/mutex.h> 
    2524#include <utils/linked_list.h> 
    2625#include <credentials/sets/cert_cache.h> 
     
    6968     * read-write lock to sets list 
    7069     */ 
    71     pthread_rwlock_t lock; 
     70    rwlock_t *lock; 
    7271}; 
    7372 
     
    171170static void destroy_cert_data(cert_data_t *data) 
    172171{ 
    173     pthread_rwlock_unlock(&data->this->lock); 
     172    data->this->lock->unlock(data->this->lock); 
    174173    free(data); 
    175174} 
     
    198197    data->trusted = trusted; 
    199198     
    200     pthread_rwlock_rdlock(&this->lock); 
     199    this->lock->read_lock(this->lock); 
    201200    return enumerator_create_nested(create_sets_enumerator(this), 
    202201                                    (void*)create_cert, data, 
     
    230229static void destroy_cdp_data(cdp_data_t *data) 
    231230{ 
    232     pthread_rwlock_unlock(&data->this->lock); 
     231    data->this->lock->unlock(data->this->lock); 
    233232    free(data); 
    234233} 
     
    252251    data->id = id; 
    253252     
    254     pthread_rwlock_rdlock(&this->lock); 
     253    this->lock->read_lock(this->lock); 
    255254    return enumerator_create_nested(create_sets_enumerator(this), 
    256255                                    (void*)create_cdp, data, 
     
    263262static void destroy_private_data(private_data_t *data) 
    264263{ 
    265     pthread_rwlock_unlock(&data->this->lock); 
     264    data->this->lock->unlock(data->this->lock); 
    266265    free(data); 
    267266} 
     
    288287    data->type = key; 
    289288    data->keyid = keyid; 
    290     pthread_rwlock_rdlock(&this->lock); 
     289    this->lock->read_lock(this->lock); 
    291290    return enumerator_create_nested(create_sets_enumerator(this), 
    292291                                    (void*)create_private, data, 
     
    317316static void destroy_shared_data(shared_data_t *data) 
    318317{ 
    319     pthread_rwlock_unlock(&data->this->lock); 
     318    data->this->lock->unlock(data->this->lock); 
    320319    free(data); 
    321320} 
     
    342341    data->other = other; 
    343342     
    344     pthread_rwlock_rdlock(&this->lock); 
     343    this->lock->read_lock(this->lock); 
    345344    return enumerator_create_nested(create_sets_enumerator(this), 
    346345                                    (void*)create_shared, data,  
     
    413412    enumerator_t *enumerator; 
    414413     
    415     if (pthread_rwlock_trywrlock(&this->lock) == 0
     414    if (this->lock->try_write_lock(this->lock)
    416415    { 
    417416        enumerator = this->sets->create_enumerator(this->sets); 
     
    424423    else 
    425424    {   /* we can't cache now as other threads are active, queue for later */ 
    426         pthread_rwlock_rdlock(&this->lock); 
     425        this->lock->read_lock(this->lock); 
    427426        this->cache_queue->insert_last(this->cache_queue, cert->get_ref(cert)); 
    428427    } 
    429     pthread_rwlock_unlock(&this->lock); 
     428    this->lock->unlock(this->lock); 
    430429} 
    431430 
     
    440439     
    441440    if (this->cache_queue->get_count(this->cache_queue) > 0 && 
    442         pthread_rwlock_trywrlock(&this->lock) == 0
     441        this->lock->try_write_lock(this->lock)
    443442    { 
    444443        while (this->cache_queue->remove_last(this->cache_queue, 
     
    453452            cert->destroy(cert); 
    454453        } 
    455         pthread_rwlock_unlock(&this->lock); 
     454        this->lock->unlock(this->lock); 
    456455    } 
    457456} 
     
    13031302        this->wrapper->destroy(this->wrapper); 
    13041303    } 
    1305     pthread_rwlock_unlock(&this->this->lock); 
     1304    this->this->lock->unlock(this->this->lock); 
    13061305     
    13071306    /* check for delayed certificate cache queue */ 
     
    13291328        add_local_set(this, &enumerator->wrapper->set); 
    13301329    } 
    1331     pthread_rwlock_rdlock(&this->lock); 
     1330    this->lock->read_lock(this->lock); 
    13321331    return &enumerator->public; 
    13331332} 
     
    15261525                               credential_set_t *set) 
    15271526{ 
    1528     pthread_rwlock_wrlock(&this->lock); 
     1527    this->lock->write_lock(this->lock); 
    15291528    this->sets->insert_last(this->sets, set); 
    1530     pthread_rwlock_unlock(&this->lock); 
     1529    this->lock->unlock(this->lock); 
    15311530} 
    15321531 
     
    15361535static void remove_set(private_credential_manager_t *this, credential_set_t *set) 
    15371536{ 
    1538     pthread_rwlock_wrlock(&this->lock); 
     1537    this->lock->write_lock(this->lock); 
    15391538    this->sets->remove(this->sets, set, NULL); 
    1540     pthread_rwlock_unlock(&this->lock); 
     1539    this->lock->unlock(this->lock); 
    15411540} 
    15421541 
     
    15521551    pthread_key_delete(this->local_sets); 
    15531552    this->cache->destroy(this->cache); 
    1554     pthread_rwlock_destroy(&this->lock); 
     1553    this->lock->destroy(this->lock); 
    15551554    free(this); 
    15561555} 
     
    15811580    this->cache_queue = linked_list_create(); 
    15821581    this->sets->insert_first(this->sets, this->cache); 
    1583     pthread_rwlock_init(&this->lock, NULL); 
     1582    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    15841583     
    15851584    return &this->public; 
  • trunk/src/charon/credentials/sets/cert_cache.c

    r4229 r4591  
    1616 */ 
    1717 
    18 #define _GNU_SOURCE 
    19 #include <pthread.h> 
    20  
    2118#include "cert_cache.h" 
    2219 
     20#include <time.h> 
     21 
    2322#include <daemon.h> 
     23#include <utils/mutex.h> 
    2424#include <utils/linked_list.h> 
    2525 
     
    5757     * read-write lock to sets list 
    5858     */ 
    59     pthread_rwlock_t lock; 
     59    rwlock_t *lock; 
    6060}; 
    6161 
     
    9191        this->check_required = TRUE; 
    9292    } 
    93     else if (pthread_rwlock_trywrlock(&this->lock) == 0
     93    else if (this->lock->try_write_lock(this->lock)
    9494    {   /* never blocks, only done if lock is available */ 
    9595        while (this->relations->get_count(this->relations) > CACHE_SIZE) 
     
    111111        } 
    112112        this->check_required = FALSE; 
    113         pthread_rwlock_unlock(&this->lock); 
     113        this->lock->unlock(this->lock); 
    114114    } 
    115115} 
     
    125125     
    126126    /* lookup cache */ 
    127     pthread_rwlock_rdlock(&this->lock); 
     127    this->lock->read_lock(this->lock); 
    128128    enumerator = this->relations->create_enumerator(this->relations); 
    129129    while (enumerator->enumerate(enumerator, &current)) 
     
    150150    } 
    151151    enumerator->destroy(enumerator); 
    152     pthread_rwlock_unlock(&this->lock); 
     152    this->lock->unlock(this->lock); 
    153153    if (found) 
    154154    { 
     
    234234{ 
    235235    ref_put(&data->this->enumerating); 
    236     pthread_rwlock_unlock(&data->this->lock); 
     236    data->this->lock->unlock(data->this->lock); 
    237237    if (data->this->check_required) 
    238238    { 
     
    261261    data->this = this; 
    262262     
    263     pthread_rwlock_rdlock(&this->lock); 
     263    this->lock->read_lock(this->lock); 
    264264    ref_get(&this->enumerating); 
    265265    return enumerator_create_filter( 
     
    276276    relation_t *relation; 
    277277     
    278     pthread_rwlock_wrlock(&this->lock); 
     278    this->lock->write_lock(this->lock); 
    279279    enumerator = this->relations->create_enumerator(this->relations); 
    280280    while (enumerator->enumerate(enumerator, &relation)) 
     
    288288    } 
    289289    enumerator->destroy(enumerator); 
    290     pthread_rwlock_unlock(&this->lock); 
     290    this->lock->unlock(this->lock); 
    291291} 
    292292 
     
    297297{ 
    298298    this->relations->destroy_function(this->relations, (void*)relation_destroy); 
    299     pthread_rwlock_destroy(&this->lock); 
     299    this->lock->destroy(this->lock); 
    300300    free(this); 
    301301} 
     
    320320    this->enumerating = 0; 
    321321    this->check_required = FALSE; 
    322     pthread_rwlock_init(&this->lock, NULL); 
     322    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    323323     
    324324    return &this->public; 
  • trunk/src/charon/plugins/nm/nm_creds.c

    r4326 r4591  
    1616 */ 
    1717 
    18 #define _GNU_SOURCE 
    19 #include <pthread.h> 
    20  
    2118#include "nm_creds.h" 
    2219 
    2320#include <daemon.h> 
     21#include <utils/mutex.h> 
    2422 
    2523typedef struct private_nm_creds_t private_nm_creds_t; 
     
    6361     * read/write lock 
    6462     */ 
    65     pthread_rwlock_t lock; 
     63    rwlock_t *lock; 
    6664}; 
    6765 
     
    9290        public->destroy(public); 
    9391    } 
    94     pthread_rwlock_rdlock(&this->lock); 
     92    this->lock->read_lock(this->lock); 
    9593    return enumerator_create_cleaner( 
    9694                                enumerator_create_single(this->usercert, NULL), 
    97                                 (void*)pthread_rwlock_unlock, &this->lock); 
     95                                (void*)this->lock->unlock, this->lock); 
    9896} 
    9997 
     
    139137        public->destroy(public); 
    140138    } 
    141     pthread_rwlock_rdlock(&this->lock); 
     139    this->lock->read_lock(this->lock); 
    142140    return enumerator_create_cleaner(enumerator_create_single(this->cert, NULL), 
    143                                      (void*)pthread_rwlock_unlock, &this->lock); 
     141                                     (void*)this->lock->unlock, this->lock); 
    144142} 
    145143 
     
    168166        } 
    169167    } 
    170     pthread_rwlock_rdlock(&this->lock); 
     168    this->lock->read_lock(this->lock); 
    171169    return enumerator_create_cleaner(enumerator_create_single(this->key, NULL), 
    172                                      (void*)pthread_rwlock_unlock, &this->lock); 
     170                                     (void*)this->lock->unlock, this->lock); 
    173171} 
    174172 
     
    206204{ 
    207205    this->key->destroy(this->key); 
    208     pthread_rwlock_unlock(&this->this->lock); 
     206    this->lock->destroy(this->lock); 
     207    this->this->lock->unlock(this->this->lock); 
    209208    free(this); 
    210209} 
     
    236235    enumerator->this = this; 
    237236    enumerator->done = FALSE; 
    238     pthread_rwlock_rdlock(&this->lock); 
     237    this->lock->read_lock(this->lock); 
    239238    enumerator->key = shared_key_create(type, 
    240239                                        chunk_clone(chunk_create(this->pass, 
     
    248247static void set_certificate(private_nm_creds_t *this, certificate_t *cert) 
    249248{ 
    250     pthread_rwlock_wrlock(&this->lock); 
     249    this->lock->write_lock(this->lock); 
    251250    DESTROY_IF(this->cert); 
    252251    this->cert = cert; 
    253     pthread_rwlock_unlock(&this->lock); 
     252    this->lock->unlock(this->lock); 
    254253} 
    255254 
     
    260259                         char *password) 
    261260{ 
    262     pthread_rwlock_wrlock(&this->lock); 
     261    this->lock->write_lock(this->lock); 
    263262    DESTROY_IF(this->user); 
    264263    /* for EAP authentication, we use always use ID_EAP type */ 
     
    267266    free(this->pass); 
    268267    this->pass = password ? strdup(password) : NULL; 
    269     pthread_rwlock_unlock(&this->lock); 
     268    this->lock->unlock(this->lock); 
    270269} 
    271270 
     
    276275                             private_key_t *key) 
    277276{ 
    278     pthread_rwlock_wrlock(&this->lock); 
     277    this->lock->write_lock(this->lock); 
    279278    DESTROY_IF(this->key); 
    280279    DESTROY_IF(this->usercert); 
    281280    this->key = key; 
    282281    this->usercert = cert; 
    283     pthread_rwlock_unlock(&this->lock); 
     282    this->lock->unlock(this->lock); 
    284283}    
    285284 
     
    307306{ 
    308307    clear(this); 
    309     pthread_rwlock_destroy(&this->lock); 
     308    this->lock->destroy(this->lock); 
    310309    free(this); 
    311310} 
     
    329328    this->public.destroy = (void(*)(nm_creds_t*))destroy; 
    330329     
    331     pthread_rwlock_init(&this->lock, NULL); 
     330    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    332331     
    333332    this->cert = NULL; 
  • trunk/src/charon/plugins/stroke/stroke_ca.c

    r4229 r4591  
    1717 */ 
    1818 
    19 #define _GNU_SOURCE 
    20 #include <pthread.h> 
    21  
    2219#include "stroke_ca.h" 
    2320#include "stroke_cred.h" 
    2421 
     22#include <utils/mutex.h> 
    2523#include <utils/linked_list.h> 
    2624#include <crypto/hashers/hasher.h> 
     
    4341     * read-write lock to lists 
    4442     */ 
    45     pthread_rwlock_t lock; 
     43    rwlock_t *lock; 
    4644     
    4745    /** 
     
    137135static void cdp_data_destroy(cdp_data_t *data) 
    138136{ 
    139     pthread_rwlock_unlock(&data->this->lock); 
     137    data->this->lock->unlock(data->this->lock); 
    140138    free(data); 
    141139} 
     
    237235    data->id = id; 
    238236     
    239     pthread_rwlock_rdlock(&this->lock); 
     237    this->lock->read_lock(this->lock); 
    240238    return enumerator_create_nested(this->sections->create_enumerator(this->sections), 
    241239            (type == CERT_X509) ? (void*)create_inner_cdp_hashandurl : (void*)create_inner_cdp, 
     
    279277            ca->certuribase = strdup(msg->add_ca.certuribase); 
    280278        } 
    281         pthread_rwlock_wrlock(&this->lock); 
     279        this->lock->write_lock(this->lock); 
    282280        this->sections->insert_last(this->sections, ca); 
    283         pthread_rwlock_unlock(&this->lock); 
     281        this->lock->unlock(this->lock); 
    284282        DBG1(DBG_CFG, "added ca '%s'", msg->add_ca.name); 
    285283    } 
     
    294292    ca_section_t *ca = NULL; 
    295293     
    296     pthread_rwlock_wrlock(&this->lock); 
     294    this->lock->write_lock(this->lock); 
    297295    enumerator = this->sections->create_enumerator(this->sections); 
    298296    while (enumerator->enumerate(enumerator, &ca)) 
     
    306304    } 
    307305    enumerator->destroy(enumerator); 
    308     pthread_rwlock_unlock(&this->lock); 
     306    this->lock->unlock(this->lock); 
    309307    if (ca == NULL) 
    310308    { 
     
    357355    } 
    358356     
    359     pthread_rwlock_wrlock(&this->lock); 
     357    this->lock->write_lock(this->lock); 
    360358    enumerator = this->sections->create_enumerator(this->sections); 
    361359    while (enumerator->enumerate(enumerator, (void**)&section)) 
     
    373371    } 
    374372    enumerator->destroy(enumerator); 
    375     pthread_rwlock_unlock(&this->lock); 
     373    this->lock->unlock(this->lock); 
    376374     
    377375    hasher->destroy(hasher); 
     
    387385    enumerator_t *enumerator; 
    388386     
    389     pthread_rwlock_rdlock(&this->lock); 
     387    this->lock->read_lock(this->lock); 
    390388    enumerator = this->sections->create_enumerator(this->sections); 
    391389    while (enumerator->enumerate(enumerator, (void**)&section)) 
     
    420418    } 
    421419    enumerator->destroy(enumerator); 
    422     pthread_rwlock_unlock(&this->lock); 
     420    this->lock->unlock(this->lock); 
    423421} 
    424422 
     
    429427{ 
    430428    this->sections->destroy_function(this->sections, (void*)ca_section_destroy); 
    431     pthread_rwlock_destroy(&this->lock); 
     429    this->lock->destroy(this->lock); 
    432430    free(this); 
    433431} 
     
    452450     
    453451    this->sections = linked_list_create(); 
    454     pthread_rwlock_init(&this->lock, NULL); 
     452    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    455453    this->cred = cred; 
    456454     
  • trunk/src/charon/plugins/stroke/stroke_cred.c

    r4317 r4591  
    1616 */ 
    1717 
    18 #define _GNU_SOURCE 
    19 #include <pthread.h> 
    2018#include <sys/stat.h> 
    2119#include <limits.h> 
     
    2927#include <utils/linked_list.h> 
    3028#include <utils/lexparser.h> 
     29#include <utils/mutex.h> 
    3130#include <asn1/pem.h> 
    3231#include <daemon.h> 
     
    7473     * read-write lock to lists 
    7574     */ 
    76     pthread_rwlock_t lock; 
     75    rwlock_t *lock; 
    7776     
    7877    /** 
     
    9594static void id_data_destroy(id_data_t *data) 
    9695{ 
    97     pthread_rwlock_unlock(&data->this->lock); 
     96    data->this->lock->unlock(data->this->lock); 
    9897    free(data); 
    9998} 
     
    141140    data->id = id; 
    142141     
    143     pthread_rwlock_rdlock(&this->lock); 
     142    this->lock->read_lock(this->lock); 
    144143    return enumerator_create_filter(this->private->create_enumerator(this->private), 
    145144                                    (void*)private_filter, data, 
     
    242241        data->id = id; 
    243242         
    244         pthread_rwlock_rdlock(&this->lock); 
     243        this->lock->read_lock(this->lock); 
    245244        return enumerator_create_filter(this->certs->create_enumerator(this->certs), 
    246245                    (cert == CERT_X509_CRL)? (void*)crl_filter : (void*)ac_filter, 
     
    255254    data->id = id; 
    256255     
    257     pthread_rwlock_rdlock(&this->lock); 
     256    this->lock->read_lock(this->lock); 
    258257    return enumerator_create_filter(this->certs->create_enumerator(this->certs), 
    259258                                    (void*)certs_filter, data, 
     
    273272static void shared_data_destroy(shared_data_t *data) 
    274273{ 
    275     pthread_rwlock_unlock(&data->this->lock); 
     274    data->this->lock->unlock(data->this->lock); 
    276275    free(data); 
    277276} 
     
    325324    data->other = other; 
    326325    data->type = type; 
    327     pthread_rwlock_rdlock(&this->lock); 
     326    this->lock->read_lock(this->lock); 
    328327    return enumerator_create_filter(this->shared->create_enumerator(this->shared), 
    329328                                    (void*)shared_filter, data, 
     
    340339    bool new = TRUE;     
    341340 
    342     pthread_rwlock_rdlock(&this->lock); 
     341    this->lock->read_lock(this->lock); 
    343342    enumerator = this->certs->create_enumerator(this->certs); 
    344343    while (enumerator->enumerate(enumerator, (void**)&current)) 
     
    359358        this->certs->insert_last(this->certs, cert); 
    360359    } 
    361     pthread_rwlock_unlock(&this->lock); 
     360    this->lock->unlock(this->lock); 
    362361    return cert; 
    363362} 
     
    401400    bool new = TRUE, found = FALSE;  
    402401 
    403     pthread_rwlock_wrlock(&this->lock); 
     402    this->lock->write_lock(this->lock); 
    404403    enumerator = this->certs->create_enumerator(this->certs); 
    405404    while (enumerator->enumerate(enumerator, (void**)&current)) 
     
    449448        this->certs->insert_last(this->certs, cert); 
    450449    } 
    451     pthread_rwlock_unlock(&this->lock); 
     450    this->lock->unlock(this->lock); 
    452451    return new; 
    453452} 
     
    460459    certificate_t *cert = &ac->certificate; 
    461460 
    462     pthread_rwlock_wrlock(&this->lock); 
     461    this->lock->write_lock(this->lock); 
    463462    this->certs->insert_last(this->certs, cert); 
    464     pthread_rwlock_unlock(&this->lock); 
     463    this->lock->unlock(this->lock); 
    465464    return TRUE; 
    466465} 
     
    699698    src = chunk; 
    700699 
    701     pthread_rwlock_wrlock(&this->lock); 
     700    this->lock->write_lock(this->lock); 
    702701    while (this->shared->remove_last(this->shared, 
    703702                                           (void**)&shared) == SUCCESS) 
     
    869868    } 
    870869error: 
    871     pthread_rwlock_unlock(&this->lock); 
     870    this->lock->unlock(this->lock); 
    872871    chunk_clear(&chunk); 
    873872} 
     
    950949    this->shared->destroy_offset(this->shared, offsetof(shared_key_t, destroy)); 
    951950    this->private->destroy_offset(this->private, offsetof(private_key_t, destroy)); 
    952     pthread_rwlock_destroy(&this->lock); 
     951    this->lock->destroy(this->lock); 
    953952    free(this); 
    954953} 
     
    975974    this->shared = linked_list_create(); 
    976975    this->private = linked_list_create(); 
    977     pthread_rwlock_init(&this->lock, NULL); 
     976    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    978977 
    979978    load_certs(this); 
  • trunk/src/libstrongswan/fetcher/fetcher_manager.c

    r4576 r4591  
    1616 */ 
    1717 
    18 #define _GNU_SOURCE 
    19 #include <pthread.h> 
    20  
    2118#include "fetcher_manager.h" 
    2219 
    2320#include <debug.h> 
     21#include <utils/mutex.h> 
    2422#include <utils/linked_list.h> 
    25 #include <utils/mutex.h> 
    2623 
    2724typedef struct private_fetcher_manager_t private_fetcher_manager_t; 
     
    4542     * read write lock to list 
    4643     */ 
    47     pthread_rwlock_t lock; 
     44    rwlock_t *lock; 
    4845}; 
    4946 
     
    7572    bool capable = FALSE; 
    7673     
    77     pthread_rwlock_rdlock(&this->lock); 
     74    this->lock->read_lock(this->lock); 
    7875    enumerator = this->fetchers->create_enumerator(this->fetchers); 
    7976    while (enumerator->enumerate(enumerator, &entry)) 
     
    133130    } 
    134131    enumerator->destroy(enumerator); 
    135     pthread_rwlock_unlock(&this->lock); 
     132    this->lock->unlock(this->lock); 
    136133    if (!capable) 
    137134    { 
     
    152149    entry->create = create; 
    153150 
    154     pthread_rwlock_wrlock(&this->lock); 
     151    this->lock->write_lock(this->lock); 
    155152    this->fetchers->insert_last(this->fetchers, entry); 
    156     pthread_rwlock_unlock(&this->lock); 
     153    this->lock->unlock(this->lock); 
    157154} 
    158155 
     
    166163    entry_t *entry; 
    167164     
    168     pthread_rwlock_wrlock(&this->lock); 
     165    this->lock->write_lock(this->lock); 
    169166    enumerator = this->fetchers->create_enumerator(this->fetchers); 
    170167    while (enumerator->enumerate(enumerator, &entry)) 
     
    177174    } 
    178175    enumerator->destroy(enumerator); 
    179     pthread_rwlock_unlock(&this->lock); 
     176    this->lock->unlock(this->lock); 
    180177} 
    181178 
     
    186183{ 
    187184    this->fetchers->destroy_function(this->fetchers, (void*)entry_destroy); 
    188     pthread_rwlock_destroy(&this->lock); 
     185    this->lock->destroy(this->lock); 
    189186    free(this); 
    190187} 
     
    203200     
    204201    this->fetchers = linked_list_create(); 
    205     pthread_rwlock_init(&this->lock, NULL); 
     202    this->lock = rwlock_create(RWLOCK_DEFAULT); 
    206203     
    207204    return &this->public; 
  • trunk/src/libstrongswan/utils/mutex.c

    r4590 r4591  
    1616 */ 
    1717 
    18 #include "mutex.h" 
    19  
    20 #include <library.h> 
    21 #include <debug.h> 
    22  
     18#define _GNU_SOURCE 
    2319#include <pthread.h> 
    2420#include <sys/time.h> 
     
    2622#include <time.h> 
    2723#include <errno.h> 
     24 
     25#include "mutex.h" 
     26 
     27#include <library.h> 
     28#include <debug.h> 
    2829 
    2930typedef struct private_mutex_t private_mutex_t; 
     
    442443 
    443444/** 
     445 * Implementation of rwlock_t.try_write_lock 
     446 */ 
     447static bool try_write_lock(private_rwlock_t *this) 
     448{ 
     449    return pthread_rwlock_trywrlock(&this->rwlock) == 0; 
     450} 
     451 
     452/** 
    444453 * Implementation of rwlock_t.unlock 
    445454 */ 
     
    473482            this->public.read_lock = (void(*)(rwlock_t*))read_lock; 
    474483            this->public.write_lock = (void(*)(rwlock_t*))write_lock; 
     484            this->public.try_write_lock = (bool(*)(rwlock_t*))try_write_lock; 
    475485            this->public.unlock = (void(*)(rwlock_t*))rw_unlock; 
    476486            this->public.destroy = (void(*)(rwlock_t*))rw_destroy; 
  • trunk/src/libstrongswan/utils/mutex.h

    r4590 r4591  
    131131     
    132132    /** 
     133     * Try to acquire the write lock. 
     134     * 
     135     * Never blocks, but returns FALSE if the lock was already occupied. 
     136     * 
     137     * @return      TRUE if lock acquired 
     138     */ 
     139    bool (*try_write_lock)(rwlock_t *this);  
     140     
     141    /** 
    133142     * Release any acquired lock. 
    134143     */