simple_components_4.62.0_a5c16c1d/atomic-access/gcc-long-offsets/synchronization-interprocess-generic_blackboard.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
--                                                                    --
--  package Generic_Blackboard      Copyright (c)  Dmitry A. Kazakov  --
--     Synchronization.Interprocess.               Luebeck            --
--     Generic_Blackboard                          Spring, 2018       --
--  Implementation                                                    --
--                                Last revision :  17:44 21 Jul 2018  --
--                                                                    --
--  This  library  is  free software; you can redistribute it and/or  --
--  modify it under the terms of the GNU General Public  License  as  --
--  published by the Free Software Foundation; either version  2  of  --
--  the License, or (at your option) any later version. This library  --
--  is distributed in the hope that it will be useful,  but  WITHOUT  --
--  ANY   WARRANTY;   without   even   the   implied   warranty   of  --
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  --
--  General  Public  License  for  more  details.  You  should  have  --
--  received  a  copy  of  the GNU General Public License along with  --
--  this library; if not, write to  the  Free  Software  Foundation,  --
--  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    --
--                                                                    --
--  As a special exception, if other files instantiate generics from  --
--  this unit, or you link this unit with other files to produce  an  --
--  executable, this unit does not by  itself  cause  the  resulting  --
--  executable to be covered by the GNU General Public License. This  --
--  exception  does not however invalidate any other reasons why the  --
--  executable file might be covered by the GNU Public License.       --
--____________________________________________________________________--

with Ada.Calendar;       use Ada.Calendar;
with Ada.Exceptions;     use Ada.Exceptions;
with Ada.IO_Exceptions;  use Ada.IO_Exceptions;

with System.Address_To_Access_Conversions;

package body Synchronization.Interprocess.Generic_Blackboard is

   Board_Init : constant String := "The blackboard is not " &
                                   "initialized or already " &
                                   "finalized";

   Storage_Offset_Size : constant Storage_Count :=
                         Storage_Count'Max_Size_In_Storage_Elements;
   Aligned_Storage_Offset_Size : constant Storage_Count :=
      (  Storage_Offset_Size
      -  (Storage_Offset_Size mod (-Element_Type'Alignment))
      );
--
-- Stored_Offset -- A sequence  of  storage  elements  of  the  size  of
--                  Storage_Offset. It is used  to  pack  Storage_Offset
--                  items into arrays of Storage_Element.
--
   subtype Stored_Offset is Buffer (1..Storage_Offset_Size);

   package Stored_Offset_Access is
      new System.Address_To_Access_Conversions (Stored_Offset);
   use Stored_Offset_Access;

   package Element_Type_Access is
      new System.Address_To_Access_Conversions (Element_Type);
   use Element_Type_Access;

   procedure Allocate
             (  Storage   : in out Blackboard_Pool;
                Address   : out System.Address;
                Size      : Storage_Count;
                Alignment : Storage_Count
             )  is
      Data  : Blackboard_Data renames Storage.Data.all;
      Upper : Storage_Count;
      Moved : Reference;
      Lower : Storage_Count :=
                 Get_Offset (Data, Load (Data.Lower'Unchecked_Access));
   begin
      Storage.Length := Size + Aligned_Storage_Offset_Size;
      if Alignment /= 0 then
         -- Rounding Length to have all following elements aligned
         Storage.Length :=
            Storage.Length - (Storage.Length mod (-Alignment));
      end if;
      Storage.Pointer := Load (Data.Upper'Unchecked_Access);
      Upper := Get_Offset (Data, Storage.Pointer);
      if Upper + Storage.Length > Data.Size then
         if Storage.Length > Data.Size then   -- Too large to fit
            Raise_Exception
            (  Storage_Error'Identity,
               (  "Too large object"
               &  Storage_Count'Image (Storage.Length)
               &  " >"
               &  Storage_Count'Image (Data.Size)
            )  );
         end if;
         --
         -- We have to wrap the buffer
         --
         if Lower >= Upper then
            --
            -- |<-current->|             |<-previous->|
            -- |           |<---------new-block-------|--->
            -- |           |Upper        |Lower       |
            -- |<Lower                                |
            --
            Moved := Load (Data.Lower'Unchecked_Access) +
                     Reference (Data.Size - Lower);
            if Moved > Storage.Preserved then
               raise Constraint_Error;
            else
               Store (Data.Lower'Access, Moved);
            end if;
         end if;
         if Upper + Storage.Length > Data.Size then
            --
            -- |   |<-current->|<-----new-block-------|-->
            -- |   |<Lower     |<Upper                |
            -- |               |0000000000000000000000|
            -- |<Upper
            --
            for Index in Upper + 1..Data.Size loop
               Data.Data (Index) := 0;
            end loop;
            --
            -- Moving to the next frame
            --
            Storage.Pointer :=
               Storage.Pointer + Reference (Data.Size - Upper);
            Upper := 0;
         end if;
      end if;
      --
      -- Here  we  already  know  that  the new block would fit into the
      -- buffer. We have to move Storage.Lower by block if necessary.
      --
      if (  Data.Lower /= Data.Upper -- Not empty
         and then            -- |<-current->|             |<-previous->|
            Lower >= Upper   -- |           |<--new-block-|-->         |
         and then            -- |           |Upper        |Lower       |
            Lower - Upper < Storage.Length
         )
      then
         --
         -- We have to move Storage.Lower by  block  sizes  until  there
         -- would be Length place between Upper and Lower.
         --
         declare
            Old  : constant Storage_Offset := Lower;
            Size : Storage_Offset;
         begin
            Size := Get_Block_Size (Data, Lower);
            if Size > 0 then
               loop
                  Lower := Lower + Size;
                  exit when Lower >= Data.Size;
                  Size := Get_Block_Size (Data, Lower);
                  exit when Size <= 0;
                  if Lower - Upper >= Storage.Length then
                     --
                     -- Now we have the place. Storage.Lower is advanced
                     -- to this index staying in the current frame.
                     --
                     Moved := Load (Data.Lower'Unchecked_Access) +
                              Reference (Lower - Old);
                     if Moved > Storage.Preserved then
                        raise Constraint_Error;
                     else
                        Store (Data.Lower'Access, Moved);
                        goto Done;
                     end if;
                  end if;
               end loop;
            end if;
            --
            -- The rest of the buffer is unused. Storage.Lower  is
            -- advanced to the next frame.
            --
            declare
               Old_Lower : constant Reference :=
                              Load (Data.Lower'Unchecked_Access);
            begin
               Moved :=
                  (  Old_Lower
                  +  Reference
                     (  Data.Size
                     -  Get_Offset (Data, Old_Lower)
                  )  );
            end;
            if Moved > Storage.Preserved then
               raise Constraint_Error;
            else
               Store (Data.Lower'Access, Moved);
            end if;
         end;
      end if;
<<Done>>
      Storage.Index := Upper + 1;
      Address :=
         Data.Data (Upper + 1)'Address + Aligned_Storage_Offset_Size;
   end Allocate;

   procedure Deallocate
             (  Storage   : in out Blackboard_Pool;
                Address   : System.Address;
                Size      : Storage_Count;
                Alignment : Storage_Count
             )  is
   begin
      null;
   end Deallocate;

   function First (Storage : Blackboard) return Reference is
   begin
      return Load (Storage.Data.Lower'Unchecked_Access);
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end First;

   function Get (Storage : Blackboard; Pointer : Reference)
      return Element_Type is
   begin
      if Storage.Data = null then
         Raise_Exception (Status_Error'Identity, Board_Init);
      end if;
      declare
         Data   : Blackboard_Data renames Storage.Data.all;
         Index  : Reference     := Pointer;
         Offset : Storage_Count := Get_Offset (Data, Pointer);
         Size   : Storage_Offset;
      begin
         if Pointer >= Data.Upper'Unchecked_Access then
            raise Constraint_Error;
         end if;
         Size := Get_Block_Size (Data, Offset) -
                 Aligned_Storage_Offset_Size;
         if Size <= 0 then
            if Size = -Aligned_Storage_Offset_Size then -- Wrapping
               Index := Index + Reference (Storage.Size - Offset);
               if Index >= Data.Upper'Unchecked_Access then
                  raise Constraint_Error; -- Reference is outside
               end if;
               Offset := 0;
               Size   := Get_Block_Size (Data, Offset) -
                         Aligned_Storage_Offset_Size;
               if (  Size <= 0
                  or else
                     Index < Data.Lower'Unchecked_Access
                  )  then
                  raise Constraint_Error;
               end if;
            else
               raise Constraint_Error;
            end if;
         end if;
         --
         -- The size must be valid, that means we can use it to copy the
         -- data from the buffer
         --
         Offset := Offset + Aligned_Storage_Offset_Size;
         declare
            Result : Buffer (1..Size) :=
                        Data.Data (Offset + 1..Offset + Size);
         begin
            --
            -- Here   Result   contains  a  raw  bit-wise  copy  of  the
            -- referenced  item. If the reference is no longer valid, we
            -- just drop an exception. Otherwise it is safe  to  convert
            -- it  to  the  legitimate  element type. Address to pointer
            -- conversion is used for. Note how Address_Offset is  added
            -- to obtain the "official" address. The offset is 0 for all
            -- types, but indefinite arrays. Though the offset is static
            -- it need to be evaluated, which the procedure Put does.
            --
            if Pointer < Data.Lower'Unchecked_Access then
               raise Constraint_Error;
            else
               return To_Pointer (Result'Address + Data.Offset).all;
            end if;
         end;
      end;
   end Get;

   function Get_Block_Size
            (  Storage : Blackboard_Data;
               Offset  : Storage_Offset
            )  return Storage_Offset is
      Size : aliased Storage_Offset;
      To   : constant Storage_Offset := Offset + Storage_Offset_Size;
   begin
      if To <= Storage.Data'Last then
         To_Pointer (Size'Address).all :=
            Storage.Data (Offset + 1..Offset + Storage_Offset_Size);
         return Size;
      else
         return 0;
      end if;
   end Get_Block_Size;

   function Get_Offset
            (  Storage : Blackboard_Data;
               Pointer : Reference
            )  return Storage_Offset is
   begin
      return Storage_Offset (Pointer mod Reference (Storage.Size));
   end Get_Offset;

   function Get_Signature (Storage : Blackboard) return Unsigned_16 is
   begin
      return 17;
   end Get_Signature;

   function Get_Size (Storage : Blackboard) return Storage_Count is
      subtype Data is Blackboard_Data (Storage.Size);
   begin
      return Round (Data'Max_Size_In_Storage_Elements);
   end Get_Size;

   function Image (Pointer : Reference) return String is
      Result : constant String := Reference'Image (Pointer);
   begin
      return Result (Result'First + 1..Result'Last);
   end Image;

   function Is_Valid (Storage : Blackboard; Pointer : Reference)
      return Boolean is
   begin
      declare
         Data : Blackboard_Data renames Storage.Data.all;
      begin
         return Pointer >= Data.Lower'Unchecked_Access and then
                Pointer <  Data.Upper'Unchecked_Access;
      end;
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end Is_Valid;

   procedure Map
             (  Storage  : in out Blackboard;
                Shared   : in out Abstract_Shared_Environment'Class;
                Location : System.Address;
                Size     : Storage_Count;
                Owner    : Boolean
             )  is
      subtype Data is Blackboard_Data (Storage.Size);
      package Mapper is new Generic_Memory_Mapper (Data);
      This : Abstract_Shared_Object_Ptr := Shared.First;
   begin
      while This /= null and then This /= Storage'Unchecked_Access loop
         if This.all in Mutex'Class then
            Storage.Lock := Mutex'Class (This.all)'Unchecked_Access;
         end if;
         This := This.Next;
      end loop;
      if Storage.Lock = null then
         Raise_Exception
         (  Data_Error'Identity,
            (  "The environment contains no mutex "
            &  "record member appearing before the blackboard object"
         )  );
      end if;
      Storage.Data := Mapper.Map (Location, Owner).all'Unchecked_Access;
   end Map;

   procedure Next
             (  Storage : Blackboard;
                Pointer : in out Reference;
                Sequent : out Boolean
             )  is
   begin
      declare
         Index  : Reference := Pointer;
         Data   : Blackboard_Data renames Storage.Data.all;
         Offset : Storage_Count;
         Size   : Storage_Offset;
      begin
         Sequent := True;
         if Index >= Data.Upper'Unchecked_Access then
            return;
         end if;
         Offset := Get_Offset (Data, Index);
         Size   := Get_Block_Size (Data, Offset);
         if Index < Data.Lower'Unchecked_Access then
            Pointer := Load (Data.Lower'Unchecked_Access);
            Sequent := False;
            return;
         end if;
         if Size <= 0 then
            Index := Index + Reference (Size + Data.Size - Offset);
            if Index >= Data.Upper'Unchecked_Access then -- Wrapped to
               return;                                   -- the end
            end if;
            Offset := 0;
            Size   := Get_Block_Size (Data, Offset);
            if Index < Data.Lower'Unchecked_Access then
               Pointer := Load (Data.Lower'Unchecked_Access);
               Sequent := False;
               return;
            end if;
         end if;
         Pointer := Index + Reference (Size);
      end;
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end Next;

   procedure Put
             (  Storage : in out Blackboard;
                Element : Element_Type;
                Pointer : out Reference;
                Timeout : Duration := Duration'Last
             )  is
      Started : constant Time := Clock;
   begin
      if Storage.Data = null then
         Raise_Exception (Status_Error'Identity, Board_Init);
      end if;
      declare
         Data : Blackboard_Data renames Storage.Data.all;
         Pool : Blackboard_Pool (Data'Access);
         --
         -- The  implementation  of  Blackboard is a storage pool. So in
         -- order to copy something into, we just allocate it there. For
         -- this an access type is created.
         --
         type Element_Type_Ptr is access Element_Type;
         for Element_Type_Ptr'Storage_Pool use Pool;
         Ptr : Element_Type_Ptr;
      begin
         Seize (Storage.Lock.all, Timeout - (Clock - Started));
         begin
            Pool.Preserved := Reference'Last;
            Ptr := new Element_Type'(Element);
            --
            -- A  copy  of  Element is allocated and Ptr is a pointer to
            -- it. The  pointer  might  be  shifted  if  Element  is  an
            -- indefinite  array.  Usually  the  array  address  is  the
            -- address of its first element rather  than  of  the  first
            -- allocated storage element. This offset is  type  specific
            -- and need  to  be  evaluated.  Which  is  the  purpose  of
            -- Address_Offset.
            --
            Data.Offset :=
               (  Ptr.all'Address
               -  Data.Data (Pool.Index)'Address
               -  Aligned_Storage_Offset_Size
               );
            Data.Data    -- Store the block size in front of the element
            (  Pool.Index
            .. Pool.Index + Storage_Offset_Size - 1
            )  := To_Pointer (Pool.Length'Address).all;
            --
            -- Finally, move the upper reference making the new  element
            -- accessible
            --
            Pointer := Pool.Pointer;
            Store
            (  Data.Upper'Access,
               Pointer + Reference (Pool.Length)
            );
            Release (Storage.Lock.all);
         exception
            when others =>
               Release (Storage.Lock.all);
         end;
      end;
   end Put;

   procedure Put
             (  Storage : in out Blackboard;
                Element : Element_Type;
                Timeout : Duration := Duration'Last
             )  is
      Started : constant Time := Clock;
   begin
      if Storage.Data = null then
         Raise_Exception (Status_Error'Identity, Board_Init);
      end if;
      declare
         Data : Blackboard_Data renames Storage.Data.all;
         Pool : Blackboard_Pool (Data'Access);

         type Element_Type_Ptr is access Element_Type;
         for Element_Type_Ptr'Storage_Pool use Pool;
         Ptr : Element_Type_Ptr;
      begin
         Seize (Storage.Lock.all, Timeout - (Clock - Started));
         begin
            Pool.Preserved := Reference'Last;
            Ptr := new Element_Type'(Element);
            --
            -- A  copy  of  Element is allocated and Ptr is a pointer to
            -- it. The  pointer  might  be  shifted  if  Element  is  an
            -- indefinite  array.  Usually  the  array  address  is  the
            -- address of its first element rather  than  of  the  first
            -- allocated storage element. This offset is  type  specific
            -- and need  to  be  evaluated.  Which  is  the  purpose  of
            -- Address_Offset.
            --
            Data.Offset :=
               (  Ptr.all'Address
               -  Data.Data (Pool.Index)'Address
               -  Aligned_Storage_Offset_Size
               );
            Data.Data    -- Store the block size in front of the element
            (  Pool.Index
            .. Pool.Index + Storage_Offset_Size - 1
            )  := To_Pointer (Pool.Length'Address).all;
            --
            -- Finally, move the upper reference making the new  element
            -- accessible
            --
            Store
            (  Data.Upper'Access,
               Pool.Pointer + Reference (Pool.Length)
            );
            Release (Storage.Lock.all);
         exception
            when others =>
               Release (Storage.Lock.all);
         end;
      end;
   end Put;

   procedure Put
             (  Storage  : in out Blackboard;
                Element  : Element_Type;
                Preserve : Reference;
                Pointer  : out Reference;
                Success  : out Boolean;
                Timeout  : Duration := Duration'Last
             )  is
      Started : constant Time := Clock;
   begin
      if Storage.Data = null then
         Raise_Exception (Status_Error'Identity, Board_Init);
      end if;
      declare
         Data : Blackboard_Data renames Storage.Data.all;
         Pool : Blackboard_Pool (Data'Access);
         --
         -- The  implementation  of  Blackboard is a storage pool. So in
         -- order to copy something into, we just allocate it there. For
         -- this an access type is created.
         --
         type Element_Type_Ptr is access Element_Type;
         for Element_Type_Ptr'Storage_Pool use Pool;
         Ptr : Element_Type_Ptr;
      begin
         Seize (Storage.Lock.all, Timeout - (Clock - Started));
         begin
            Pool.Preserved := Preserve;
            Ptr := new Element_Type'(Element);
            --
            -- A  copy  of  Element is allocated and Ptr is a pointer to
            -- it. The  pointer  might  be  shifted  if  Element  is  an
            -- indefinite  array.  Usually  the  array  address  is  the
            -- address of its first element rather  than  of  the  first
            -- allocated storage element. This offset is  type  specific
            -- and need  to  be  evaluated.  Which  is  the  purpose  of
            -- Address_Offset.
            --
            Data.Offset :=
               (  Ptr.all'Address
               -  Data.Data (Pool.Index)'Address
               -  Aligned_Storage_Offset_Size
               );
            Data.Data    -- Store the block size in front of the element
            (  Pool.Index
            .. Pool.Index + Storage_Offset_Size - 1
            )  := To_Pointer (Pool.Length'Address).all;
            --
            -- Finally, move the upper reference making the new  element
            -- accessible
            --
            Pointer := Pool.Pointer;
            Store
            (  Data.Upper'Access,
               Pointer + Reference (Pool.Length)
            );
            Success := True;
            Release (Storage.Lock.all);
         exception
            when Constraint_Error =>
               Success := False;
               Release (Storage.Lock.all);
            when others =>
               Release (Storage.Lock.all);
         end;
      end;
   end Put;

   procedure Put
             (  Storage  : in out Blackboard;
                Element  : Element_Type;
                Preserve : Reference;
                Success  : out Boolean;
                Timeout  : Duration := Duration'Last
             )  is
      Pointer : Reference;
   begin
      Put (Storage, Element, Preserve, Pointer, Success, Timeout);
   end Put;

   function Storage_Size (Storage : Blackboard_Pool)
      return Storage_Count is
   begin
      return Storage.Data.Size;
   end Storage_Size;

   function Upper (Storage : Blackboard) return Reference is
   begin
      return Load (Storage.Data.Upper'Unchecked_Access);
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end Upper;

   function "<" (Storage : Blackboard; Pointer : Reference)
      return Boolean is
   begin
      return LE (Load (Storage.Data.Upper'Unchecked_Access), Pointer);
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end "<";

   function "<" (Pointer : Reference; Storage : Blackboard)
      return Boolean is
   begin
      return LT (Pointer, Load (Storage.Data.Lower'Unchecked_Access));
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end "<";

   function "<"
            (  Left  : Reference;
               Right : Atomic_Reference_Ptr
            )  return Boolean is
   begin
      return LT (Left, Load (Right));
   end "<";

   function "<"  (Left, Right : Reference) return Boolean is
   begin
      return LT (Left, Right);
   end "<";

   function ">" (Storage : Blackboard; Pointer : Reference)
      return Boolean is
   begin
      return GT (Load (Storage.Data.Lower'Unchecked_Access), Pointer);
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end ">";

   function ">" (Pointer : Reference; Storage : Blackboard)
      return Boolean is
   begin
      return GE (Pointer, Load (Storage.Data.Upper'Unchecked_Access));
   exception
      when Constraint_Error =>
         if Storage.Data = null then
            Raise_Exception (Status_Error'Identity, Board_Init);
         else
            raise;
         end if;
   end ">";

   function ">" (Left, Right : Reference) return Boolean is
   begin
      return GT (Left, Right);
   end ">";

   function "<=" (Left, Right : Reference) return Boolean is
   begin
      return LE (Left, Right);
   end "<=";

   function ">=" (Left, Right : Reference) return Boolean is
   begin
      return GE (Left, Right);
   end ">=";

   function ">="
            (  Left  : Reference;
               Right : Atomic_Reference_Ptr
            )  return Boolean is
   begin
      return GE (Left, Load (Right));
   end ">=";

end Synchronization.Interprocess.Generic_Blackboard;