当前位置: 首页>>代码示例>>C++>>正文


C++ GF_CALLOC函数代码示例

本文整理汇总了C++中GF_CALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ GF_CALLOC函数的具体用法?C++ GF_CALLOC怎么用?C++ GF_CALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GF_CALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: event_pool_new_epoll

static struct event_pool *
event_pool_new_epoll (int count, int eventthreadcount)
{
        struct event_pool *event_pool = NULL;
        int                epfd = -1;

        event_pool = GF_CALLOC (1, sizeof (*event_pool),
                                gf_common_mt_event_pool);

        if (!event_pool)
                goto out;

        epfd = epoll_create (count);

        if (epfd == -1) {
                gf_msg ("epoll", GF_LOG_ERROR, errno,
                        LG_MSG_EPOLL_FD_CREATE_FAILED, "epoll fd creation "
                        "failed");
                GF_FREE (event_pool->reg);
                GF_FREE (event_pool);
                event_pool = NULL;
                goto out;
        }

        event_pool->fd = epfd;

        event_pool->count = count;

        event_pool->eventthreadcount = eventthreadcount;

        pthread_mutex_init (&event_pool->mutex, NULL);

out:
        return event_pool;
}
开发者ID:lkzhd,项目名称:glusterfs-annotation,代码行数:35,代码来源:event-epoll.c

示例2: xlator_volopt_dynload

int
xlator_volopt_dynload (char *xlator_type, void **dl_handle,
                       volume_opt_list_t *opt_list)
{
        int                     ret = -1;
        char                    *name = NULL;
        void                    *handle = NULL;
        volume_opt_list_t       *vol_opt = NULL;

        GF_VALIDATE_OR_GOTO ("xlator", xlator_type, out);

        GF_ASSERT (dl_handle);

        if (*dl_handle)
                if (dlclose (*dl_handle))
                        gf_log ("xlator", GF_LOG_WARNING, "Unable to close "
                                  "previously opened handle( may be stale)."
                                  "Ignoring the invalid handle");

        ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xlator_type);
        if (-1 == ret) {
                gf_log ("xlator", GF_LOG_ERROR, "asprintf failed");
                goto out;
        }

        ret = -1;

        gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name);

        handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL);
        if (!handle) {
                gf_log ("xlator", GF_LOG_WARNING, "%s", dlerror ());
                goto out;
        }
        *dl_handle = handle;


        vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),
                         gf_common_mt_volume_opt_list_t);

        if (!vol_opt) {
                goto out;
        }

        if (!(vol_opt->given_opt = dlsym (handle, "options"))) {
                dlerror ();
                gf_log ("xlator", GF_LOG_DEBUG,
                         "Strict option validation not enforced -- neglecting");
        }
        opt_list->given_opt = vol_opt->given_opt;

        INIT_LIST_HEAD (&vol_opt->list);
        list_add_tail (&vol_opt->list, &opt_list->list);

        ret = 0;
 out:
        gf_log ("xlator", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;

}
开发者ID:BillTheBest,项目名称:glusterfs,代码行数:60,代码来源:xlator.c

示例3: lic_dict_add_words

int lic_dict_add_words(dict_t *dict, const char **words, int wordcount)
{
        char  *cmd = NULL;
	int   len = 0;
	int   i = 0;
	int   ret = 0;

	for (i=0; i<wordcount; i++)
                len += strlen(words[i]) + 1;

	if (len < 1)
		goto out;

        cmd = GF_CALLOC(1, len, gf_common_mt_char);
	if (!cmd) {
		ret = -1;
		goto out;
	}

        for (i=0; i<wordcount; i++) {
                strncat(cmd, words[i], strlen(words[i]));
                if (i < wordcount-1)
                        strncat (cmd, " ", strlen (" "));
        }

        ret = dict_set_dynstr (dict, "cmd-str", cmd);
        if (ret)
                goto out;

out:
	return ret;
}
开发者ID:beback1986,项目名称:MyGitProject,代码行数:32,代码来源:lic_rpc_ops.c

示例4: event_pool_new_epoll

static struct event_pool *
event_pool_new_epoll (int count, int eventthreadcount)
{
        struct event_pool *event_pool = NULL;
        int                epfd = -1;

        event_pool = GF_CALLOC (1, sizeof (*event_pool),
                                gf_common_mt_event_pool);

        if (!event_pool)
                goto out;

        epfd = epoll_create (count);

        if (epfd == -1) {
                gf_log ("epoll", GF_LOG_ERROR, "epoll fd creation failed (%s)",
                        strerror (errno));
                GF_FREE (event_pool->reg);
                GF_FREE (event_pool);
                event_pool = NULL;
                goto out;
        }

        event_pool->fd = epfd;

        event_pool->count = count;

        event_pool->eventthreadcount = eventthreadcount;

        pthread_mutex_init (&event_pool->mutex, NULL);

out:
        return event_pool;
}
开发者ID:RichWpg,项目名称:glusterfs,代码行数:34,代码来源:event-epoll.c

示例5: make_export_path

int
make_export_path (const char *real_path, char **path)
{
    int     ret = -1;
    char   *tmp = NULL;
    char   *export_path = NULL;
    char   *dup = NULL;
    char   *ptr = NULL;
    char   *freeptr = NULL;
    uuid_t  gfid = {0, };

    export_path = GF_CALLOC (1, sizeof (char) * PATH_MAX, 0);
    if (!export_path)
        goto out;

    dup = gf_strdup (real_path);
    if (!dup)
        goto out;

    freeptr = dup;
    ret = solaris_getxattr ("/", GFID_XATTR_KEY, gfid, 16);
    /* Return value of getxattr */
    if (ret == 16) {
        if (__is_root_gfid (gfid)) {
            strcat (export_path, "/");
            ret = 0;
            goto done;
        }
    }

    do {
        ptr = strtok_r (dup, "/", &tmp);
        if (!ptr)
            break;
        strcat (export_path, dup);
        ret = solaris_getxattr (export_path, GFID_XATTR_KEY, gfid, 16);
        if (ret == 16) {
            if (__is_root_gfid (gfid)) {
                ret = 0;
                goto done;
            }
        }
        strcat (export_path, "/");
        dup = tmp;
    } while (ptr);

    goto out;

done:
    if (!ret) {
        *path = export_path;
    }
out:
    if (freeptr)
        GF_FREE (freeptr);
    if (ret && export_path)
        GF_FREE (export_path);

    return ret;
}
开发者ID:rambhatm,项目名称:glusterfs,代码行数:60,代码来源:compat.c

示例6: gf_timer_registry_init

gf_timer_registry_t *
gf_timer_registry_init (glusterfs_ctx_t *ctx)
{
        if (ctx == NULL) {
                gf_log_callingfn ("timer", GF_LOG_ERROR, "invalid argument");
                return NULL;
        }

        if (!ctx->timer) {
                gf_timer_registry_t *reg = NULL;

                reg = GF_CALLOC (1, sizeof (*reg),
                                 gf_common_mt_gf_timer_registry_t);
                if (!reg)
                        goto out;

                pthread_mutex_init (&reg->lock, NULL);
                reg->active.next = &reg->active;
                reg->active.prev = &reg->active;
                reg->stale.next = &reg->stale;
                reg->stale.prev = &reg->stale;

                ctx->timer = reg;
                pthread_create (&reg->th, NULL, gf_timer_proc, ctx);
        }
out:
        return ctx->timer;
}
开发者ID:lkundrak,项目名称:glusterfs,代码行数:28,代码来源:timer.c

示例7: _exports_file_init

/**
 * _export_file_init -- Initialize an exports file structure.
 *
 * @return  : success: Pointer to an allocated exports file struct
 *            failure: NULL
 *
 * Not for external use.
 */
struct exports_file *
_exports_file_init()
{
    struct exports_file *file = NULL;

    file = GF_CALLOC(1, sizeof(*file), gf_common_mt_nfs_exports);
    if (!file) {
        gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
               "Failed to allocate file struct!");
        goto out;
    }

    file->exports_dict = dict_new();
    file->exports_map = dict_new();
    if (!file->exports_dict || !file->exports_map) {
        gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
               "Failed to allocate dict!");
        goto free_and_out;
    }

    goto out;

free_and_out:
    if (file->exports_dict)
        dict_unref(file->exports_dict);

    GF_FREE(file);
    file = NULL;
out:
    return file;
}
开发者ID:gluster,项目名称:glusterfs,代码行数:39,代码来源:exports.c

示例8: glusterfs_ctx_defaults_init

static int
glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
{
        cmd_args_t    *cmd_args = NULL;
        struct rlimit  lim = {0, };
        call_pool_t   *pool = NULL;

        xlator_mem_acct_init (THIS, cli_mt_end);

        ctx->process_uuid = generate_uuid ();
        if (!ctx->process_uuid)
                return -1;

        ctx->page_size  = 128 * GF_UNIT_KB;

        ctx->iobuf_pool = iobuf_pool_new (8 * GF_UNIT_MB, ctx->page_size);
        if (!ctx->iobuf_pool)
                return -1;

        ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE);
        if (!ctx->event_pool)
                return -1;

        pool = GF_CALLOC (1, sizeof (call_pool_t),
                          cli_mt_call_pool_t);
        if (!pool)
                return -1;

        /* frame_mem_pool size 112 * 16k */
        pool->frame_mem_pool = mem_pool_new (call_frame_t, 16384);

        if (!pool->frame_mem_pool)
                return -1;

        /* stack_mem_pool size 256 * 8k */
        pool->stack_mem_pool = mem_pool_new (call_stack_t, 8192); 

        if (!pool->stack_mem_pool)
                return -1;

        ctx->stub_mem_pool = mem_pool_new (call_stub_t, 1024);
        if (!ctx->stub_mem_pool)
                return -1;

        INIT_LIST_HEAD (&pool->all_frames);
        LOCK_INIT (&pool->lock);
        ctx->pool = pool;

        pthread_mutex_init (&(ctx->lock), NULL);

        cmd_args = &ctx->cmd_args;

        INIT_LIST_HEAD (&cmd_args->xlator_options);

        lim.rlim_cur = RLIM_INFINITY;
        lim.rlim_max = RLIM_INFINITY;
        setrlimit (RLIMIT_CORE, &lim);

        return 0;
}
开发者ID:Dhandapani,项目名称:glusterfs,代码行数:60,代码来源:cli.c

示例9: gf_clienttable_alloc

clienttable_t *
gf_clienttable_alloc (void)
{
        clienttable_t *clienttable = NULL;
        int            result = 0;

        clienttable =
                GF_CALLOC (1, sizeof (clienttable_t), gf_common_mt_clienttable_t);
        if (!clienttable)
                return NULL;

        LOCK_INIT (&clienttable->lock);

        result = gf_client_clienttable_expand (clienttable,
                                               GF_CLIENTTABLE_INITIAL_SIZE);
        if (result != 0) {
                gf_msg ("client_t", GF_LOG_ERROR, 0,
                        LG_MSG_EXPAND_CLIENT_TABLE_FAILED,
                        "gf_client_clienttable_expand failed");
                GF_FREE (clienttable);
                return NULL;
        }

        return clienttable;
}
开发者ID:rlugojr,项目名称:glusterfs,代码行数:25,代码来源:client_t.c

示例10: runner_log

void
runner_log (runner_t *runner, const char *dom, gf_loglevel_t lvl,
            const char *msg)
{
        char *buf = NULL;
        size_t len = 0;
        int i = 0;

        if (runner->runerr)
                return;

        for (i = 0;; i++) {
                if (runner->argv[i] == NULL)
                        break;
                len += (strlen (runner->argv[i]) + 1);
        }

        buf = GF_CALLOC (1, len + 1, gf_common_mt_run_logbuf);
        if (!buf) {
                runner->runerr = errno;
                return;
        }
        for (i = 0;; i++) {
                if (runner->argv[i] == NULL)
                        break;
                strcat (buf, runner->argv[i]);
                strcat (buf, " ");
        }
        if (len > 0)
                buf[len - 1] = '\0';

        gf_msg_callingfn (dom, lvl, 0, LG_MSG_RUNNER_LOG, "%s: %s", msg, buf);

        GF_FREE (buf);
}
开发者ID:2510,项目名称:glusterfs,代码行数:35,代码来源:run.c

示例11: br_stub_fd_new

br_stub_fd_t *
br_stub_fd_new(void)
{
    br_stub_fd_t *br_stub_fd = NULL;

    br_stub_fd = GF_CALLOC(1, sizeof(*br_stub_fd), gf_br_stub_mt_br_stub_fd_t);

    return br_stub_fd;
}
开发者ID:gluster,项目名称:glusterfs,代码行数:9,代码来源:bit-rot-stub-helpers.c

示例12: strfd_open

strfd_t *
strfd_open ()
{
        strfd_t *strfd = NULL;

        strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t);

        return strfd;
}
开发者ID:2510,项目名称:glusterfs,代码行数:9,代码来源:strfd.c

示例13: mem_pool_new_fn

struct mem_pool *
mem_pool_new_fn (unsigned long sizeof_type,
                 unsigned long count)
{
        struct mem_pool  *mem_pool = NULL;
        unsigned long     padded_sizeof_type = 0;
        void             *pool = NULL;
        int               i = 0;
        struct list_head *list = NULL;

        if (!sizeof_type || !count) {
                gf_log ("mem-pool", GF_LOG_ERROR, "invalid argument");
                return NULL;
        }
        padded_sizeof_type = sizeof_type + GF_MEM_POOL_PAD_BOUNDARY;

        mem_pool = GF_CALLOC (sizeof (*mem_pool), 1, gf_common_mt_mem_pool);
        if (!mem_pool)
                return NULL;

        LOCK_INIT (&mem_pool->lock);
        INIT_LIST_HEAD (&mem_pool->list);

        mem_pool->padded_sizeof_type = padded_sizeof_type;
        mem_pool->cold_count = count;
        mem_pool->real_sizeof_type = sizeof_type;

        pool = GF_CALLOC (count, padded_sizeof_type, gf_common_mt_long);
        if (!pool) {
                GF_FREE (mem_pool);
                return NULL;
        }

        for (i = 0; i < count; i++) {
                list = pool + (i * (padded_sizeof_type));
                INIT_LIST_HEAD (list);
                list_add_tail (list, &mem_pool->list);
        }

        mem_pool->pool = pool;
        mem_pool->pool_end = pool + (count * (padded_sizeof_type));

        return mem_pool;
}
开发者ID:vbellur,项目名称:glusterfs,代码行数:44,代码来源:mem-pool.c

示例14: alloc_format

int32_t alloc_format(crypt_local_t *local, size_t size)
{
	if (size > 0) {
		local->format = GF_CALLOC(1, size, gf_crypt_mt_mtd);
		if (!local->format)
			return ENOMEM;
	}
	local->format_size = size;
	return 0;
}
开发者ID:Anna-Miya-Dan,项目名称:glusterfs,代码行数:10,代码来源:metadata.c

示例15: _export_dir_init

/**
 * _export_dir_init -- Initialize an export directory structure.
 *
 * @return  : success: Pointer to an allocated exports directory struct
 *            failure: NULL
 *
 * Not for external use.
 */
static struct export_dir *
_export_dir_init()
{
    struct export_dir *expdir = GF_CALLOC(1, sizeof(*expdir),
                                          gf_common_mt_nfs_exports);

    if (!expdir)
        gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
               "Failed to allocate export dir structure!");

    return expdir;
}
开发者ID:gluster,项目名称:glusterfs,代码行数:20,代码来源:exports.c


注:本文中的GF_CALLOC函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。