comp.lang.ada
 help / color / mirror / Atom feed
* Buffer PO
@ 2016-06-03 13:29 tonyg
  2016-06-03 15:35 ` Anh Vo
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: tonyg @ 2016-06-03 13:29 UTC (permalink / raw)



I have a Fifo buffer in a protect object with a push / pop procedures and an is_empty function storing a gaggle of variant records.

I push just fine but when I come to collect my data with a pop, I have to assign it to a variable which is predeclared.

I cannot use a function as this cannot change the inside of a protected object.

Now I could use an extra buffer to contain the variant record discriminator but is there a better way?

I did think of adding a function to peek at the discriminator, but this could cause a problem as a push may change the record being viewed before my pop.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Buffer PO
  2016-06-03 13:29 Buffer PO tonyg
@ 2016-06-03 15:35 ` Anh Vo
  2016-06-03 16:20 ` Mark Lorenzen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Anh Vo @ 2016-06-03 15:35 UTC (permalink / raw)


On Friday, June 3, 2016 at 6:29:14 AM UTC-7, tonyg wrote:
> I have a Fifo buffer in a protect object with a push / pop procedures and an is_empty function storing a gaggle of variant records.
>  
> I did think of adding a function to peek at the discriminator, but this could cause a problem as a push may change the record being viewed before my pop.

PO will guaranteed that this kind of problem will not happen.

Anh Vo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Buffer PO
  2016-06-03 13:29 Buffer PO tonyg
  2016-06-03 15:35 ` Anh Vo
@ 2016-06-03 16:20 ` Mark Lorenzen
  2016-06-03 17:48 ` Jeffrey R. Carter
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Lorenzen @ 2016-06-03 16:20 UTC (permalink / raw)


On Friday, June 3, 2016 at 3:29:14 PM UTC+2, tonyg wrote:
> I have a Fifo buffer in a protect object with a push / pop procedures and an is_empty function storing a gaggle of variant records.
> 
> I push just fine but when I come to collect my data with a pop, I have to assign it to a variable which is predeclared.
> 
> I cannot use a function as this cannot change the inside of a protected object.
> 
> Now I could use an extra buffer to contain the variant record discriminator but is there a better way?
> 
> I did think of adding a function to peek at the discriminator, but this could cause a problem as a push may change the record being viewed before my pop.

I cannot really understand what your problem is, but I think you want to return a discriminated record in a protected procedure call and that gives you problems with the discriminant set by the caller.

You should use a default discriminant as this allows for the (protected) procedure to modify the discriminant of the object passed to the procedure.

Regards,

Mark L

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Buffer PO
  2016-06-03 13:29 Buffer PO tonyg
  2016-06-03 15:35 ` Anh Vo
  2016-06-03 16:20 ` Mark Lorenzen
@ 2016-06-03 17:48 ` Jeffrey R. Carter
  2016-06-03 19:10 ` Dmitry A. Kazakov
  2016-06-04 11:49 ` tonyg
  4 siblings, 0 replies; 6+ messages in thread
From: Jeffrey R. Carter @ 2016-06-03 17:48 UTC (permalink / raw)


On 06/03/2016 06:29 AM, tonyg wrote:
> 
> I have a Fifo buffer in a protect object with a push / pop procedures and an is_empty function storing a gaggle of variant records.
> 
> I push just fine but when I come to collect my data with a pop, I have to assign it to a variable which is predeclared.
> 
> I cannot use a function as this cannot change the inside of a protected object.
> 
> Now I could use an extra buffer to contain the variant record discriminator but is there a better way?
> 
> I did think of adding a function to peek at the discriminator, but this could cause a problem as a push may change the record being viewed before my pop.

So the element type is discriminated? If the type has a default for the
discriminants, then the variable that obtains the value can be unconstrained.

If you're using Ada 12, you can use a synchronized queue rather than rolling
your own (ARM A.18.28-29). If not, the PragmAda Reusable Components have a
collection of protected queues.

-- 
Jeff Carter
"To Err is human, to really screw up, you need C++!"
Stéphane Richard
63

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Buffer PO
  2016-06-03 13:29 Buffer PO tonyg
                   ` (2 preceding siblings ...)
  2016-06-03 17:48 ` Jeffrey R. Carter
@ 2016-06-03 19:10 ` Dmitry A. Kazakov
  2016-06-04 11:49 ` tonyg
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2016-06-03 19:10 UTC (permalink / raw)


On 2016-06-03 15:29, tonyg wrote:

> I have a Fifo buffer in a protect object with a push / pop procedures and an is_empty function storing a gaggle of variant records.

Put the protected object into the container not otherwise.

The pop operation will go:

1. lock the container (entry call)
2. pop the result in a task-unsafe way onto the stack
3. release the container (protected procedure call)
4. return the result from the stack

This will alow you to re-use any exiting task-unsafe container 
implementation you wanted.

The lock can be made re-entrant, BTW.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Buffer PO
  2016-06-03 13:29 Buffer PO tonyg
                   ` (3 preceding siblings ...)
  2016-06-03 19:10 ` Dmitry A. Kazakov
@ 2016-06-04 11:49 ` tonyg
  4 siblings, 0 replies; 6+ messages in thread
From: tonyg @ 2016-06-04 11:49 UTC (permalink / raw)


Thanks for your replies. I did not come across them till I settled on a solution , but thanks.
 What I settled on was ,
  I made a peek function for the discriminant, which I used just before popping and then within the PO to check before I popped.I added a success flag to the pop and if the second peek was different then success was marked false and the pop was not done, and the calling procedure would exit a loop if successful, if not a delay then a retry ( which is very very rare but could happen).


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-06-04 11:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 13:29 Buffer PO tonyg
2016-06-03 15:35 ` Anh Vo
2016-06-03 16:20 ` Mark Lorenzen
2016-06-03 17:48 ` Jeffrey R. Carter
2016-06-03 19:10 ` Dmitry A. Kazakov
2016-06-04 11:49 ` tonyg

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