Skip to content

Commit

Permalink
thdat75/thdat105: fix openmp race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
DankRank committed Sep 13, 2023
1 parent 78bbf35 commit 7503f34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 7 additions & 6 deletions thtk/thdat105.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,18 @@ th105_write(
if (ret != entry->size)
return -1;

/* FIXME: race condition on thdat->offset */
th_crypt105_file(data, entry->size, thdat->offset, THCRYPT_PATCHCON_KEY);
#pragma omp critical
{
entry->offset = thdat->offset;
thdat->offset += entry->size;
}

th_crypt105_file(data, entry->size, entry->offset, THCRYPT_PATCHCON_KEY);

int failed = 0;
#pragma omp critical
{
failed = (thtk_io_write(thdat->stream, data, entry->size, error) != entry->size);
if (!failed) {
entry->offset = thdat->offset;
thdat->offset += entry->size;
}
}

free(data);
Expand Down
13 changes: 7 additions & 6 deletions thtk/thdat75.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ th75_write(
if (ret != entry->size)
return -1;

/* FIXME: race condition on thdat->offset */
#pragma omp critical
{
entry->offset = thdat->offset;
thdat->offset += entry->size;
}

if (thdat->version == 7575)
th_crypt105_file(data, entry->size, thdat->offset, THCRYPT_MEGAMARI_KEY);
th_crypt105_file(data, entry->size, entry->offset, THCRYPT_MEGAMARI_KEY);

int failed = 0;
#pragma omp critical
{
failed = (thtk_io_write(thdat->stream, data, entry->size, error) != entry->size);
if (!failed) {
entry->offset = thdat->offset;
thdat->offset += entry->size;
}
}

free(data);
Expand Down

0 comments on commit 7503f34

Please sign in to comment.