
  PROCEDURE [INLINE] mtp$clear_lock (VAR lock: mtt$monitor_lock);

{ Reading the free running clock in the compare swap loop is to prevent two CPUs
{ from getting in synch on compare swap when one CPU is trying to set a lock while
{ the other CPU is trying to clear the lock.
{ When they get in synch, the compare swap for the set always sees the lock set,
{ while the compare swap for the clear always sees that the other processor has
{ the word locked for compare swap (left 32 bits all ones).

    VAR
      frc: ost$free_running_clock,
      id,
      actual: integer,
      result: 0..2;

    id := #read_register (osc$pr_base_constant);
    REPEAT
      frc := #FREE_RUNNING_CLOCK (0);
      #compare_swap (lock, id, 0, actual, result);
      IF result = 1 THEN
        mtp$error_stop ('MT- wrong initial value for mtp$clear_lock');
      IFEND;
    UNTIL result = 0;

  PROCEND mtp$clear_lock;

?? PUSH (LISTEXT := ON) ??
*copyc mtt$monitor_lock
*copyc osc$processor_defined_registers
*copyc ost$free_running_clock
?? POP ??
