[teklib-general] changeset in /hg/teklib/current: added locking of display
Franciska Schulze
fschulze at neoscientists.org
Mon Nov 26 16:22:12 CET 2007
changeset 1ba5d8f0030a in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=1ba5d8f0030a
description:
added locking of display
diffs (231 lines):
diff -r 3e7d7565cad6 -r 1ba5d8f0030a src/visual/posix/visual_host.c
--- a/src/visual/posix/visual_host.c Sun Sep 02 22:05:41 2007 +0200
+++ b/src/visual/posix/visual_host.c Sun Sep 02 22:06:24 2007 +0200
@@ -55,6 +55,8 @@ vis_hostopenfont(TMOD_VIS *mod, TTAGITEM
fquery = (TSTRPTR) TExecAlloc0(exec, mod->vis_MMU, FNT_LENGTH + strlen(fname));
if (fquery)
{
+ TExecLock(exec, g->lock);
+
/* build fontquery name */
sprintf(fquery, "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
fname,
@@ -89,6 +91,7 @@ vis_hostopenfont(TMOD_VIS *mod, TTAGITEM
}
}
+ TExecUnlock(exec, g->lock);
TExecFree(exec, fquery);
}
@@ -113,6 +116,8 @@ vis_hostclosefont(TMOD_VIS *mod, TAPTR f
GLOBAL *g = mod->vis_HostGlobal;
struct FontNode *fn = (struct FontNode *) font;
TAPTR exec = TGetExecBase(mod);
+
+ TExecLock(exec, g->lock);
if (font == g->fm.deffont)
{
@@ -130,12 +135,14 @@ vis_hostclosefont(TMOD_VIS *mod, TAPTR f
node = g->vlist.tlh_Head;
for (; (next = node->tln_Succ); node = next)
{
- /* the font we're going to free is currently */
- /* in use -> replace it with the default font */
+ /* the font is currently used by another visual */
VISUAL *v = (VISUAL *) node;
if (font == v->curfont)
- setfont(v->mod, g->fm.deffont);
+ {
+ TDBPRINTF(20, ("attempt to close font which is currently in use\n"));
+ TDBFATAL();
+ }
}
}
@@ -149,6 +156,8 @@ vis_hostclosefont(TMOD_VIS *mod, TAPTR f
/* remove from openfonts list */
TRemove(&fn->node);
+ TExecUnlock(exec, g->lock);
+
/* free fontnode itself */
TExecFree(exec, fn);
}
@@ -157,8 +166,12 @@ vis_hosttextsize(TMOD_VIS *mod, TAPTR fo
vis_hosttextsize(TMOD_VIS *mod, TAPTR font, TSTRPTR text)
{
TINT len;
+ TAPTR exec = TGetExecBase(mod);
+ GLOBAL *g = mod->vis_HostGlobal;
struct FontNode *fn = (struct FontNode *) font;
+ TExecLock(exec, g->lock);
len = XTextWidth(fn->font, text, strlen(text));
+ TExecUnlock(exec, g->lock);
return len;
}
@@ -192,7 +205,6 @@ vis_hostgetfattrfunc(struct THook *hook,
data->num++;
return TTRUE;
}
-
/*****************************************************************************/
@@ -1191,6 +1203,9 @@ vis_init(TMOD_VIS *mod)
{
TInitList(&g->vlist);
+ g->lock = TExecCreateLock(exec, TNULL);
+ if (g->lock == TNULL) break;
+
g->display = XOpenDisplay(TNULL);
if (g->display == TNULL) break;
@@ -1209,9 +1224,7 @@ vis_init(TMOD_VIS *mod)
TAddTail(&g->fm.openfonts, &fn->node);
g->fm.deffont = (TAPTR)fn;
- //g->fm.curfont = (TAPTR)fn;
-
- TDBPRINTF(20,("vis_init - mod: %p - global: %p\n", mod, g));
+
mod->vis_HostGlobal = g;
return TTRUE;
}
@@ -1225,14 +1238,19 @@ vis_exit(TMOD_VIS *mod)
{
TAPTR exec = TGetExecBase(mod);
GLOBAL *g = mod->vis_HostGlobal;
-
- TDBPRINTF(20,("vis_exit - mod: %p - global: %p\n", mod, g));
+ struct TNode *node, *next;
- if (g->fm.deffont)
- vis_hostclosefont(mod, g->fm.deffont);
-
+ /* close all fonts */
+ node = g->fm.openfonts.tlh_Head;
+ for (; (next = node->tln_Succ); node = next)
+ {
+ vis_hostclosefont(mod, (TAPTR)node);
+ }
+
if (g->display)
XCloseDisplay(g->display);
+
+ TDestroy(g->lock);
TExecFree(exec, g);
mod->vis_HostGlobal = TNULL;
@@ -1250,6 +1268,8 @@ vis_open(TMOD_VIS *mod)
mod->vis_HostVisual = v;
TInitList(&v->imsgpool);
+ TExecLock(exec, g->lock);
+
for (;;)
{
XSetWindowAttributes swa;
@@ -1397,6 +1417,8 @@ vis_close(TMOD_VIS *mod)
VISUAL *v = mod->vis_HostVisual;
if (v)
{
+ GLOBAL *g = mod->vis_HostGlobal;
+ TAPTR exec = TGetExecBase(mod);
struct TNode *imsg;
TRemove(&v->node);
@@ -1416,6 +1438,8 @@ vis_close(TMOD_VIS *mod)
if (v->sizehints)
XFree(v->sizehints);
+ ((GLOBAL *)(v->mod->vis_HostGlobal))->fm.defref--;
+
if (v->fd_sigpipe_read != -1)
{
close(v->fd_sigpipe_read);
@@ -1425,6 +1449,7 @@ vis_close(TMOD_VIS *mod)
THALDestroyLock(v->HalBase, &v->lock);
TExecFree(TGetExecBase(mod), v);
mod->vis_HostVisual = TNULL;
+ TExecUnlock(exec, g->lock);
}
}
@@ -1434,12 +1459,16 @@ vis_wait(TMOD_VIS *mod)
vis_wait(TMOD_VIS *mod)
{
VISUAL *v = mod->vis_HostVisual;
+ GLOBAL *g = mod->vis_HostGlobal;
+ TAPTR exec = TGetExecBase(mod);
fd_set rset;
FD_ZERO(&rset);
FD_SET(v->fd_display, &rset);
FD_SET(v->fd_sigpipe_read, &rset);
+ TExecUnlock(exec, g->lock);
+
if (select(v->fd_max, &rset, NULL, NULL, NULL) > 0)
{
if (FD_ISSET(v->fd_sigpipe_read, &rset))
@@ -1448,6 +1477,8 @@ vis_wait(TMOD_VIS *mod)
read(v->fd_sigpipe_read, sig, 1);
}
}
+
+ TExecLock(exec, g->lock);
for (;;)
{
@@ -1578,33 +1609,5 @@ vis_docmd(TMOD_VIS *mod, VISREQ *req)
case VISCMD_SETFONT:
setfont(mod, req->vis_Op.SetFont.Font);
break;
-
-#if 0
- case VISCMD_OPENFONT:
- req->vis_Op.OpenFont.Font =
- openfont(mod, req->vis_Op.OpenFont.Tags);
- break;
-
- case VISCMD_CLOSEFONT:
- closefont(mod, req->vis_Op.CloseFont.Font);
- break;
-
-
- case VISCMD_TEXTSIZE:
- req->vis_Op.TextSize.Len =
- textsize(mod, req->vis_Op.TextSize.Font,
- req->vis_Op.TextSize.Text);
- break;
-
- case VISCMD_GETFATTRS:
- data.mod = mod;
- data.v = v;
- data.font = req->vis_Op.GetFAttrs.Font;
- data.num = 0;
- TInitHook(&hook, getfattrfunc, &data);
- TForEachTag(req->vis_Op.GetFAttrs.Tags, &hook);
- req->vis_Op.GetFAttrs.Num = data.num;
- break;
-#endif
- }
-}
+ }
+}
diff -r 3e7d7565cad6 -r 1ba5d8f0030a src/visual/posix/visual_host.h
--- a/src/visual/posix/visual_host.h Sun Sep 02 22:05:41 2007 +0200
+++ b/src/visual/posix/visual_host.h Sun Sep 02 22:06:24 2007 +0200
@@ -81,6 +81,7 @@ typedef struct
Display *display;
struct FontMan fm;
struct TList vlist; /* list of host visuals */
+ TAPTR lock;
} GLOBAL;
More information about the teklib-general
mailing list