Пример #1
0
/*
 * returns a pointer to a table, or NULL if fails
 */
struct table *bucket_get_table(struct bucket *bucket, int64_t id, int flags) {
    struct table *table;
    int wrlocked;

    if (bucket == NULL)
        return NULL;
        
    wrlocked = 0;
    pthread_rwlock_rdlock(&bucket->rwlock);

again:
    HASH_FIND_INT64(bucket->tables, &id, table);
    
    if (table == NULL) {
        if (wrlocked == 0) {
            pthread_rwlock_unlock(&bucket->rwlock);
            pthread_rwlock_wrlock(&bucket->rwlock);
            wrlocked = 1;
            goto again;
        }
        table = table_create_and_read(bucket, id, flags);
        if (table)
            HASH_ADD_INT64(bucket->tables, id, table);
    }

    pthread_rwlock_unlock(&bucket->rwlock);
    return table;
}
Пример #2
0
struct schema *schema_get_from_hash(uint64_t hash, const char *bucket_name) {
    struct schema *schema;
    pthread_mutex_lock(&mutex);
    HASH_FIND_INT64(schemas, &hash, schema);
    if (schema == NULL) {
        schema = schema_create_from_hash(hash, bucket_name);
        if (schema)
            HASH_ADD_INT64(schemas, hash, schema);
    }
    pthread_mutex_unlock(&mutex);
    return schema;
}
Пример #3
0
struct lensum_hash* find_lens(struct lensum_hash* lensums, int64 id) {
    // a single file reference, don't allocate
    struct lensum_hash* alensum=NULL;
    HASH_FIND_INT64(lensums, &id, alensum);
    return alensum;
}
Пример #4
0
struct point_hash* point_hash_find(struct point_hash* self, int64 id) {
    struct point_hash* pth=NULL;
    HASH_FIND_INT64(self, &id, pth);
    return pth;
}