Back to index

glibc  2.9
pspinlock.c
Go to the documentation of this file.
00001 /* POSIX spinlock implementation.  MIPS version.
00002    Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License as
00007    published by the Free Software Foundation; either version 2.1 of the
00008    License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00017    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.  */
00019 
00020 #include <errno.h>
00021 #include <pthread.h>
00022 #include <sgidefs.h>
00023 #include <sys/tas.h>
00024 #include "internals.h"
00025 
00026 #include <sgidefs.h>
00027 
00028 /* This implementation is similar to the one used in the Linux kernel.  */
00029 int
00030 __pthread_spin_lock (pthread_spinlock_t *lock)
00031 {
00032   unsigned int tmp1, tmp2;
00033 
00034   asm volatile
00035     ("\t\t\t# spin_lock\n"
00036      "1:\n\t"
00037      ".set    push\n\t"
00038 #if _MIPS_SIM == _ABIO32
00039      ".set    mips2\n\t"
00040 #endif
00041      "ll      %1,%3\n\t"
00042      "li      %2,1\n\t"
00043      "bnez    %1,1b\n\t"
00044      "sc      %2,%0\n\t"
00045      ".set    pop\n\t"
00046      "beqz    %2,1b"
00047      : "=m" (*lock), "=&r" (tmp1), "=&r" (tmp2)
00048      : "m" (*lock)
00049      : "memory");
00050 
00051   return 0;
00052 }
00053 
00054 weak_alias (__pthread_spin_lock, pthread_spin_lock)
00055 
00056 
00057 int
00058 __pthread_spin_trylock (pthread_spinlock_t *lock)
00059 {
00060   /* To be done.  */
00061   return 0;
00062 }
00063 weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
00064 
00065 
00066 int
00067 __pthread_spin_unlock (pthread_spinlock_t *lock)
00068 {
00069   asm volatile
00070     ("\t\t\t# spin_unlock\n\t"
00071      "sw      $0,%0"
00072      : "=m" (*lock)
00073      :
00074      : "memory");
00075   return 0;
00076 }
00077 weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
00078 
00079 
00080 int
00081 __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
00082 {
00083   /* We can ignore the `pshared' parameter.  Since we are busy-waiting
00084      all processes which can access the memory location `lock' points
00085      to can use the spinlock.  */
00086   *lock = 0;
00087   return 0;
00088 }
00089 weak_alias (__pthread_spin_init, pthread_spin_init)
00090 
00091 
00092 int
00093 __pthread_spin_destroy (pthread_spinlock_t *lock)
00094 {
00095   /* Nothing to do.  */
00096   return 0;
00097 }
00098 weak_alias (__pthread_spin_destroy, pthread_spin_destroy)