: "i" (2)
: "r1", "r20", "r22", "r29", "r31", "fr4", "memory"
);
+
+ /* If the kernel LWS call is successful, lws_ret contains 0. */
+ if (__builtin_expect (lws_ret == 0, 1))
+ return 0;
+
if (__builtin_expect (lws_errno == -EFAULT || lws_errno == -ENOSYS, 0))
__builtin_trap ();
- /* If the kernel LWS call fails, return EBUSY */
- if (!lws_errno && lws_ret)
- lws_errno = -EBUSY;
+ /* If the kernel LWS call fails with no error, return -EBUSY */
+ if (__builtin_expect (!lws_errno, 0))
+ return -EBUSY;
return lws_errno;
}
__sync_fetch_and_##OP##_##WIDTH (TYPE *ptr, TYPE val) \
{ \
TYPE tmp, newval; \
- int failure; \
+ long failure; \
\
do { \
tmp = __atomic_load_n (ptr, __ATOMIC_SEQ_CST); \
return tmp; \
}
+FETCH_AND_OP_2 (add, , +, long long, 8, 3)
+FETCH_AND_OP_2 (sub, , -, long long, 8, 3)
+FETCH_AND_OP_2 (or, , |, long long, 8, 3)
+FETCH_AND_OP_2 (and, , &, long long, 8, 3)
+FETCH_AND_OP_2 (xor, , ^, long long, 8, 3)
+FETCH_AND_OP_2 (nand, ~, &, long long, 8, 3)
+
FETCH_AND_OP_2 (add, , +, short, 2, 1)
FETCH_AND_OP_2 (sub, , -, short, 2, 1)
FETCH_AND_OP_2 (or, , |, short, 2, 1)
__sync_##OP##_and_fetch_##WIDTH (TYPE *ptr, TYPE val) \
{ \
TYPE tmp, newval; \
- int failure; \
+ long failure; \
\
do { \
tmp = __atomic_load_n (ptr, __ATOMIC_SEQ_CST); \
return PFX_OP (tmp INF_OP val); \
}
+OP_AND_FETCH_2 (add, , +, long long, 8, 3)
+OP_AND_FETCH_2 (sub, , -, long long, 8, 3)
+OP_AND_FETCH_2 (or, , |, long long, 8, 3)
+OP_AND_FETCH_2 (and, , &, long long, 8, 3)
+OP_AND_FETCH_2 (xor, , ^, long long, 8, 3)
+OP_AND_FETCH_2 (nand, ~, &, long long, 8, 3)
+
OP_AND_FETCH_2 (add, , +, short, 2, 1)
OP_AND_FETCH_2 (sub, , -, short, 2, 1)
OP_AND_FETCH_2 (or, , |, short, 2, 1)
int HIDDEN \
__sync_fetch_and_##OP##_4 (int *ptr, int val) \
{ \
- int failure, tmp; \
+ int tmp; \
+ long failure; \
\
do { \
tmp = __atomic_load_n (ptr, __ATOMIC_SEQ_CST); \
int HIDDEN \
__sync_##OP##_and_fetch_4 (int *ptr, int val) \
{ \
- int tmp, failure; \
+ int tmp; \
+ long failure; \
\
do { \
tmp = __atomic_load_n (ptr, __ATOMIC_SEQ_CST); \
TYPE newval) \
{ \
TYPE actual_oldval; \
- int fail; \
+ long fail; \
\
while (1) \
{ \
__sync_bool_compare_and_swap_##WIDTH (TYPE *ptr, TYPE oldval, \
TYPE newval) \
{ \
- int failure = __kernel_cmpxchg2 (ptr, &oldval, &newval, INDEX); \
- return (failure != 0); \
+ long failure = __kernel_cmpxchg2 (ptr, &oldval, &newval, INDEX); \
+ return (failure == 0); \
}
+COMPARE_AND_SWAP_2 (long long, 8, 3)
COMPARE_AND_SWAP_2 (short, 2, 1)
COMPARE_AND_SWAP_2 (char, 1, 0)
int HIDDEN
__sync_val_compare_and_swap_4 (int *ptr, int oldval, int newval)
{
- int actual_oldval, fail;
+ long fail;
+ int actual_oldval;
while (1)
{
bool HIDDEN
__sync_bool_compare_and_swap_4 (int *ptr, int oldval, int newval)
{
- int failure = __kernel_cmpxchg (ptr, oldval, newval);
+ long failure = __kernel_cmpxchg (ptr, oldval, newval);
return (failure == 0);
}
__sync_lock_test_and_set_##WIDTH (TYPE *ptr, TYPE val) \
{ \
TYPE oldval; \
- int failure; \
+ long failure; \
\
do { \
oldval = __atomic_load_n (ptr, __ATOMIC_SEQ_CST); \
return oldval; \
}
+SYNC_LOCK_TEST_AND_SET_2 (long long, 8, 3)
SYNC_LOCK_TEST_AND_SET_2 (short, 2, 1)
SYNC_LOCK_TEST_AND_SET_2 (signed char, 1, 0)
int HIDDEN
__sync_lock_test_and_set_4 (int *ptr, int val)
{
- int failure, oldval;
+ long failure;
+ int oldval;
do {
oldval = __atomic_load_n (ptr, __ATOMIC_SEQ_CST);
void HIDDEN \
__sync_lock_release_##WIDTH (TYPE *ptr) \
{ \
- TYPE failure, oldval, zero = 0; \
+ TYPE oldval, zero = 0; \
+ long failure; \
\
do { \
oldval = __atomic_load_n (ptr, __ATOMIC_SEQ_CST); \
} while (failure != 0); \
}
+SYNC_LOCK_RELEASE_2 (long long, 8, 3)
SYNC_LOCK_RELEASE_2 (short, 2, 1)
SYNC_LOCK_RELEASE_2 (signed char, 1, 0)
void HIDDEN
__sync_lock_release_4 (int *ptr)
{
- int failure, oldval;
+ long failure;
+ int oldval;
do {
oldval = __atomic_load_n (ptr, __ATOMIC_SEQ_CST);