Commit db2ddfab authored by Philip Carns's avatar Philip Carns
Browse files

close wrapper

parent 12e09b0f
......@@ -11,6 +11,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <openssl/rand.h>
#include <errno.h>
#include <abt.h>
#include <abt-io.h>
......@@ -176,27 +177,42 @@ static void worker_ult(void *_arg)
ret = RAND_bytes(buffer, arg->opt_unit_size);
assert(ret == 1);
sprintf(template, "./XXXXXX");
sprintf(template, "./data-XXXXXX");
if(arg->opt_abt_io)
{
fd = abt_io_mkostemp(arg->aid, template, O_DIRECT|O_SYNC);
if(fd < 0)
{
fprintf(stderr, "abt_io_mkostemp: %d\n", fd);
}
assert(fd >= 0);
ret = abt_io_pwrite(arg->aid, fd, buffer, arg->opt_unit_size, 0);
assert(ret == arg->opt_unit_size);
ret = abt_io_close(arg->aid, fd);
assert(ret == 0);
ret = abt_io_unlink(arg->aid, template);
assert(ret == 0);
}
else
{
fd = mkostemp(template, O_DIRECT|O_SYNC);
if(fd < 0)
{
perror("mkostemp");
fprintf(stderr, "errno: %d\n", errno);
}
assert(fd >= 0);
ret = pwrite(fd, buffer, arg->opt_unit_size, 0);
assert(ret == arg->opt_unit_size);
ret = close(fd);
assert(ret == 0);
ret = unlink(template);
assert(ret == 0);
}
......
......@@ -54,6 +54,11 @@ int abt_io_mkostemp(abt_io_instance_id aid, char *template, int flags);
*/
int abt_io_unlink(abt_io_instance_id aid, const char *pathname);
/**
* wrapper for close()
*/
int abt_io_close(abt_io_instance_id aid, int fd);
#ifdef __cplusplus
}
#endif
......
......@@ -217,4 +217,43 @@ int abt_io_unlink(abt_io_instance_id aid, const char *pathname)
return(state.ret);
}
struct abt_io_close_state
{
int ret;
int fd;
};
static void abt_io_close_fn(void *foo)
{
struct abt_io_close_state *state = foo;
state->ret = close(state->fd);
if(state->ret < 0)
state->ret = -errno;
return;
}
int abt_io_close(abt_io_instance_id aid, int fd)
{
struct abt_io_close_state state;
int ret;
ABT_thread tid;
state.ret = -ENOSYS;
state.fd = fd;
ret = ABT_thread_create(aid->progress_pool, abt_io_close_fn, &state,
ABT_THREAD_ATTR_NULL, &tid);
if(ret != 0)
{
return(-EINVAL);
}
ABT_thread_join(tid);
ABT_thread_free(&tid);
return(state.ret);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment