Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

writer: use pread and remove locks

  • Loading branch information...
commit 5923a2fff4591f9683993df826eb8f3fe83c0dbc 1 parent e140fcf
@indutny authored
Showing with 1 addition and 14 deletions.
  1. +1 −14 src/writer.c
View
15 src/writer.c
@@ -130,14 +130,7 @@ int bp__writer_read(bp__writer_t* w,
cdata = malloc(*size);
if (cdata == NULL) return BP_EALLOC;
- bp__mutex_lock(&w->writer_mutex);
- if (lseek(w->fd, (off_t) offset, SEEK_SET) == -1) {
- bp__mutex_unlock(&w->writer_mutex);
- return BP_EFILE;
- }
-
- bytes_read = read(w->fd, cdata, (size_t) *size);
- bp__mutex_unlock(&w->writer_mutex);
+ bytes_read = pread(w->fd, cdata, (size_t) *size, (off_t) offset);
if ((uint64_t) bytes_read != *size) {
free(cdata);
@@ -189,9 +182,7 @@ int bp__writer_write(bp__writer_t* w,
/* Write padding */
if (padding != sizeof(w->padding)) {
- bp__mutex_lock(&w->writer_mutex);
written = write(w->fd, &w->padding, (size_t) padding);
- bp__mutex_unlock(&w->writer_mutex);
if ((uint32_t) written != padding) return BP_EFILEWRITE;
w->filesize += padding;
}
@@ -204,9 +195,7 @@ int bp__writer_write(bp__writer_t* w,
/* head shouldn't be compressed */
if (comp == kNotCompressed) {
- bp__mutex_lock(&w->writer_mutex);
written = write(w->fd, data, *size);
- bp__mutex_unlock(&w->writer_mutex);
} else {
int ret;
size_t max_csize = bp__max_compressed_size(*size);
@@ -222,9 +211,7 @@ int bp__writer_write(bp__writer_t* w,
}
*size = result_size;
- bp__mutex_lock(&w->writer_mutex);
written = write(w->fd, compressed, result_size);
- bp__mutex_unlock(&w->writer_mutex);
free(compressed);
}
Please sign in to comment.
Something went wrong with that request. Please try again.