?? mutex.c
字號:
/*****************************************************************************
*
* Module : mutex
* Description : Simple Mutual Exclusion module that allows
* critical sections of code to have access to
* shared memory.
* OS : SLOS
* Platform : generic
* History :
*
* 10th November 2001 Andrew N. Sloss
* - add mutex to SLOS
*
*****************************************************************************/
/*****************************************************************************
* IMPORT
*****************************************************************************/
/* none... */
/*****************************************************************************
* MACROS
*****************************************************************************/
/* none... */
/*****************************************************************************
* STATICS
*****************************************************************************/
unsigned volatile int semaphore = 2; /* this is a start value */
/*****************************************************************************
* ROUTINES
*****************************************************************************/
/* -- mutex_gatelock ----------------------------------------------------------
*
* Description : Locks the semaphore...
*
* Parameters : none...
* Return : none...
* Notes :
*
*/
void mutex_gatelock (void)
{
register unsigned int semaAddr = (unsigned int) &semaphore;
asm volatile
(
"spin:\n"
" MOV r1, %0\n"
" MOV r2, #0x1\n"
" SWP r3, r2, [r1]\n"
" CMP r3, #0x1\n"
" BEQ spin\n"
: /* no output */
: "r" (semaAddr)
);
}
/* -- mutex_gateunlock --------------------------------------------------------
*
* Description : Unlocks the semaphore ...
*
* Parameters : none...
* Return : none...
* Notes :
*
*/
void mutex_gateunlock (void)
{
register unsigned int semaAddr = (unsigned int) &semaphore;
asm volatile
(
" mov r1, %0\n"
" mov r2, #0\n"
" swp r0,r2,[r1]"
: /* no output */
: "r" (semaAddr)
);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -