mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 00:38:31 +00:00
Serialize ZipOS handle IO across threads
This commit is contained in:
parent
0f1ead8943
commit
a808b3e738
7 changed files with 18 additions and 6 deletions
|
@ -17,9 +17,10 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/calls/struct/iovec.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/zip.h"
|
||||
#include "libc/zipos/zipos.internal.h"
|
||||
|
||||
|
@ -39,11 +40,13 @@ static size_t GetIovSize(const struct iovec *iov, size_t iovlen) {
|
|||
ssize_t __zipos_read(struct ZiposHandle *h, const struct iovec *iov,
|
||||
size_t iovlen, ssize_t opt_offset) {
|
||||
size_t i, b, x, y;
|
||||
pthread_mutex_lock(&h->lock);
|
||||
x = y = opt_offset != -1 ? opt_offset : h->pos;
|
||||
for (i = 0; i < iovlen && y < h->size; ++i, y += b) {
|
||||
b = min(iov[i].iov_len, h->size - y);
|
||||
if (b) memcpy(iov[i].iov_base, h->mem + y, b);
|
||||
}
|
||||
if (opt_offset == -1) h->pos = y;
|
||||
pthread_mutex_unlock(&h->lock);
|
||||
return y - x;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue