Skip to content

Commit

Permalink
Merge pull request #601 from JoakimSoderberg/fix_rrd_graph_thread_issue
Browse files Browse the repository at this point in the history
Fix pango fontmap threading issue.
  • Loading branch information
oetiker committed Apr 1, 2015
2 parents 120bfb0 + e1f6ee1 commit d95016e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/rrd_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,11 @@ int im_free(
free(im->rendered_image);
}

mutex_lock(im->fontmap_mutex);
if (im->layout) {
g_object_unref(im->layout);
}
mutex_unlock(im->fontmap_mutex);

if (im->ylegend)
free(im->ylegend);
Expand Down Expand Up @@ -4656,6 +4658,7 @@ void rrd_graph_init(
unsigned int i;
char *deffont = getenv("RRD_DEFAULT_FONT");
static PangoFontMap *fontmap = NULL;
static mutex_t fontmap_mutex = MUTEX_INITIALIZER;
PangoContext *context;

/* zero the whole structure first */
Expand Down Expand Up @@ -4740,15 +4743,18 @@ void rrd_graph_init(

im->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 10, 10);
im->cr = cairo_create(im->surface);
im->fontmap_mutex = &fontmap_mutex;

for (i = 0; i < DIM(text_prop); i++) {
im->text_prop[i].size = -1;
im->text_prop[i].font_desc = NULL;
rrd_set_font_desc(im,i, deffont ? deffont : text_prop[i].font,text_prop[i].size);
}

mutex_lock(im->fontmap_mutex);

if (fontmap == NULL){
fontmap = pango_cairo_font_map_get_default();
fontmap = pango_cairo_font_map_new();
}

#ifdef HAVE_PANGO_FONT_MAP_CREATE_CONTEXT
Expand All @@ -4772,7 +4778,7 @@ void rrd_graph_init(
(im->font_options, CAIRO_HINT_METRICS_ON);
cairo_font_options_set_antialias(im->font_options, CAIRO_ANTIALIAS_GRAY);


mutex_unlock(im->fontmap_mutex);

for (i = 0; i < DIM(graph_col); i++)
im->graph_col[i] = graph_col[i];
Expand Down Expand Up @@ -5369,8 +5375,10 @@ void rrd_graph_options(
}
} /* while (1) */

mutex_lock(im->fontmap_mutex);
pango_cairo_context_set_font_options(pango_layout_get_context(im->layout), im->font_options);
pango_layout_context_changed(im->layout);
mutex_unlock(im->fontmap_mutex);


if (im->primary_axis_format != NULL && im->primary_axis_format[0] != '\0') {
Expand Down
2 changes: 2 additions & 0 deletions src/rrd_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "rrd_tool.h"
#include "rrd_rpncalc.h"
#include "mutex.h"

#include <glib.h>

Expand Down Expand Up @@ -351,6 +352,7 @@ typedef struct image_desc_t {
rrd_info_t *grinfo_current; /* pointing to current entry */
GHashTable* gdef_map; /* a map of all *def gdef entries for quick access */
GHashTable* rrd_map; /* a map of all rrd files in use for gdef entries */
mutex_t *fontmap_mutex; /* Mutex for locking the global fontmap */
} image_desc_t;

/* Prototypes */
Expand Down

0 comments on commit d95016e

Please sign in to comment.