1 Star 0 Fork 0

pengchaochn/m5threads

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
spinlock_sparc.h 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
Daniel Sanchez 提交于 2009-02-11 08:59 +08:00 . Initial import
/*
m5threads, a pthread library for the M5 simulator
Copyright (C) 2009, Stanford University
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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
*/
#ifndef __SPINLOCK_SPARC_H__
#define __SPINLOCK_SPARC_H__
// routines from /usr/src/linux/include/asm-sparc/spinlock_64.h
// Note: these work even with RMO, but a few barriers could be eliminated for TSO
static __inline__ void spin_lock(volatile int* lock)
{
unsigned long tmp;
__asm__ __volatile__(
"1: ldstub [%1], %0\n"
" membar #StoreLoad | #StoreStore\n"
" brnz,pn %0, 2f\n"
" nop\n"
" .subsection 2\n"
"2: ldub [%1], %0\n"
" membar #LoadLoad\n"
" brnz,pt %0, 2b\n"
" nop\n"
" ba,a,pt %%xcc, 1b\n"
" .previous"
: "=&r" (tmp)
: "r" (lock)
: "memory");
}
static __inline__ int trylock(volatile int* lock)
{
unsigned long result;
__asm__ __volatile__(
" ldstub [%1], %0\n"
" membar #StoreLoad | #StoreStore"
: "=r" (result)
: "r" (lock)
: "memory");
return (result == 0);
}
static __inline__ void spin_unlock(volatile int* lock)
{
__asm__ __volatile__(
" membar #StoreStore | #LoadStore\n"
" stb %%g0, [%0]"
: // No outputs
: "r" (lock)
: "memory");
}
#endif // __SPINLOCK_SPARC_H__
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pengchaochn/m5threads.git
git@gitee.com:pengchaochn/m5threads.git
pengchaochn
m5threads
m5threads
master

搜索帮助