freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] ftgzip reentrant?


From: Detlef Würkner
Subject: [Devel] ftgzip reentrant?
Date: Sat, 10 May 2003 11:49:29 +0200

Hello!

When defining FT_CONFIG_OPTION_USE_ZLIB and not defining
FT_CONFIG_OPTION_SYSTEM_ZLIB, i.e. when using the gzip code from ftgzip.c,
the symbol BUILDFIXED gets defined in ftgzip.c.

With BUILDFIXED defined, in inftrees.c the following happens

----8<----
/* build fixed tables only once--keep them here */
#ifdef BUILDFIXED
local int fixed_built = 0;
[...]
local int inflate_trees_fixed( /* bl, bd, tl, td, z) */
uIntf *bl,               /* literal desired/actual bit depth */
uIntf *bd,               /* distance desired/actual bit depth */
inflate_huft * FAR *tl,  /* literal/length tree result */
inflate_huft * FAR *td,  /* distance tree result */
z_streamp z              /* for memory allocation */
)
{
#ifdef BUILDFIXED
  /* build fixed tables if not already */
  if (!fixed_built)
  {
    int k;              /* temporary variable */
    uInt f = 0;         /* number of hufts used in fixed_mem */
    uIntf *c;           /* length list for huft_build */
    uIntf *v;           /* work area for huft_build */

    /* allocate memory */
    if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
      return Z_MEM_ERROR;
    if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
    {
      ZFREE(z, c);
      return Z_MEM_ERROR;
    }

    /* literal table */
    for (k = 0; k < 144; k++)
      c[k] = 8;
    for (; k < 256; k++)
      c[k] = 9;
    for (; k < 280; k++)
      c[k] = 7;
    for (; k < 288; k++)
      c[k] = 8;
    fixed_bl = 9;
    huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
               fixed_mem, &f, v);

    /* distance table */
    for (k = 0; k < 30; k++)
      c[k] = 5;
    fixed_bd = 5;
    huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
               fixed_mem, &f, v);

    /* done */
    ZFREE(z, v);
    ZFREE(z, c);
    fixed_built = 1;
  }
----8<----

I'm unsure what happens when this code runs multiple times "at once", i.e.
if its pure, reentrant, thread-safe, whatever. "local int fixed_built" is 
a static variable, i.e. in bss space, common to all threads, tasks, processes,
whatever. IMHO the fixed tables can be build by several threads at the same
time without an arbitration protocol? If yes, can this be problematic?

Ciao, Detlef
-- 
_ // address@hidden
\X/  Detlef Wuerkner, Langgoens/Germany



reply via email to

[Prev in Thread] Current Thread [Next in Thread]