Navigation Menu

Skip to content

Commit

Permalink
io: share common code to compute base segment address
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 16, 2015
1 parent c3d125c commit bd55bd9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/io.c
Expand Up @@ -111,6 +111,12 @@ grn_io_compute_base(uint32_t header_size)
return (total_header_size + grn_pagesize - 1) & ~(grn_pagesize - 1);
}

static inline uint32_t
grn_io_compute_base_segment(uint32_t base, uint32_t segment_size)
{
return (base + segment_size - 1) / segment_size;
}

grn_io *
grn_io_create_tmp(uint32_t header_size, uint32_t segment_size,
uint32_t max_segment, grn_io_mode mode, uint32_t flags)
Expand Down Expand Up @@ -207,7 +213,7 @@ grn_io_create(grn_ctx *ctx, const char *path, uint32_t header_size, uint32_t seg
}
if (!*path || (strlen(path) > PATH_MAX - 4)) { return NULL; }
b = grn_io_compute_base(header_size);
bs = (b + segment_size - 1) / segment_size;
bs = grn_io_compute_base_segment(b, segment_size);
max_nfiles = (unsigned int)(
((uint64_t)segment_size * (max_segment + bs) + GRN_IO_FILE_SIZE - 1)
/ GRN_IO_FILE_SIZE);
Expand Down Expand Up @@ -455,7 +461,7 @@ grn_io_open(grn_ctx *ctx, const char *path, grn_io_mode mode)
if (!segment_size) { return NULL; }
}
b = grn_io_compute_base(header_size);
bs = (b + segment_size - 1) / segment_size;
bs = grn_io_compute_base_segment(b, segment_size);
max_nfiles = (unsigned int)(
((uint64_t)segment_size * (max_segment + bs) + GRN_IO_FILE_SIZE - 1)
/ GRN_IO_FILE_SIZE);
Expand Down

0 comments on commit bd55bd9

Please sign in to comment.