Add checks to sample task systems to ensure that TasksInit has been

called; if not, print an informative error message.
This commit is contained in:
Matt Pharr
2011-07-01 14:11:16 +01:00
parent d2d5858be1
commit 6ed6961958
3 changed files with 36 additions and 0 deletions

View File

@@ -35,7 +35,10 @@
Dispatch. */
#include <dispatch/dispatch.h>
#include <stdio.h>
#include <stdlib.h>
static bool initialized = false;
static dispatch_queue_t gcdQueue;
static dispatch_group_t gcdGroup;
@@ -55,6 +58,7 @@ void
TasksInit() {
gcdQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
gcdGroup = dispatch_group_create();
initialized = true;
}
@@ -77,6 +81,10 @@ lRunTask(void *ti) {
void ISPCLaunch(void *func, void *data) {
if (!initialized) {
fprintf(stderr, "You must call TasksInit() before launching tasks.\n");
exit(1);
}
TaskInfo *ti = new TaskInfo;
ti->func = func;
ti->data = data;
@@ -85,6 +93,11 @@ void ISPCLaunch(void *func, void *data) {
void ISPCSync() {
if (!initialized) {
fprintf(stderr, "You must call TasksInit() before launching tasks.\n");
exit(1);
}
// Wait for all of the tasks in the group to complete before returning
dispatch_group_wait(gcdGroup, DISPATCH_TIME_FOREVER);
}