acrn-hypervisor/hypervisor/lib/spinlock.c
Mingqiang Chi 666430a3d4 hv:fix "missing for discarded return value" for memset
No need to check the return value for memset
code like this:
int a(void) {
	return 0;
}
int b(void){
	a();
}
fix as follow:
int a(void) {
	return 0;
}
int b(void){
	(void)a();
}

Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-07-05 14:14:48 +08:00

34 lines
794 B
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <hv_lib.h>
inline void spinlock_init(spinlock_t *lock)
{
(void)memset(lock, 0, sizeof(spinlock_t));
}
void spinlock_obtain(spinlock_t *lock)
{
/* The lock function atomically increments and exchanges the head
* counter of the queue. If the old head of the queue is equal to the
* tail, we have locked the spinlock. Otherwise we have to wait.
*/
asm volatile (" lock xaddl %%eax,%[head]\n"
" cmpl %%eax,%[tail]\n"
" jz 1f\n"
"2: pause\n"
" cmpl %%eax,%[tail]\n"
" jnz 2b\n"
"1:\n"
:
: "a" (1),
[head] "m"(lock->head),
[tail] "m"(lock->tail)
: "cc", "memory");
}