completion.c 2.3 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#include <stdlib.h>
#include "mobject-store-config.h"
#include "libmobject-store.h"
10
#include "src/client/aio/completion.h"
Matthieu Dorier's avatar
Matthieu Dorier committed
11
#include "src/util/log.h"
12
#if 0
Matthieu Dorier's avatar
Matthieu Dorier committed
13 14 15 16 17 18 19 20 21 22 23 24
int mobject_store_aio_create_completion(void *cb_arg,
                                mobject_store_callback_t cb_complete,
                                mobject_store_callback_t cb_safe,
                                mobject_store_completion_t *pc)
{
	int r;
	mobject_store_completion_t completion = 
		(mobject_store_completion_t)calloc(1, sizeof(struct mobject_store_completion));
	MOBJECT_ASSERT(completion != 0, "Could not allocate mobject_store_completion_t object"); 
	completion->cb_complete   = cb_complete;
	completion->cb_safe       = cb_safe;
	completion->cb_arg        = cb_arg;
Matthieu Dorier's avatar
Matthieu Dorier committed
25
    completion->request       = MARGO_REQUEST_NULL;
Matthieu Dorier's avatar
Matthieu Dorier committed
26 27 28 29 30 31 32 33 34 35
	*pc = completion;
	return 0;
}

int mobject_store_aio_wait_for_complete(mobject_store_completion_t c)
{
	if(c == MOBJECT_COMPLETION_NULL) {
		MOBJECT_LOG("Warning: passing NULL to mobject_store_aio_wait_for_complete");
		return -1;
	}
Matthieu Dorier's avatar
Matthieu Dorier committed
36 37 38 39 40
    
    MOBJECT_ASSERT(c->request != MARGO_REQUEST_NULL, "Invalid completion handle");
    c->ret_value = margo_wait(c->request);
    if(c->ret_value != HG_SUCCESS) {
        MOBJECT_LOG("Warning: margo_wait returned something different from HG_SUCCESS");
41
    }
Matthieu Dorier's avatar
Matthieu Dorier committed
42 43 44 45
    c->request = MARGO_REQUEST_NULL;

    if(c->cb_safe)
        (c->cb_safe)(c, c->cb_arg);
46

Matthieu Dorier's avatar
Matthieu Dorier committed
47 48
    if(c->cb_complete)
        (c->cb_complete)(c, c->cb_arg);
Matthieu Dorier's avatar
Matthieu Dorier committed
49 50 51 52 53 54

	return 0;
}

int mobject_store_aio_is_complete(mobject_store_completion_t c)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
55 56
    MOBJECT_ASSERT(0,"mobject_store_aio_is_complete is not yet implemented");
    return 0;
Matthieu Dorier's avatar
Matthieu Dorier committed
57 58 59 60 61 62 63 64 65
}

int mobject_store_aio_get_return_value(mobject_store_completion_t c)
{
	int r;
	if(c == MOBJECT_COMPLETION_NULL) {
		MOBJECT_LOG("Warning: passing NULL to mobject_store_aio_get_return_value");
		return 0;
	}
Matthieu Dorier's avatar
Matthieu Dorier committed
66
    MOBJECT_ASSERT((c->request == MARGO_REQUEST_NULL), 
67
        "calling mobject_store_aio_get_return_value on a non-terminated completion");
Matthieu Dorier's avatar
Matthieu Dorier committed
68
	return c->ret_value;
Matthieu Dorier's avatar
Matthieu Dorier committed
69 70 71 72
}

void mobject_store_aio_release(mobject_store_completion_t c)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
73 74 75
    if(c == MOBJECT_COMPLETION_NULL) return;
    MOBJECT_ASSERT(c->request != MARGO_REQUEST_NULL,
        "Trying to release a completion handle before operation completed");
Matthieu Dorier's avatar
Matthieu Dorier committed
76 77
	free(c);
}
78
#endif