Skip to content

Commit 7503f34

Browse files
committed
thdat75/thdat105: fix openmp race condition
1 parent 78bbf35 commit 7503f34

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

thtk/thdat105.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,18 @@ th105_write(
158158
if (ret != entry->size)
159159
return -1;
160160

161-
/* FIXME: race condition on thdat->offset */
162-
th_crypt105_file(data, entry->size, thdat->offset, THCRYPT_PATCHCON_KEY);
161+
#pragma omp critical
162+
{
163+
entry->offset = thdat->offset;
164+
thdat->offset += entry->size;
165+
}
166+
167+
th_crypt105_file(data, entry->size, entry->offset, THCRYPT_PATCHCON_KEY);
163168

164169
int failed = 0;
165170
#pragma omp critical
166171
{
167172
failed = (thtk_io_write(thdat->stream, data, entry->size, error) != entry->size);
168-
if (!failed) {
169-
entry->offset = thdat->offset;
170-
thdat->offset += entry->size;
171-
}
172173
}
173174

174175
free(data);

thtk/thdat75.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,19 @@ th75_write(
147147
if (ret != entry->size)
148148
return -1;
149149

150-
/* FIXME: race condition on thdat->offset */
150+
#pragma omp critical
151+
{
152+
entry->offset = thdat->offset;
153+
thdat->offset += entry->size;
154+
}
155+
151156
if (thdat->version == 7575)
152-
th_crypt105_file(data, entry->size, thdat->offset, THCRYPT_MEGAMARI_KEY);
157+
th_crypt105_file(data, entry->size, entry->offset, THCRYPT_MEGAMARI_KEY);
153158

154159
int failed = 0;
155160
#pragma omp critical
156161
{
157162
failed = (thtk_io_write(thdat->stream, data, entry->size, error) != entry->size);
158-
if (!failed) {
159-
entry->offset = thdat->offset;
160-
thdat->offset += entry->size;
161-
}
162163
}
163164

164165
free(data);

0 commit comments

Comments
 (0)