From b3ee472fee0fe45cd421878d7525549b329fb559 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 13 Oct 2008 14:35:07 +0000 Subject: [PATCH] 2008-10-13 16:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbclass.ch * harbour/source/vm/classes.c * harbour/source/rtl/tobject.prg * harbour/source/rtl/tclass.prg ! fixed race condition when class function is called 1-st time and new class is created. It was possible that more then one thread execute this function simultaneously and two classes identical classes but with different handles were created and registered in HVM * harbour/contrib/xhb/xhbcomp.prg * updated hack with optional inheritance for new class code --- harbour/ChangeLog | 14 ++++ harbour/contrib/xhb/xhbcomp.prg | 2 +- harbour/include/hbclass.ch | 84 +++++++++++----------- harbour/source/rtl/tclass.prg | 120 +++++++++++++++++--------------- harbour/source/rtl/tobject.prg | 101 +++++++++++++++------------ harbour/source/vm/classes.c | 53 ++++++++++++++ 6 files changed, 232 insertions(+), 142 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 09df458209..bd77741074 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,20 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-13 16:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbclass.ch + * harbour/source/vm/classes.c + * harbour/source/rtl/tobject.prg + * harbour/source/rtl/tclass.prg + ! fixed race condition when class function is called 1-st time + and new class is created. It was possible that more then one + thread execute this function simultaneously and two classes + identical classes but with different handles were created + and registered in HVM + + * harbour/contrib/xhb/xhbcomp.prg + * updated hack with optional inheritance for new class code + 2008-10-13 13:51 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * make_b32.mak * make_gcc.mak diff --git a/harbour/contrib/xhb/xhbcomp.prg b/harbour/contrib/xhb/xhbcomp.prg index 55e197c06b..831f28cc95 100644 --- a/harbour/contrib/xhb/xhbcomp.prg +++ b/harbour/contrib/xhb/xhbcomp.prg @@ -61,7 +61,7 @@ ANNOUNCE XHB_LIB */ #xcommand OPTIONAL INHERIT => ; if type( <"className">+"()" ) == "UI" ;; - aadd( s_oClass:asSuper, @__() ) ;; + aadd( oClass:asSuper, @__() ) ;; end diff --git a/harbour/include/hbclass.ch b/harbour/include/hbclass.ch index f347a96755..30c089b0cb 100644 --- a/harbour/include/hbclass.ch +++ b/harbour/include/hbclass.ch @@ -269,10 +269,11 @@ DECLARE HBClass ; _HB_CLASS ;; function __HB_CLS_OPT([,] ) ( HB_CLS_PARAM_LIST ) ;; static s_oClass ;; - local nScope, oInstance ;; - if s_oClass == NIL ;; - nScope := HB_OO_CLSTP_EXPORTED ;; - s_oClass := IIF(<.metaClass.>, <(metaClass)>, HBClass():new( <(ClassName)> , __HB_CLS_PAR( [ @() ] [ , @() ] ), @__HB_CLS_OPT([__HB_CLS_ASID(),] )() [, <.modulfriend.> ] ) ) ;; + local nScope, oClass, oInstance ;; + if s_oClass == NIL .and. __clsLockDef( @s_oClass ) ;; + begin sequence ;; + nScope := HB_OO_CLSTP_EXPORTED ;; + oClass := IIF(<.metaClass.>, <(metaClass)>, HBClass():new( <(ClassName)> , __HB_CLS_PAR( [ @() ] [ , @() ] ), @__HB_CLS_OPT([__HB_CLS_ASID(),] )() [, <.modulfriend.> ] ) ) ;; #undef _CLASS_NAME_ ; #define _CLASS_NAME_ ;; #undef _CLASS_MODE_ ; #define _CLASS_MODE_ _CLASS_DECLARATION_ ; [ ; #translate Super( ): => ::: ] ; @@ -282,11 +283,14 @@ DECLARE HBClass ; [ ; #translate ::Super : => ::: ] #xcommand ENDCLASS [] => ; - s_oClass:Create() ; [<-lck-> __clsLock( s_oClass:hClass ) ] ;; - oInstance := s_oClass:Instance() ;; - if __ObjHasMsg( oInstance, "InitClass" ) ;; - oInstance:InitClass( HB_CLS_PARAM_LIST ) ;; - end ;; + oClass:Create() ; [<-lck-> __clsLock( oClass:hClass ) ] ;; + oInstance := oClass:Instance() ;; + if __ObjHasMsg( oInstance, "InitClass" ) ;; + oInstance:InitClass( HB_CLS_PARAM_LIST ) ;; + end ;; + always ;; + __clsUnlockDef( @s_oClass, oClass ) ;; + end sequence ;; return oInstance ;; end ;; return s_oClass:Instance() AS CLASS _CLASS_NAME_ ;; @@ -308,7 +312,7 @@ DECLARE HBClass ; #xcommand METHOD [ ] [ AS ] [ ] [] [