Fixed concurrent write issue (discovered by Sergey Oboguev) which may happen if SIM_ASYNC_IO is enabled
This commit is contained in:
parent
88076c4b1b
commit
e1d1893834
1 changed files with 6 additions and 2 deletions
|
@ -57,7 +57,6 @@
|
||||||
|
|
||||||
#include "sim_defs.h"
|
#include "sim_defs.h"
|
||||||
|
|
||||||
static unsigned char sim_flip[FLIP_SIZE];
|
|
||||||
int32 sim_end = 1; /* 1 = little */
|
int32 sim_end = 1; /* 1 = little */
|
||||||
|
|
||||||
/* OS-independent, endian independent binary I/O package
|
/* OS-independent, endian independent binary I/O package
|
||||||
|
@ -141,11 +140,13 @@ size_t sim_fwrite (void *bptr, size_t size, size_t count, FILE *fptr)
|
||||||
size_t c, nelem, nbuf, lcnt, total;
|
size_t c, nelem, nbuf, lcnt, total;
|
||||||
int32 i;
|
int32 i;
|
||||||
unsigned char *sptr;
|
unsigned char *sptr;
|
||||||
|
unsigned char *sim_flip;
|
||||||
|
|
||||||
if ((size == 0) || (count == 0)) /* check arguments */
|
if ((size == 0) || (count == 0)) /* check arguments */
|
||||||
return 0;
|
return 0;
|
||||||
if (sim_end || (size == sizeof (char))) /* le or byte? */
|
if (sim_end || (size == sizeof (char))) /* le or byte? */
|
||||||
return fwrite (bptr, size, count, fptr); /* done */
|
return fwrite (bptr, size, count, fptr); /* done */
|
||||||
|
sim_flip = (unsigned char *)malloc(FLIP_SIZE);
|
||||||
nelem = FLIP_SIZE / size; /* elements in buffer */
|
nelem = FLIP_SIZE / size; /* elements in buffer */
|
||||||
nbuf = count / nelem; /* number buffers */
|
nbuf = count / nelem; /* number buffers */
|
||||||
lcnt = count % nelem; /* count in last buf */
|
lcnt = count % nelem; /* count in last buf */
|
||||||
|
@ -158,10 +159,13 @@ for (i = (int32)nbuf; i > 0; i--) { /* loop on buffers */
|
||||||
sim_buf_copy_swapped (sim_flip, sptr, size, c);
|
sim_buf_copy_swapped (sim_flip, sptr, size, c);
|
||||||
sptr = sptr + size * count;
|
sptr = sptr + size * count;
|
||||||
c = fwrite (sim_flip, size, c, fptr);
|
c = fwrite (sim_flip, size, c, fptr);
|
||||||
if (c == 0)
|
if (c == 0) {
|
||||||
|
free(sim_flip);
|
||||||
return total;
|
return total;
|
||||||
|
}
|
||||||
total = total + c;
|
total = total + c;
|
||||||
}
|
}
|
||||||
|
free(sim_flip);
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue