From: Vadim Godunko <vgodunko@gmail.com>
Subject: Re: Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing!
Date: Sun, 9 Mar 2008 07:41:33 -0700 (PDT)
Date: 2008-03-09T07:41:33-07:00 [thread overview]
Message-ID: <ec684efe-61a6-4463-bd43-fb5895e868bc@x30g2000hsd.googlegroups.com> (raw)
In-Reply-To: 1lbnckly14ak1$.1toakcw8jw12$.dlg@40tude.net
On Mar 9, 4:37 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
>
> It is unclear in which the context you are using protected objects. I don't
> see why a protected object should be slower than, say, critical section +
> operation.
>
I have attach all source code. Protected object used for atomic
reference counting (The design may be looks strange, I just have plans
to replace protected object by the inline assembler code). C++ class
used inline assembler for the same. Both C++ class and Ada tagged type
share internal string data.
> > for J in 1 .. 1_000 loop
> > if J mod 2 = 1 then
> > B := A;
>
> Is this a deep copy?
No.
> What is controlled, array, elements, both?
Array's elements are controlled.
> What is the locking policy, per container, per element, both?
Per element.
------->-8--------
private with Ada.Finalization;
private with League.Internals.Atomics;
package League.Strings is
pragma Preelaborate;
type Universal_String is tagged private;
function To_Universal_String (Item : in Wide_Wide_String)
return Universal_String;
function To_Wide_Wide_String (Self : in Universal_String'Class)
return Wide_Wide_String;
function "=" (Left : in Universal_String;
Right : in Universal_String)
return Boolean;
private
type Utf16_String is new Wide_String;
type Utf16_String_Access is access all Utf16_String;
type Private_Data is record
Counter : aliased League.Internals.Atomics.Counter;
String : Utf16_String_Access;
Last : Natural := 0;
Length : Natural := 0;
end record;
type Private_Data_Access is access all Private_Data;
Empty_String : aliased Utf16_String := "";
Shared_Empty : aliased Private_Data
:= (String => Empty_String'Access,
others => <>);
type Universal_String is new Ada.Finalization.Controlled with
record
Data : Private_Data_Access := Shared_Empty'Access;
end record;
overriding
procedure Initialize (Self : in out Universal_String);
overriding
procedure Adjust (Self : in out Universal_String);
overriding
procedure Finalize (Self : in out Universal_String);
end League.Strings;
with Ada.Unchecked_Deallocation;
package body League.Strings is
Surrogate_First : constant := 16#D800#;
High_Surrogate_First : constant := 16#D800#;
High_Surrogate_Last : constant := 16#DBFF#;
Low_Surrogate_First : constant := 16#DC00#;
Low_Surrogate_Last : constant := 16#DFFF#;
Surrogate_Last : constant := 16#DFFF#;
subtype Surrogate_Wide_Character is Wide_Character
range Wide_Character'Val (Surrogate_First)
.. Wide_Character'Val (Surrogate_Last);
subtype High_Surrogate_Wide_Character is Surrogate_Wide_Character
range Wide_Character'Val (High_Surrogate_First)
.. Wide_Character'Val (High_Surrogate_Last);
subtype Low_Surrogate_Wide_Character is Surrogate_Wide_Character
range Wide_Character'Val (Low_Surrogate_First)
.. Wide_Character'Val (Low_Surrogate_Last);
procedure Free is
new Ada.Unchecked_Deallocation (Private_Data,
Private_Data_Access);
procedure Free is
new Ada.Unchecked_Deallocation (Utf16_String,
Utf16_String_Access);
function "=" (Left : in Universal_String;
Right : in Universal_String)
return Boolean
is
begin
raise Program_Error;
return False;
end "=";
overriding
procedure Adjust (Self : in out Universal_String) is
begin
League.Internals.Atomics.Increment (Self.Data.Counter'Access);
end Adjust;
overriding
procedure Finalize (Self : in out Universal_String) is
begin
if League.Internals.Atomics.Decrement (Self.Data.Counter'Access)
then
pragma Assert (Self.Data /= Shared_Empty'Access);
Free (Self.Data.String);
Free (Self.Data);
end if;
end Finalize;
overriding
procedure Initialize (Self : in out Universal_String) is
begin
League.Internals.Atomics.Increment (Self.Data.Counter'Access);
end Initialize;
function To_Universal_String (Item : in Wide_Wide_String)
return Universal_String
is
Aux : Utf16_String_Access
:= new Utf16_String (1 .. Item'Length * 2);
-- Reserve memory in assumption of all character will be
encoded as
-- surrogate pair.
Last : Natural := 0;
begin
for J in Item'Range loop
if Item (J) > Wide_Wide_Character'Val (Code_Point'Last)
or else Item (J) in Wide_Wide_Character'Val
(Surrogate_First)
.. Wide_Wide_Character'Val
(Surrogate_Last)
then
raise Constraint_Error
with "Wide_Wide_Character is not a valid Unicode code
point";
end if;
declare
C : constant Code_Point
:= Wide_Wide_Character'Pos (Item (J));
begin
if C <= 16#FFFF# then
Last := Last + 1;
Aux (Last) := Wide_Character'Val (C);
else
Last := Last + 1;
Aux (Last) :=
Wide_Character'Val (High_Surrogate_First + C /
16#400#);
Last := Last + 1;
Aux (Last) :=
Wide_Character'Val (Low_Surrogate_First + C mod
16#400#);
end if;
end;
end loop;
return
(Ada.Finalization.Controlled with
Data =>
new Private_Data'
(Counter => League.Internals.Atomics.One,
String => Aux,
Last => Last,
Length => Item'Length));
exception
when others =>
Free (Aux);
raise;
end To_Universal_String;
function To_Wide_Wide_String (Self : in Universal_String'Class)
return Wide_Wide_String
is
Current : Positive := 1;
begin
return Result : Wide_Wide_String (1 .. Self.Data.Length) do
for J in Result'Range loop
if Self.Data.String (Current) in Surrogate_Wide_Character
then
if Current < Self.Data.Last
and then Self.Data.String (Current)
in High_Surrogate_Wide_Character
and then Self.Data.String (Current + 1)
in Low_Surrogate_Wide_Character
then
Result (J) :=
Wide_Wide_Character'Val
((Wide_Character'Pos (Self.Data.String (Current))
- High_Surrogate_First) * 16#400#
+ (Wide_Character'Pos
(Self.Data.String (Current + 1))
- Low_Surrogate_First)
+ 16#1_0000#);
Current := Current + 2;
else
raise Constraint_Error
with "Ill-formed UTF-16 string: invalid surrogate
pair";
end if;
else
Result (J) :=
Wide_Wide_Character'Val
(Wide_Character'Pos (Self.Data.String (Current)));
Current := Current + 1;
end if;
end loop;
pragma Assert (Current = Self.Data.Last + 1);
end return;
end To_Wide_Wide_String;
end League.Strings;
private with Interfaces.C;
package League.Internals.Atomics is
pragma Preelaborate;
type Counter is private;
Zero : constant Counter;
One : constant Counter;
procedure Increment (Self : not null access Counter);
-- Atomicaly increment counter value.
function Decrement (Self : not null access Counter)
return Boolean;
-- Atomicaly decrement counter value. Returns True if counter has
zero
-- value after decrement.
private
type Counter is record
Value : Interfaces.C.int := 1;
end record;
Zero : constant Counter := (Value => 0);
One : constant Counter := (Value => 1);
end League.Internals.Atomics;
------------------------------------------------------------------------------
-- This is portable version of the package.
------------------------------------------------------------------------------
package body League.Internals.Atomics is
protected Guard is
procedure Increment (Self : not null access Counter);
procedure Decrement (Self : not null access Counter;
Zero : out Boolean);
end Guard;
function Decrement (Self : not null access Counter)
return Boolean
is
Aux : Boolean;
begin
Guard.Decrement (Self, Aux);
return Aux;
end Decrement;
protected body Guard is
procedure Decrement (Self : not null access Counter;
Zero : out Boolean)
is
use type Interfaces.C.int;
begin
Self.Value := Self.Value - 1;
Zero := Self.Value = 0;
end Decrement;
procedure Increment (Self : not null access Counter) is
use type Interfaces.C.int;
begin
Self.Value := Self.Value + 1;
end Increment;
end Guard;
procedure Increment (Self : not null access Counter) is
begin
Guard.Increment (Self);
end Increment;
end League.Internals.Atomics;
package League.Internals is
pragma Pure;
end League.Internals;
package League is
pragma Pure;
type Code_Point is mod 16#11_0000#;
for Code_Point'Size use 32;
end League;
next prev parent reply other threads:[~2008-03-09 14:41 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-08 6:04 Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing! ME
2008-03-08 22:11 ` Maciej Sobczak
2008-03-09 1:09 ` Christopher Henrich
2008-03-09 13:52 ` Maciej Sobczak
2008-03-09 1:51 ` Phaedrus
2008-03-09 3:17 ` Jeffrey R. Carter
2008-03-09 13:59 ` Maciej Sobczak
2008-03-09 3:15 ` Jeffrey R. Carter
2008-03-09 13:32 ` Maciej Sobczak
2008-03-09 14:02 ` Dmitry A. Kazakov
2008-03-09 18:26 ` Phaedrus
2008-03-10 0:04 ` Ray Blaak
2008-03-10 7:49 ` Georg Bauhaus
2008-03-10 16:48 ` Ray Blaak
2008-03-10 7:53 ` Phaedrus
2008-03-09 22:31 ` Jeffrey R. Carter
2008-03-10 3:53 ` gpriv
2008-03-10 3:04 ` Robert Dewar's great article about the Strengths of Ada over Larry Kilgallen
2008-03-10 9:23 ` Maciej Sobczak
2008-03-10 19:01 ` Jeffrey R. Carter
2008-03-10 22:00 ` Maciej Sobczak
2008-03-11 0:48 ` Jeffrey R. Carter
2008-03-11 7:12 ` Pascal Obry
2008-03-11 8:59 ` Maciej Sobczak
2008-03-11 9:49 ` GNAT bug, Assert_Failure at atree.adb:2893 Ludovic Brenta
2008-03-14 20:03 ` Robert Dewar's great article about the Strengths of Ada over Ivan Levashew
2008-03-22 21:12 ` Florian Weimer
2008-03-09 8:20 ` Robert Dewar's great article about the Strengths of Ada over other langauges in multiprocessing! Pascal Obry
2008-03-09 9:39 ` Georg Bauhaus
2008-03-09 12:40 ` Vadim Godunko
2008-03-09 13:37 ` Dmitry A. Kazakov
2008-03-09 14:41 ` Vadim Godunko [this message]
2008-03-10 20:51 ` Randy Brukardt
2008-03-10 22:30 ` Niklas Holsti
2008-03-10 9:56 ` Ole-Hjalmar Kristensen
2008-03-11 13:58 ` george.priv
2008-03-11 15:41 ` Vadim Godunko
2008-03-12 0:32 ` gpriv
2008-03-12 13:33 ` Maciej Sobczak
2008-03-12 14:41 ` gpriv
2008-03-12 15:22 ` Vadim Godunko
2008-03-13 0:34 ` gpriv
2008-03-12 16:28 ` Maciej Sobczak
2008-03-12 17:24 ` Samuel Tardieu
2008-03-13 8:41 ` Maciej Sobczak
2008-03-13 15:20 ` Samuel Tardieu
2008-03-12 23:54 ` gpriv
2008-03-13 9:40 ` Maciej Sobczak
2008-03-13 10:49 ` Peter C. Chapin
2008-03-13 13:03 ` Alex R. Mosteo
2008-03-13 14:02 ` gpriv
2008-03-14 1:12 ` Randy Brukardt
2008-03-14 10:16 ` Alex R. Mosteo
2008-03-13 11:42 ` gpriv
2008-03-13 16:10 ` Maciej Sobczak
2008-03-13 16:16 ` gpriv
2008-03-13 22:01 ` Simon Wright
2008-03-13 22:25 ` Maciej Sobczak
2008-03-14 2:07 ` gpriv
2008-03-14 9:29 ` Maciej Sobczak
2008-03-14 21:54 ` Simon Wright
2008-03-15 2:29 ` gpriv
2008-03-15 13:29 ` Maciej Sobczak
2008-03-15 16:09 ` gpriv
2008-03-11 22:09 ` gpriv
2008-03-09 13:50 ` Maciej Sobczak
2008-03-09 14:54 ` Pascal Obry
2008-03-10 21:24 ` Randy Brukardt
2008-03-11 10:12 ` Alex R. Mosteo
2008-03-22 22:43 ` Florian Weimer
2008-03-26 13:49 ` Ole-Hjalmar Kristensen
2008-03-26 21:27 ` Florian Weimer
2008-03-27 9:31 ` Ole-Hjalmar Kristensen
2008-03-27 23:10 ` Florian Weimer
2008-03-28 9:51 ` Ole-Hjalmar Kristensen
2008-03-28 18:12 ` Florian Weimer
2008-03-28 21:45 ` Randy Brukardt
2008-03-31 7:59 ` Ole-Hjalmar Kristensen
2008-03-31 13:03 ` (see below)
2008-03-31 14:17 ` (see below)
2008-04-01 9:02 ` Ole-Hjalmar Kristensen
2008-04-01 14:12 ` (see below)
2008-04-02 7:22 ` Ole-Hjalmar Kristensen
2008-04-02 14:59 ` (see below)
2008-04-04 6:36 ` Ole-Hjalmar Kristensen
2008-04-04 13:56 ` (see below)
2008-04-04 17:36 ` Georg Bauhaus
2008-04-04 17:40 ` (see below)
2008-04-15 12:05 ` Ole-Hjalmar Kristensen
2008-04-17 4:46 ` Randy Brukardt
2008-03-28 6:34 ` Randy Brukardt
2008-04-29 7:15 ` Ivan Levashew
2008-05-01 2:03 ` Steve Whalen
2008-03-14 19:20 ` Mike Silva
2008-03-14 20:43 ` Ed Falis
2008-03-22 22:51 ` Florian Weimer
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox