]> Pileus Git - grits/commitdiff
Lock the sphere when working with volatile triangles
authorAndy Spencer <andy753421@gmail.com>
Mon, 25 Jan 2010 20:43:27 +0000 (20:43 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 25 Jan 2010 20:43:27 +0000 (20:43 +0000)
As far as I know, this doesn't fix anything, but it's probably a good
idea incase threading causes issues.

src/gis-opengl.c
src/gis-opengl.h
src/roam.c

index b07820612d1d6f7b25d53b2e7ee8d7278a0f74e9..bb05d68fe17b5f2ba3029fa37ce7d52de135830e 100644 (file)
@@ -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)
index ce65cbc6edc30b107cc88ed9c5e86fa4186d2f4d..a77b5a43d6f289cdae4fed3de6bf9725fa504ca0 100644 (file)
@@ -40,6 +40,7 @@ struct _GisOpenGL {
        /* instance members */
        GTree      *objects;
        RoamSphere *sphere;
+       GMutex     *sphere_lock;
        guint       sm_source[2];
 
        /* for testing */
index 7a1d6d3a86d961ae5c5a7771a026c122108bec88..ef9eeb8d41ae311bc3f3b11d714a5cbff5103dd2 100644 (file)
@@ -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)
 {