Navigation Menu

Skip to content

Commit

Permalink
io: remove unused map/unmap functions
Browse files Browse the repository at this point in the history
The following functions aren't used:

  * grn_io_win_map()
  * grn_io_win_mapv() # no implementation
  * grn_io_win_unmap()

All codes use the following function instead:

  * grn_io_win_map2()
  * grn_io_win_unmap2()
  • Loading branch information
kou committed Jan 7, 2015
1 parent de05414 commit 4848151
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 147 deletions.
5 changes: 0 additions & 5 deletions lib/grn_io.h
Expand Up @@ -134,11 +134,6 @@ grn_rc grn_io_size(grn_ctx *ctx, grn_io *io, uint64_t *size);
grn_rc grn_io_rename(grn_ctx *ctx, const char *old_name, const char *new_name);
GRN_API void *grn_io_header(grn_io *io);

void *grn_io_win_map(grn_io *io, grn_ctx *ctx, grn_io_win *iw, uint32_t segment,
uint32_t offset, uint32_t size, grn_io_rw_mode mode);
grn_rc grn_io_win_mapv(grn_io_win **list, grn_ctx *ctx, int nent);
grn_rc grn_io_win_unmap(grn_io_win *iw);

void *grn_io_win_map2(grn_io *io, grn_ctx *ctx, grn_io_win *iw, uint32_t segment,
uint32_t offset, uint32_t size, grn_io_rw_mode mode);
grn_rc grn_io_win_unmap2(grn_io_win *iw);
Expand Down
142 changes: 0 additions & 142 deletions lib/io.c
Expand Up @@ -844,148 +844,6 @@ grn_io_write_ja_ehead(grn_io *io, grn_ctx *ctx, uint32_t key,
}
}

void *
grn_io_win_map(grn_io *io, grn_ctx *ctx, grn_io_win *iw, uint32_t segment,
uint32_t offset, uint32_t size, grn_io_rw_mode mode)
{
byte *p;
off_t pos, base;
int fno;
uint32_t nseg, bseg;
uint32_t segment_size = io->header->segment_size;
uint32_t segments_per_file = GRN_IO_FILE_SIZE / segment_size;
iw->ctx = ctx;
iw->diff = 0;
if (offset >= segment_size) {
segment += offset / segment_size;
offset = offset % segment_size;
}
nseg = (offset + size + segment_size - 1) / segment_size;
bseg = segment + io->base_seg;
fno = bseg / segments_per_file;
base = fno ? 0 : io->base - (uint64_t)segment_size * io->base_seg;
pos = (uint64_t)segment_size * (bseg % segments_per_file) + offset + base;
if (!size || !io || segment + nseg > io->header->max_segment ||
fno != (bseg + nseg - 1) / segments_per_file) {
return NULL;
}
switch (mode) {
case grn_io_rdonly:
{
fileinfo *fi = &io->fis[fno];
if (!grn_opened(fi)) {
char path[PATH_MAX];
gen_pathname(io->path, path, fno);
if (grn_open(ctx, fi, path, O_RDWR|O_CREAT, GRN_IO_FILE_SIZE)) {
return NULL;
}
}
if (!(p = GRN_MALLOC(size))) { return NULL; }
if (grn_pread(ctx, fi, p, size, pos)) {
GRN_FREE(p);
return NULL;
}
iw->addr = p;
}
break;
case grn_io_rdwr:
// if (nseg > 1) { /* auto unmap is not implemented yet */
if (nseg > 0) {
fileinfo *fi = &io->fis[fno];
if (!grn_opened(fi)) {
char path[PATH_MAX];
gen_pathname(io->path, path, fno);
if (grn_open(ctx, fi, path, O_RDWR|O_CREAT, GRN_IO_FILE_SIZE)) {
return NULL;
}
}
if (!(p = GRN_MMAP(&grn_gctx, &iw->fmo, fi, pos, (uint64_t)segment_size * nseg))) {
return NULL;
}
{
uint64_t tail = io->base + (uint64_t)segment_size * segment + offset + size;
if (tail > io->header->curr_size) { io->header->curr_size = tail; }
}
} else {
GRN_LOG(ctx, GRN_LOG_ALERT, "nseg == 0! in grn_io_win_map(%p, %u, %u, %u)", io, segment, offset, size);
// GRN_IO_SEG_REF(io, segment, p); if (!p) { return NULL; }
return NULL;
}
iw->addr = p + offset;
break;
case grn_io_wronly:
if (!(p = GRN_MALLOC(size))) { return NULL; }
memset(p, 0, size);
iw->cached = 0;
iw->addr = p;
break;
default :
return NULL;
}
iw->io = io;
iw->mode = mode;
iw->segment = segment;
iw->offset = offset;
iw->nseg = nseg;
iw->size = size;
iw->pos = pos;
return iw->addr;
}

grn_rc
grn_io_win_unmap(grn_io_win *iw)
{
grn_rc rc = GRN_SUCCESS;
grn_io *io = iw->io;
grn_ctx *ctx = iw->ctx;
uint32_t segment_size = io->header->segment_size;
uint32_t segments_per_file = GRN_IO_FILE_SIZE / segment_size;
int nseg = iw->nseg;
switch (iw->mode) {
case grn_io_rdonly:
if (iw->addr) { GRN_FREE(iw->addr); }
iw->addr = NULL;
break;
case grn_io_rdwr:
// if (nseg > 1) { /* auto unmap is not implemented yet */
if (nseg > 0) {
GRN_MUNMAP(&grn_gctx, &iw->fmo, ((byte *)iw->addr) - iw->offset, (uint64_t)segment_size * nseg);
} else {
if (iw->segment >= io->header->max_segment) {
rc = GRN_INVALID_ARGUMENT;
} else {
//GRN_IO_SEG_UNREF(io, iw->segment);
}
}
iw->addr = NULL;
break;
case grn_io_wronly:
{
int fno = (iw->segment + io->base_seg) / segments_per_file;
fileinfo *fi = &io->fis[fno];
if (!grn_opened(fi)) {
char path[PATH_MAX];
gen_pathname(io->path, path, fno);
rc = grn_open(ctx, fi, path, O_RDWR|O_CREAT, GRN_IO_FILE_SIZE);
}
if (!rc) {
if (!(rc = grn_pwrite(ctx, fi, iw->addr, iw->size, iw->pos))) {
{
uint64_t tail = io->base + (uint64_t)segment_size * iw->segment + iw->offset + iw->size;
if (tail > io->header->curr_size) { io->header->curr_size = tail; }
}
if (!iw->cached) { GRN_FREE(iw->addr); }
iw->addr = NULL;
}
}
}
break;
default :
rc = GRN_INVALID_ARGUMENT;
}
return rc;
}

void *
grn_io_win_map2(grn_io *io, grn_ctx *ctx, grn_io_win *iw, uint32_t segment,
uint32_t offset, uint32_t size, grn_io_rw_mode mode)
Expand Down

0 comments on commit 4848151

Please sign in to comment.