text: font: add owner field to font_ops

The owner fields specifies the module that provides the code for the given
backend. The font-core is responsible of ref/unref'ing the module so its
code is always available as long as the module exists.

We cannot push this into the modules as modules _must_ never call
kmscon_module_unref(KMSCON_THIS_MODULE)! Because this might drop the last
reference and hence the function might disallocate the module. However,
this means that it cannot return because the caller is _part_ of the
module and so no longer valid.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann committed 2013-01-03 16:23:52 +01:00
1 parent a8c1d8bbf1
commit 5dcdc91b42
6 files changed
+9 -7

No files matched your search

+2 -1
View File
@@ -40,6 +40,7 @@
#include <errno.h>
#include <stdlib.h>
#include "kmscon_module.h"
#include "tsm_screen.h"
#include "uterm.h"
@@ -85,6 +86,7 @@ struct kmscon_font {
struct kmscon_font_ops {
const char *name;
struct kmscon_module *owner;
int (*init) (struct kmscon_font *out,
const struct kmscon_font_attr *attr);
void (*destroy) (struct kmscon_font *font);
@@ -95,7 +97,6 @@ struct kmscon_font_ops {
const struct kmscon_glyph **out);
int (*render_inval) (struct kmscon_font *font,
const struct kmscon_glyph **out);
void (*finalize) (void);
};
int kmscon_font_register(const struct kmscon_font_ops *ops);
+3 -2
View File
@@ -56,6 +56,7 @@
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include "kmscon_module.h"
#include "log.h"
#include "shl_dlist.h"
#include "shl_register.h"
@@ -137,8 +138,7 @@ static inline void kmscon_font_destroy(void *data)
{
const struct kmscon_font_ops *ops = data;
if (ops->finalize)
ops->finalize();
kmscon_module_unref(ops->owner);
}
/**
@@ -172,6 +172,7 @@ int kmscon_font_register(const struct kmscon_font_ops *ops)
return ret;
}
kmscon_module_ref(ops->owner);
return 0;
}
+1 -1
View File
@@ -107,12 +107,12 @@ static int kmscon_font_8x16_render_inval(struct kmscon_font *font,
struct kmscon_font_ops kmscon_font_8x16_ops = {
.name = "8x16",
.owner = NULL,
.init = kmscon_font_8x16_init,
.destroy = kmscon_font_8x16_destroy,
.render = kmscon_font_8x16_render,
.render_empty = kmscon_font_8x16_render_empty,
.render_inval = kmscon_font_8x16_render_inval,
.finalize = NULL,
};
static const struct kmscon_glyph kmscon_font_8x16_glyphs[256] = {
+1 -1
View File
@@ -684,10 +684,10 @@ static int kmscon_font_freetype2_render_inval(struct kmscon_font *font,
struct kmscon_font_ops kmscon_font_freetype2_ops = {
.name = "freetype2",
.owner = NULL,
.init = kmscon_font_freetype2_init,
.destroy = kmscon_font_freetype2_destroy,
.render = kmscon_font_freetype2_render,
.render_empty = kmscon_font_freetype2_render_empty,
.render_inval = kmscon_font_freetype2_render_inval,
.finalize = NULL,
};
+1 -1
View File
@@ -430,10 +430,10 @@ static int kmscon_font_pango_render_inval(struct kmscon_font *font,
struct kmscon_font_ops kmscon_font_pango_ops = {
.name = "pango",
.owner = NULL,
.init = kmscon_font_pango_init,
.destroy = kmscon_font_pango_destroy,
.render = kmscon_font_pango_render,
.render_empty = kmscon_font_pango_render_empty,
.render_inval = kmscon_font_pango_render_inval,
.finalize = NULL,
};
+1 -1
View File
@@ -113,10 +113,10 @@ static int kmscon_font_unifont_render_empty(struct kmscon_font *font,
struct kmscon_font_ops kmscon_font_unifont_ops = {
.name = "unifont",
.owner = NULL,
.init = kmscon_font_unifont_init,
.destroy = kmscon_font_unifont_destroy,
.render = kmscon_font_unifont_render,
.render_empty = kmscon_font_unifont_render_empty,
.render_inval = kmscon_font_unifont_render_inval,
.finalize = NULL,
};