Fewer atomic operations

This commit is contained in:
Erica Fischer
2024-02-01 13:06:53 -08:00
parent afe6afe794
commit 9af42515ec
+6 -2
View File
@@ -52,6 +52,8 @@ void serialize_long_long(FILE *out, long long n, std::atomic<long long> *fpos, c
} }
void serialize_ulong_long(FILE *out, unsigned long long zigzag, std::atomic<long long> *fpos, const char *fname) { void serialize_ulong_long(FILE *out, unsigned long long zigzag, std::atomic<long long> *fpos, const char *fname) {
int inc = 0;
while (1) { while (1) {
unsigned char b = zigzag & 0x7F; unsigned char b = zigzag & 0x7F;
if ((zigzag >> 7) != 0) { if ((zigzag >> 7) != 0) {
@@ -60,17 +62,19 @@ void serialize_ulong_long(FILE *out, unsigned long long zigzag, std::atomic<long
fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname, strerror(errno)); fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname, strerror(errno));
exit(EXIT_WRITE); exit(EXIT_WRITE);
} }
*fpos += 1; inc++;
zigzag >>= 7; zigzag >>= 7;
} else { } else {
if (putc(b, out) == EOF) { if (putc(b, out) == EOF) {
fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname, strerror(errno)); fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname, strerror(errno));
exit(EXIT_WRITE); exit(EXIT_WRITE);
} }
*fpos += 1; inc++;
break; break;
} }
} }
*fpos += inc;
} }
void serialize_byte(FILE *out, signed char n, std::atomic<long long> *fpos, const char *fname) { void serialize_byte(FILE *out, signed char n, std::atomic<long long> *fpos, const char *fname) {