--- a/render_thread.c Thu Jun 26 01:32:56 2008 +0300
+++ b/render_thread.c Thu Jun 26 02:57:20 2008 +0300
@@ -18,18 +18,30 @@
// measure how long it takes
double duration;
- // render it...
- if (render_local(&ctx->render_info, &duration))
- goto error;
+ struct render_local local_ctx;
+
+ // initialize it...
+ if (!(ctx->err = render_local_init(&local_ctx, &ctx->render_info))) {
+ // setup the cancel exit handlers
+ pthread_cleanup_push( (void (*)(void *)) render_local_deinit, &local_ctx);
-#ifdef DEBUG_INFO
- u_int32_t img_w, img_h;
+ // render it...
+ ctx->err = render_local_run(&local_ctx, &duration);
+
+ if (!ctx->err) {
+#if INFO_ENABLED
+ u_int32_t img_w, img_h;
- render_get_size(&ctx->render_info, &img_w, &img_h);
+ render_get_size(&ctx->render_info, &img_w, &img_h);
- // report the duration
- INFO("rendered [%ux%u] in %f seconds", img_w, img_h, duration);
+ // report the duration
+ INFO("rendered [%ux%u] in %f seconds", img_w, img_h, duration);
#endif
+ }
+
+ // cleanup
+ pthread_cleanup_pop(1);
+ }
// notify completion, writeall()
ssize_t ret;
@@ -52,6 +64,7 @@
return NULL;
error:
+ // if notifying of completion failed...
return ctx;
}
@@ -59,6 +72,14 @@
struct render_thread *ctx = arg;
void *thread_return;
+ // join the thread and check the return value
+ if (pthread_join(ctx->thread_id, &thread_return))
+ PWARNING("pthread_join");
+ else if (thread_return == PTHREAD_CANCELED)
+ PWARNING("PTHREAD_CANCELED");
+ else if (thread_return != NULL)
+ PWARNING("thread_return != NULL");
+
// make a lazy effort to read the contents of the pipe
struct render_thread *ctx2;
char *buf = (void *) &ctx2;
@@ -82,19 +103,11 @@
if (close(ctx->notify_fd))
PWARNING("close(pipe-write)");
- // join the thread and check the return value
- if (pthread_join(ctx->thread_id, &thread_return))
- PWARNING("pthread_join");
- else if (thread_return == PTHREAD_CANCELED)
- PWARNING("PTHREAD_CANCELED");
- else if (thread_return != NULL)
- PWARNING("thread_return != NULL");
-
// mark it as done
ctx->is_active = 0;
// call our callback
- ctx->cb_func(ctx, ctx->cb_arg);
+ ctx->cb_func(ctx, ctx->err, ctx->cb_arg);
}
int render_thread_init (struct render_thread *ctx, struct render *render_info, render_thread_done_cb cb_func, void *cb_arg) {