OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc2/] [gcc/] [config/] [vxlib.c] - Diff between revs 282 and 384

Only display areas with differences | Details | Blame | View Log

Rev 282 Rev 384
/* Copyright (C) 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
/* Copyright (C) 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
   Contributed by Zack Weinberg <zack@codesourcery.com>
   Contributed by Zack Weinberg <zack@codesourcery.com>
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify it under
GCC 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
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
Software Foundation; either version 3, or (at your option) any later
version.
version.
 
 
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
for more details.
 
 
Under Section 7 of GPL version 3, you are granted additional
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
3.1, as published by the Free Software Foundation.
 
 
You should have received a copy of the GNU General Public License and
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
/* Threads compatibility routines for libgcc2 for VxWorks.
/* Threads compatibility routines for libgcc2 for VxWorks.
   These are out-of-line routines called from gthr-vxworks.h.  */
   These are out-of-line routines called from gthr-vxworks.h.  */
 
 
#include "tconfig.h"
#include "tconfig.h"
#include "tsystem.h"
#include "tsystem.h"
#include "gthr.h"
#include "gthr.h"
 
 
#if defined(__GTHREADS)
#if defined(__GTHREADS)
#include <vxWorks.h>
#include <vxWorks.h>
#ifndef __RTP__
#ifndef __RTP__
#include <vxLib.h>
#include <vxLib.h>
#endif
#endif
#include <taskLib.h>
#include <taskLib.h>
#ifndef __RTP__
#ifndef __RTP__
#include <taskHookLib.h>
#include <taskHookLib.h>
#else
#else
# include <errno.h>
# include <errno.h>
#endif
#endif
 
 
/* Init-once operation.
/* Init-once operation.
 
 
   This would be a clone of the implementation from gthr-solaris.h,
   This would be a clone of the implementation from gthr-solaris.h,
   except that we have a bootstrap problem - the whole point of this
   except that we have a bootstrap problem - the whole point of this
   exercise is to prevent double initialization, but if two threads
   exercise is to prevent double initialization, but if two threads
   are racing with each other, once->mutex is liable to be initialized
   are racing with each other, once->mutex is liable to be initialized
   by both.  Then each thread will lock its own mutex, and proceed to
   by both.  Then each thread will lock its own mutex, and proceed to
   call the initialization routine.
   call the initialization routine.
 
 
   So instead we use a bare atomic primitive (vxTas()) to handle
   So instead we use a bare atomic primitive (vxTas()) to handle
   mutual exclusion.  Threads losing the race then busy-wait, calling
   mutual exclusion.  Threads losing the race then busy-wait, calling
   taskDelay() to yield the processor, until the initialization is
   taskDelay() to yield the processor, until the initialization is
   completed.  Inefficient, but reliable.  */
   completed.  Inefficient, but reliable.  */
 
 
int
int
__gthread_once (__gthread_once_t *guard, void (*func)(void))
__gthread_once (__gthread_once_t *guard, void (*func)(void))
{
{
  if (guard->done)
  if (guard->done)
    return 0;
    return 0;
 
 
#ifdef __RTP__
#ifdef __RTP__
  __gthread_lock_library ();
  __gthread_lock_library ();
#else
#else
  while (!vxTas ((void *)&guard->busy))
  while (!vxTas ((void *)&guard->busy))
    {
    {
#ifdef __PPC__
#ifdef __PPC__
      /* This can happen on powerpc, which is using all 32 bits
      /* This can happen on powerpc, which is using all 32 bits
         of the gthread_once_t structure.  */
         of the gthread_once_t structure.  */
      if (guard->done)
      if (guard->done)
        return;
        return;
#endif
#endif
      taskDelay (1);
      taskDelay (1);
    }
    }
#endif
#endif
 
 
  /* Only one thread at a time gets here.  Check ->done again, then
  /* Only one thread at a time gets here.  Check ->done again, then
     go ahead and call func() if no one has done it yet.  */
     go ahead and call func() if no one has done it yet.  */
  if (!guard->done)
  if (!guard->done)
    {
    {
      func ();
      func ();
      guard->done = 1;
      guard->done = 1;
    }
    }
 
 
#ifdef __RTP__
#ifdef __RTP__
  __gthread_unlock_library ();
  __gthread_unlock_library ();
#else
#else
  guard->busy = 0;
  guard->busy = 0;
#endif
#endif
  return 0;
  return 0;
}
}
 
 
#endif /* __GTHREADS */
#endif /* __GTHREADS */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.