summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-08-21 00:28:52 -0600
committerTavian Barnes <tavianator@gmail.com>2011-08-21 13:18:28 -0600
commit6b1fcde7af64ca81079dffe1d62096228693b5d6 (patch)
tree2600ece91b5179105a572d79b60a6fc07e82c0a7 /libdimension
parent4f9a96f6cdee4cf234bde7fdafd0be0f5b6b808e (diff)
downloaddimension-6b1fcde7af64ca81079dffe1d62096228693b5d6.tar.xz
Don't dynamically allocate timers.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/scene.h4
-rw-r--r--libdimension/dimension/timer.h18
-rw-r--r--libdimension/raytrace.c8
-rw-r--r--libdimension/scene.c7
-rw-r--r--libdimension/timer.c17
5 files changed, 15 insertions, 39 deletions
diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h
index 2f659e9..c35f91f 100644
--- a/libdimension/dimension/scene.h
+++ b/libdimension/dimension/scene.h
@@ -76,8 +76,8 @@ typedef struct dmnsn_scene {
unsigned int nthreads;
/** Timers. */
- dmnsn_timer *bounding_timer;
- dmnsn_timer *render_timer;
+ dmnsn_timer bounding_timer;
+ dmnsn_timer render_timer;
bool initialized; /**< @internal Whether the scene is initialized. */
} dmnsn_scene;
diff --git a/libdimension/dimension/timer.h b/libdimension/dimension/timer.h
index bd72a90..6bffce6 100644
--- a/libdimension/dimension/timer.h
+++ b/libdimension/dimension/timer.h
@@ -28,8 +28,6 @@ typedef struct dmnsn_timer {
double real; /**< Wall-clock time. */
double user; /**< Time spent executing. */
double system; /**< Time spent waiting for the system. */
-
- dmnsn_refcount refcount; /**< @internal Reference count. */
} dmnsn_timer;
/** A standard format string for timers. */
@@ -41,22 +39,16 @@ typedef struct dmnsn_timer {
* @endcode
* will print something like "1.00s (user: 0.99s; system: 0.01s)".
*/
-#define DMNSN_TIMER_PRINTF(t) (t)->real, (t)->user, (t)->system
+#define DMNSN_TIMER_PRINTF(t) (t).real, (t).user, (t).system
/**
- * Create a new timer. Timing starts right before this function returns.
- * @return A new timer object.
+ * Start a timer. The values of an unfinished timer are undefined.
+ * @param[in,out] timer The timer to start.
*/
-dmnsn_timer *dmnsn_new_timer(void);
+void dmnsn_start_timer(dmnsn_timer *timer);
/**
* Finish timing. The members of the timer struct will now contain timing data.
* @param[in,out] timer The timer to stop.
*/
-void dmnsn_complete_timer(dmnsn_timer *timer);
-
-/**
- * Delete a timer.
- * @param[in,out] timer The timer to delete.
- */
-void dmnsn_delete_timer(dmnsn_timer *timer);
+void dmnsn_stop_timer(dmnsn_timer *timer);
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 71e5578..92947d6 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -80,18 +80,18 @@ dmnsn_raytrace_scene_thread(void *ptr)
dmnsn_initialize_scene(payload->scene);
/* Time the bounding tree construction */
- payload->scene->bounding_timer = dmnsn_new_timer();
+ dmnsn_start_timer(&payload->scene->bounding_timer);
payload->prtree = dmnsn_new_prtree(payload->scene->objects);
- dmnsn_complete_timer(payload->scene->bounding_timer);
+ dmnsn_stop_timer(&payload->scene->bounding_timer);
/* Set up the progress object */
dmnsn_set_progress_total(payload->progress, payload->scene->canvas->height);
/* Time the render itself */
- payload->scene->render_timer = dmnsn_new_timer();
+ dmnsn_start_timer(&payload->scene->render_timer);
int ret = dmnsn_execute_concurrently(dmnsn_raytrace_scene_concurrent,
payload, payload->scene->nthreads);
- dmnsn_complete_timer(payload->scene->render_timer);
+ dmnsn_stop_timer(&payload->scene->render_timer);
dmnsn_delete_prtree(payload->prtree);
dmnsn_free(payload);
diff --git a/libdimension/scene.c b/libdimension/scene.c
index f0ff451..dc62799 100644
--- a/libdimension/scene.c
+++ b/libdimension/scene.c
@@ -48,8 +48,6 @@ dmnsn_new_scene(void)
scene->reclimit = 5;
scene->adc_bailout = 1.0/255.0;
scene->nthreads = dmnsn_ncpus();
- scene->bounding_timer = NULL;
- scene->render_timer = NULL;
scene->initialized = false;
return scene;
@@ -60,9 +58,6 @@ void
dmnsn_delete_scene(dmnsn_scene *scene)
{
if (scene) {
- dmnsn_delete_timer(scene->render_timer);
- dmnsn_delete_timer(scene->bounding_timer);
-
DMNSN_ARRAY_FOREACH (dmnsn_light **, light, scene->lights) {
dmnsn_delete_light(*light);
}
@@ -84,7 +79,7 @@ dmnsn_delete_scene(dmnsn_scene *scene)
void
dmnsn_initialize_scene(dmnsn_scene *scene)
{
- dmnsn_assert(!scene->initialized, "Texture double-initialized.");
+ dmnsn_assert(!scene->initialized, "Scene double-initialized.");
scene->initialized = true;
if (scene->outer_width == 0) {
diff --git a/libdimension/timer.c b/libdimension/timer.c
index ad0fd9b..e0873a8 100644
--- a/libdimension/timer.c
+++ b/libdimension/timer.c
@@ -25,17 +25,14 @@
#include "dimension-impl.h"
-dmnsn_timer *
-dmnsn_new_timer(void)
+void
+dmnsn_start_timer(dmnsn_timer *timer)
{
- dmnsn_timer *timer = dmnsn_malloc(sizeof(dmnsn_timer));
dmnsn_get_times(timer);
- timer->refcount = 1;
- return timer;
}
void
-dmnsn_complete_timer(dmnsn_timer *timer)
+dmnsn_stop_timer(dmnsn_timer *timer)
{
dmnsn_timer now;
dmnsn_get_times(&now);
@@ -43,11 +40,3 @@ dmnsn_complete_timer(dmnsn_timer *timer)
timer->user = now.user - timer->user;
timer->system = now.system - timer->system;
}
-
-void
-dmnsn_delete_timer(dmnsn_timer *timer)
-{
- if (DMNSN_DECREF(timer)) {
- dmnsn_free(timer);
- }
-}