Skip to content

Commit

Permalink
- fixed multithreading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nalexandru committed Jan 31, 2021
1 parent 4501d86 commit aaea01b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
20 changes: 17 additions & 3 deletions ToneMapping/ToneMapping.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct ThreadArgs
uint8_t *ldr;
uint32_t count;
float exposure, invGamma;
HANDLE evt;
};

static uint32_t _cpuCount = 0;
Expand Down Expand Up @@ -55,6 +56,8 @@ _acesToneMapProc(void *a)
ldr += 3;
}

SetEvent(args.evt);

return 0;
}

Expand Down Expand Up @@ -93,6 +96,8 @@ _uc2ToneMapProc(void *a)
ldr += 3;
}

SetEvent(args.evt);

return 0;
}

Expand Down Expand Up @@ -124,6 +129,8 @@ _hejlRichardToneMapProc(void *a)
ldr += 3;
}

SetEvent(args.evt);

return 0;
}

Expand Down Expand Up @@ -152,6 +159,8 @@ _reinhardToneMapProc(void *a)
ldr += 3;
}

SetEvent(args.evt);

return 0;
}

Expand All @@ -165,6 +174,9 @@ initToneMap(void)

_args = (struct ThreadArgs *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _cpuCount * sizeof(*_args));
_threads = (HANDLE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _cpuCount * sizeof(*_threads));

for (uint32_t i = 0; i < _cpuCount; ++i)
_args[i].evt = CreateEvent(NULL, FALSE, FALSE, NULL);
}

void
Expand All @@ -183,6 +195,8 @@ toneMap(enum ToneMapMode tm, float *exr, uint8_t *ldr, uint32_t width, uint32_t
case TM_ACES:
default: _acesToneMapProc(&_args[0]); break;
}

ResetEvent(_args[0].evt);
}

void
Expand Down Expand Up @@ -212,10 +226,10 @@ toneMapMT(enum ToneMapMode tm, float *hdr, uint8_t *ldr, uint32_t width, uint32_
CreateThread(NULL, 0, proc, &_args[i], 0, NULL);
}

WaitForMultipleObjects(_cpuCount, _threads, TRUE, INFINITE);

for (uint32_t i = 0; i < _cpuCount; ++i)
for (uint32_t i = 0; i < _cpuCount; ++i) {
WaitForSingleObject(_args[i].evt, INFINITE);
CloseHandle(_threads[i]);
}
}

void
Expand Down
8 changes: 0 additions & 8 deletions ToneMapping/ToneMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

enum ToneMapMode
{
TM_ACES,
Expand All @@ -20,8 +16,4 @@ void toneMap(enum ToneMapMode tm, float *exr, uint8_t *ldr, uint32_t width, uint
void toneMapMT(enum ToneMapMode tm, float *exr, uint8_t *ldr, uint32_t width, uint32_t height, float exposure, float gamma);
void termToneMap(void);

#ifdef __cplusplus
}
#endif

#endif /* _TONEMAPPING_H_ */
2 changes: 1 addition & 1 deletion ToneMapping/ToneMappingAction_moc.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'ToneMappingAction.h'
**
** Created: Sun Jan 31 23:10:05 2021
** Created: Mon Feb 1 00:43:26 2021
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
**
** WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion ToneMapping/ToneMappingDialog_moc.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'ToneMappingDialog.h'
**
** Created: Sun Jan 31 23:10:05 2021
** Created: Mon Feb 1 00:43:26 2021
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
**
** WARNING! All changes made in this file will be lost!
Expand Down

0 comments on commit aaea01b

Please sign in to comment.