comp.lang.ada
 help / color / mirror / Atom feed
* Protected Adjust?
@ 2009-04-17  7:52 Dimonax
  2009-04-17  8:40 ` Dmitry A. Kazakov
  2009-04-17 18:21 ` sjw
  0 siblings, 2 replies; 3+ messages in thread
From: Dimonax @ 2009-04-17  7:52 UTC (permalink / raw)


How does one encapsulate a Controlled type inside a Protected type such 
that Initialize, Finalize, and Ajust can be done concurrently?

Basically I'm locking a Variable into a Cache, and I don't want that 
variable being copied in and out of the Cache. i.e. Each Task has to be 
able to operate on the variable in-place.

I'm using the low level mlock()/munlock() system calls to create the 
cache.(Locks the memory to RAM and prevents paging/swapping).

So far, I'm thinking this...

Pragma Profile(Ravenscar);
with Ada.Finalization;  --Yeah, this works even with Ravenscar profile. --
package mutators is

	type Item_Type is tagged null record;

	type Mutable is new Ada.Finalization.Controlled with private;

private

	type Item_Pointer is access Item_Type;

	type Mutable is new Ada.Finalization.Controlled with record
		Mutable_Item : Item_Pointer;
	end record;

	-- Catchy type name eh? ;-> --
	Protected Type Mutual_Excluder is
		-- This procedure is called by Initialize --
		procedure Create(Item : in Item_Type); 
		
		-- This procedure is called by Adjust. --
		procedure Update(Item : in out Item_Pointer);

		-- This procedure is called by Finalize --
		procedure Destroy(Item : in out Item_Pointer);

	private

		Item_Holder : Item_Type;
		Item_Location : Item_Pointer := Item_Holder'Access;

	end Mutual_Excluder;

	procedure Initialize(Mutable_Object : in out Mutable);
	procedure Adjust(Mutable_Object : in out Mutable);
	procedure Finalize(Mutable_Object : in out Mutable);

end mutators;


Should I have the seperate Item_Type and handle that seperately? Or 
should I just pass the entire Mutable Object in and out of the protected 
procedures?

The goal of this excercise is to be able to use the Adjust procedure from 
different tasks exclusively.

Tips, advice?

Freejack




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

end of thread, other threads:[~2009-04-17 18:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-17  7:52 Protected Adjust? Dimonax
2009-04-17  8:40 ` Dmitry A. Kazakov
2009-04-17 18:21 ` sjw

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