From: Andy Spencer Date: Mon, 25 Jan 2010 20:43:27 +0000 (+0000) Subject: Lock the sphere when working with volatile triangles X-Git-Tag: v0.4~123 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=e1c0182c49c7899345b6e0e3de5fd0eae69764df Lock the sphere when working with volatile triangles As far as I know, this doesn't fix anything, but it's probably a good idea incase threading causes issues. --- diff --git a/src/gis-opengl.c b/src/gis-opengl.c index b078206..bb05d68 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -270,7 +270,9 @@ static void on_realize(GisOpenGL *self, gpointer _) { g_debug("GisOpenGL: on_realize"); _set_visuals(self); + g_mutex_lock(self->sphere_lock); roam_sphere_update_errors(self->sphere); + g_mutex_unlock(self->sphere_lock); } static gboolean on_configure(GisOpenGL *self, GdkEventConfigure *event, gpointer _) { @@ -288,7 +290,9 @@ static gboolean on_configure(GisOpenGL *self, GdkEventConfigure *event, gpointer gluPerspective(rad2deg(ang)*2, width/height, 1, 10*EARTH_R); #ifndef ROAM_DEBUG + g_mutex_lock(self->sphere_lock); roam_sphere_update_errors(self->sphere); + g_mutex_unlock(self->sphere_lock); #endif _gis_opengl_end(self); @@ -402,8 +406,10 @@ static gboolean on_idle(GisOpenGL *self) //g_debug("GisOpenGL: on_idle"); gdk_threads_enter(); _gis_opengl_begin(self); + g_mutex_lock(self->sphere_lock); if (roam_sphere_split_merge(self->sphere)) gtk_widget_queue_draw(GTK_WIDGET(self)); + g_mutex_unlock(self->sphere_lock); _gis_opengl_end(self); gdk_threads_leave(); return TRUE; @@ -517,6 +523,7 @@ static void gis_opengl_set_height_func(GisViewer *_self, GisTile *tile, if (!tile) return; /* TODO: get points? */ + g_mutex_lock(self->sphere_lock); GList *triangles = roam_sphere_get_intersect(self->sphere, TRUE, tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); for (GList *cur = triangles; cur; cur = cur->next) { @@ -532,6 +539,7 @@ static void gis_opengl_set_height_func(GisViewer *_self, GisTile *tile, } } g_list_free(triangles); + g_mutex_unlock(self->sphere_lock); } static void _gis_opengl_clear_height_func_rec(RoamTriangle *root) @@ -627,6 +635,7 @@ static void gis_opengl_init(GisOpenGL *self) self->objects = g_tree_new(_objects_cmp); self->sphere = roam_sphere_new(self); + self->sphere_lock = g_mutex_new(); #ifndef ROAM_DEBUG self->sm_source[0] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+30, 33, (GSourceFunc)on_idle, self, NULL); @@ -665,6 +674,7 @@ static void gis_opengl_finalize(GObject *_self) { g_debug("GisViewer: finalize"); GisOpenGL *self = GIS_OPENGL(_self); + g_mutex_free(self->sphere_lock); G_OBJECT_CLASS(gis_opengl_parent_class)->finalize(_self); } static void gis_opengl_class_init(GisOpenGLClass *klass) diff --git a/src/gis-opengl.h b/src/gis-opengl.h index ce65cbc..a77b5a4 100644 --- a/src/gis-opengl.h +++ b/src/gis-opengl.h @@ -40,6 +40,7 @@ struct _GisOpenGL { /* instance members */ GTree *objects; RoamSphere *sphere; + GMutex *sphere_lock; guint sm_source[2]; /* for testing */ diff --git a/src/roam.c b/src/roam.c index 7a1d6d3..ef9eeb8 100644 --- a/src/roam.c +++ b/src/roam.c @@ -650,6 +650,9 @@ static GList *_roam_sphere_get_intersect_rec(RoamTriangle *tri, GList *list, return g_list_prepend(list, tri); } } +/* Warning: This grabs pointers to triangles which can be changed by other + * calls, e.g. split_merge. If you use this, you need to do some locking to + * prevent the returned list from becomming stale. */ GList *roam_sphere_get_intersect(RoamSphere *self, gboolean all, gdouble n, gdouble s, gdouble e, gdouble w) {