

/* usage exmaple:

   struct BarrStruct B;

   Barrier(&B);

   B is global

   count consists of two variables, used alternately to ensure
   correct operation even when the barrier call is within a short
   loop */

#define BARR_MAX_CPUS 64 

struct BarrStruct {
   int Count[2];
   int EvenOdd[BARR_MAX_CPUS];
} ;

Barrier(PB)
   struct BarrStruct *PB;

{  int Par,OldCount;

   Par = PB->EvenOdd[CPU_NUM];
   OldCount = AINC(PB->Count[Par]);
   if (OldCount == SYS_SIZE-1) PB->Count[Par] = 0;
   else while (PB->Count[Par] > 0) ;
   PB->EvenOdd[CPU_NUM] = 1 - Par;
}


