comp.lang.ada
 help / color / mirror / Atom feed
From: hanslad@gmail.com
Subject: Re: pragma Thread_Local_Storage on record?
Date: Tue, 1 Mar 2016 07:22:11 -0800 (PST)
Date: 2016-03-01T07:22:11-08:00	[thread overview]
Message-ID: <0e3fb431-ee4b-46ca-b1a5-a78e3245d7f3@googlegroups.com> (raw)
In-Reply-To: <87k2lmmf5w.fsf@mid.deneb.enyo.de>


> I suspect that one of the components of type Core is itself a record
> and has a component which is not statically initialized.

Indeed, the Wait_Queue is a synchronized interface:

generic
   type Element is private;
package Buffers is
   type Buffer is synchronized interface;
   type Any_Buffer is access all Buffer'Class;
   Procedure Put(Buf: in out Buffer; Item: in Element)
   is abstract;
   Procedure Get(Buf: in out Buffer; Item: out Element)
   is abstract;
end Buffers; 

===============================================================

with Buffers;
generic
package Buffers.Mailboxes is
   type Buffer_Store is array(Positive range <>) of Element;

   protected type MailBox(Max_Capacity : Positive) is
        new Buffer with
      overriding entry Put(Item : in Element);
      overriding entry Get(Item : out Element);
   private
      First : Positive := 1;
      Last : Positive := Max_Capacity;
      Number_In_Buffer : Natural := 0;
      Box_Store        : Buffer_Store(1 .. Max_Capacity);
   end MailBox;
end Buffers.Mailboxes;
====================================================================
package body Buffers.Mailboxes is
   protected body MailBox is
      entry Get(Item : out Element)
        when Number_In_Buffer /= 0 is
      begin
         Item := Box_Store(First);
         First := First mod Max_Capacity + 1;
         Number_In_Buffer := Number_In_Buffer - 1;
      end Get;

      entry Put(Item : in Element)
        when Number_In_Buffer /= Max_Capacity is
      begin
         Last := Last mod Max_Capacity + 1;
         Box_Store(Last):= Item;
         Number_In_Buffer := Number_In_Buffer + 1;
      end Put;

      function Buffer_Capacity return Positive is
      begin
         return Number_In_Buffer;
      end Buffer_Capacity;
   end MailBox;
end Buffers.Mailboxes;

Any idea on how I could implement such buffer in a Thread local data structure(record)?

HP 


  reply	other threads:[~2016-03-01 15:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01 13:45 pragma Thread_Local_Storage on record? hanslad
2016-03-01 14:44 ` Florian Weimer
2016-03-01 15:22   ` hanslad [this message]
2016-03-01 15:55     ` Dmitry A. Kazakov
2016-03-01 16:31       ` hanslad
2016-03-01 17:03         ` Dmitry A. Kazakov
2016-03-01 15:52 ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox