Ejemplo n.º 1
0
RmHasherTask *rm_hasher_task_new(RmHasher *hasher, RmDigest *digest,
                                 gpointer task_user_data) {
    g_mutex_lock(&hasher->lock);
    { hasher->active_tasks++; }
    g_mutex_unlock(&hasher->lock);

    RmHasherTask *self = g_slice_new0(RmHasherTask);
    self->hasher = hasher;
    if(digest) {
        self->digest = digest;
    } else {
        self->digest = rm_digest_new(hasher->digest_type, 0, 0, 0,
                                     hasher->digest_type == RM_DIGEST_PARANOID);
    }

    /* get a recycled hashpipe if available */
    self->hashpipe = g_async_queue_try_pop(hasher->hashpipe_pool);
    if(!self->hashpipe) {
        if(g_atomic_int_get(&hasher->unalloc_hashpipes) > 0) {
            /* create a new hashpipe */
            g_atomic_int_dec_and_test(&hasher->unalloc_hashpipes);
            self->hashpipe =
                rm_util_thread_pool_new((GFunc)rm_hasher_hashpipe_worker, hasher, 1);

        } else {
            /* already at thread limit - wait for a hashpipe to come available */
            self->hashpipe = g_async_queue_pop(hasher->hashpipe_pool);
        }
    }
    rm_assert_gentle(self->hashpipe);

    self->task_user_data = task_user_data;
    return self;
}
Ejemplo n.º 2
0
void rm_mds_start(RmMDS *mds) {
    guint disk_count = g_hash_table_size(mds->disks);
    guint threads = CLAMP(mds->threads_per_disk * disk_count, 1, (guint)mds->max_threads);
    rm_log_debug_line("Starting MDS scheduler with %i threads", threads);

    mds->pool = rm_util_thread_pool_new((GFunc)rm_mds_factory, mds, threads);
    mds->running = TRUE;
    GList *disks = g_hash_table_get_values(mds->disks);
    g_list_foreach(disks, (GFunc)rm_mds_device_start, mds);
    g_list_free(disks);
}