Browse Source

+ made the ref. couting MT safe

florian 24 years ago
parent
commit
23b3c24a01
3 changed files with 43 additions and 15 deletions
  1. 8 4
      rtl/inc/astrings.inc
  2. 23 5
      rtl/inc/dynarr.inc
  3. 12 6
      rtl/inc/objpas.inc

+ 8 - 4
rtl/inc/astrings.inc

@@ -121,8 +121,9 @@ Begin
   { check for constant strings ...}
   { check for constant strings ...}
   l:=@PANSIREC(S-FirstOff)^.Ref;
   l:=@PANSIREC(S-FirstOff)^.Ref;
   If l^<0 then exit;
   If l^<0 then exit;
-  Dec(l^);
-  If l^=0 then
+
+  { declocked does a MT safe dec and returns true, if the counter is 0 }
+  If declocked(l^) then
     { Ref count dropped to zero }
     { Ref count dropped to zero }
     DisposeAnsiString (S);        { Remove...}
     DisposeAnsiString (S);        { Remove...}
   { this pointer is not valid anymore, so set it to zero }
   { this pointer is not valid anymore, so set it to zero }
@@ -136,7 +137,7 @@ Begin
     exit;
     exit;
   { Let's be paranoid : Constant string ??}
   { Let's be paranoid : Constant string ??}
   If PAnsiRec(S-FirstOff)^.Ref<0 then exit;
   If PAnsiRec(S-FirstOff)^.Ref<0 then exit;
-  Inc(PAnsiRec(S-FirstOff)^.Ref);
+  inclocked(PAnsiRec(S-FirstOff)^.Ref);
 end;
 end;
 
 
 
 
@@ -725,7 +726,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.10  2001-04-13 18:06:07  peter
+  Revision 1.11  2001-05-27 14:28:44  florian
+    + made the ref. couting MT safe
+
+  Revision 1.10  2001/04/13 18:06:07  peter
     * upcase, lowercase for ansistring
     * upcase, lowercase for ansistring
 
 
   Revision 1.9  2000/12/10 15:00:14  florian
   Revision 1.9  2000/12/10 15:00:14  florian

+ 23 - 5
rtl/inc/dynarr.inc

@@ -81,17 +81,29 @@ procedure dynarray_decr_ref(var p : pointer;ti : pdynarraytypeinfo);[Public,Alia
      if realp^.refcount=0 then
      if realp^.refcount=0 then
        HandleErrorFrame(204,get_frame);
        HandleErrorFrame(204,get_frame);
 
 
-     { this isn't MT safe! }
      { decr. ref. count }
      { decr. ref. count }
-     declocked(realp^.refcount);
-
      { should we remove the array? }
      { should we remove the array? }
-     if realp^.refcount=0 then
+     if declocked(realp^.refcount) then
        dynarray_clear(realp,ti);
        dynarray_clear(realp,ti);
      p:=nil;
      p:=nil;
   end;
   end;
 
 
 
 
+procedure dynarray_incr_ref(var p : pointer);[Public,Alias:'FPC_DYNARRAY_INCR_REF'];
+  var
+     realp : pdynarray;
+  begin
+     if p=nil then
+       exit;
+
+     realp:=pdynarray(p-sizeof(tdynarray));
+     if realp^.refcount=0 then
+       HandleErrorFrame(204,get_frame);
+
+     inclocked(realp^.refcount);
+  end;
+
+
 procedure dynarray_setlength(var p : pointer;pti : pdynarraytypeinfo;
 procedure dynarray_setlength(var p : pointer;pti : pdynarraytypeinfo;
   dimcount : dword;dims : pdynarrayindex);[Public,Alias:'FPC_DYNARR_SETLENGTH'];
   dimcount : dword;dims : pdynarrayindex);[Public,Alias:'FPC_DYNARR_SETLENGTH'];
 
 
@@ -146,6 +158,9 @@ procedure dynarray_setlength(var p : pointer;pti : pdynarraytypeinfo;
                { it could be that the in MT enviroments  }
                { it could be that the in MT enviroments  }
                { in the mean time the refcount was       }
                { in the mean time the refcount was       }
                { decremented                             }
                { decremented                             }
+
+               { it is, because it doesn't really matter }
+               { if the array is now removed             }
                dynarray_decr_ref(p,ti);
                dynarray_decr_ref(p,ti);
             end
             end
           else if dims[0]<>realp^.high+1 then
           else if dims[0]<>realp^.high+1 then
@@ -202,7 +217,10 @@ function dynarray_copy(var p : pointer;ti : pdynarraytypeinfo;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.6  2001-04-13 23:49:48  peter
+  Revision 1.7  2001-05-27 14:28:44  florian
+    + made the ref. couting MT safe
+
+  Revision 1.6  2001/04/13 23:49:48  peter
     * fixes for the stricter compiler
     * fixes for the stricter compiler
 
 
   Revision 1.5  2000/12/01 23:30:00  florian
   Revision 1.5  2000/12/01 23:30:00  florian

+ 12 - 6
rtl/inc/objpas.inc

@@ -636,10 +636,13 @@
     function TInterfacedObject._Release : longint;stdcall;
     function TInterfacedObject._Release : longint;stdcall;
 
 
       begin
       begin
-         declocked(frefcount);
-         _release:=frefcount;
-         if frefcount=0 then
-           destroy;
+         if declocked(frefcount) then
+           begin
+              destroy;
+              _Release:=0;
+           end
+         else
+           _Release:=frefcount;
       end;
       end;
 
 
     procedure TInterfacedObject.AfterConstruction;
     procedure TInterfacedObject.AfterConstruction;
@@ -678,14 +681,17 @@
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.14  2001-04-13 22:30:04  peter
+  Revision 1.15  2001-05-27 14:28:44  florian
+    + made the ref. couting MT safe
+
+  Revision 1.14  2001/04/13 22:30:04  peter
     * remove warnings
     * remove warnings
 
 
   Revision 1.13  2000/12/20 21:38:23  florian
   Revision 1.13  2000/12/20 21:38:23  florian
     * is-operator fixed
     * is-operator fixed
 
 
   Revision 1.12  2000/11/12 23:23:34  florian
   Revision 1.12  2000/11/12 23:23:34  florian
-    * interfaces basically running
+    * interfaces are basically running
 
 
   Revision 1.11  2000/11/09 17:50:12  florian
   Revision 1.11  2000/11/09 17:50:12  florian
     * Finalize to int_finalize renamed
     * Finalize to int_finalize renamed