On Mon, 07 Jan 2008, Szakáts Viktor wrote:
> Hi,
> Exactly like Marek says. hb_stack*() API
> is not a public API, it's reserved for
> internal Harbour usage. It's needed for a
> proper separation of layers / components.

I agree. Number of public functions does not increase
functionality but seriously reduce possible modifications
in core code due to compatibility with existing 3-rd
party code.

> RTL actually uses it in 4 files, which needs
> to be fixed, IMO:
> do.c, errorapi.c, errorint.c, xhelp.c

All these files needs functionality which is not available
without calling hb_stack*() functions so it cannot be done
without adding some public wrapper functions to HVM or making
some of hb_stack*() functions public.
Additionaly I will have to add two new functions:
hb_stackGetTSD() and hb_stackTestTSD() which will be used in
some other RTL files. They are necessary for thread specific
data - static variables local to thread. It's very important
feature which allows to keep common MT and ST code. Below I'm
attaching ChangeLog for modifications which introduce TSD support
to Harbour in .prg and .c level.

best regards,
Przemek


XXXX-XX-XX XX:XX UTC+XXXX Przemyslaw Czerpak (druzus/at/priv.onet.pl)
  * harbour/include/hbstack.h
  * harbour/source/vm/estack.c
  * harbour/source/vm/hvm.c
    + added support for thread specific data located on HVM stack
      Now it's possible to allocate static variables which are
      local to thread. Such variables are allocated on HVM stack
      and automatically destroyed. To declare new TSD variable use:
         HB_TSD_NEW( <name>, <size>, <init>, <destruct> )
      <name> - name of variable which holds TSD handler
      <size> - size of TSD are which has to be allocated
      <init> - init function, executed when new TSD is allocated by thread
               (thread access given TSD 1-st time). This function receives
               void * pointer to allocated area.
      <destruct> - destructor function executed when HVM stack is destroyed
      f.e.:
         static HB_TSD_NEW( s_scrData, sizeof( HB_SCRDATA ),
                            NULL, hb_xSaveRestRelease );
      To initialize dynamically allocated TSD variable use:
         HB_TSD_INIT( <name>, <size>, <init>, <destruct> )
      Pointer to TSD can be accessed using hb_stackGetTSD( &<name> )
      where <name> is name of variable which holds TSD handler, f.e.:
         PHB_SCRDATA pScrData = ( PHB_SCRDATA ) hb_stackGetTSD( &s_scrData );
      See source/rtl/xsavescr.c as an example
      It's also possible to test if data has been already allocated for
      current thread by:
         hb_stackTestTSD( &<name> ) => pData
      it works like hb_stackGetTSD() but return NULL if current thread data
      has not been allocated yet.

  * harbour/source/rtl/xsavescr.c
    * use TSD data for screen buffer to make __XSAVESCREEN()/__XRESTSCREEN()
      thread independent

  * harbour/source/rtl/setkey.c
    * use TSD data for allocated keys to make SETKEY() thread independent

  * harbour/include/hbapigt.h
  * harbour/source/rtl/console.c
    * removed hb_setkeyInit() and hb_setkeyExit() - they are not longer
      necessary, allocated resources will be freed by TSD destructor
      function

  * harbour/include/hbapi.h
  * harbour/source/rtl/console.c
    * removed hb_conXSaveRestRelease() - it's not longer necessary,
      allocated resources will be freed by TSD destructor function

  * harbour/include/hbcomp.h
  * harbour/include/hbcompdf.h
  * harbour/source/compiler/complex.c
  * harbour/source/compiler/harbour.y
  * harbour/source/compiler/harbour.yyc
  * harbour/source/compiler/harbour.yyh
  * harbour/source/vm/hvm.c
    + added support for static variables which are local to thread:
         STATIC THREAD <varname [:= <exp>], ...>
      They work like normal static variables but each thread operates
      on its own copy.
    * added protection against possible double call to hb_xfree()
      It can happen due to wrong marking expressions as used by bison
      and executing destructors after our free code when syntax error
      appear.

  * harbour/source/rtl/perfuncs.prg
  * harbour/source/rtl/menuto.prg
  * harbour/source/rtl/getlist.prg
  * harbour/source/rtl/readvar.prg
  * harbour/source/rtl/text.prg
    * use STATIC THREAD variables to make above code MT safe
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to