更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
Atomic
Atomic 的协作图:

函数

STATIC INLINE INT32 LOS_AtomicRead (const Atomic *v)
 Atomic read. | 读取32bit原子数据 更多...
 
STATIC INLINE VOID LOS_AtomicSet (Atomic *v, INT32 setVal)
 Atomic setting. 更多...
 
STATIC INLINE INT32 LOS_AtomicAdd (Atomic *v, INT32 addVal)
 Atomic addition. 更多...
 
STATIC INLINE INT32 LOS_AtomicSub (Atomic *v, INT32 subVal)
 Atomic subtraction. 更多...
 
STATIC INLINE VOID LOS_AtomicInc (Atomic *v)
 Atomic addSelf. 更多...
 
STATIC INLINE INT32 LOS_AtomicIncRet (Atomic *v)
 Atomic addSelf. | 对内存数据加1并返回运算结果 更多...
 
STATIC INLINE VOID LOS_AtomicDec (Atomic *v)
 Atomic auto-decrement. | 对32bit原子数据做减1 更多...
 
STATIC INLINE INT32 LOS_AtomicDecRet (Atomic *v)
 Atomic auto-decrement. | 对内存数据减1并返回运算结果 更多...
 
STATIC INLINE INT64 LOS_Atomic64Read (const Atomic64 *v)
 Atomic64 read. | 读取64bit原子数据 更多...
 
STATIC INLINE VOID LOS_Atomic64Set (Atomic64 *v, INT64 setVal)
 Atomic64 setting. | 写入64位内存数据 更多...
 
STATIC INLINE INT64 LOS_Atomic64Add (Atomic64 *v, INT64 addVal)
 Atomic64 addition. | 对64位内存数据做加法 更多...
 
STATIC INLINE INT64 LOS_Atomic64Sub (Atomic64 *v, INT64 subVal)
 Atomic64 subtraction. | 对64位原子数据做减法 更多...
 
STATIC INLINE VOID LOS_Atomic64Inc (Atomic64 *v)
 Atomic64 addSelf. | 对64位原子数据加1 更多...
 
STATIC INLINE INT64 LOS_Atomic64IncRet (Atomic64 *v)
 Atomic64 addSelf. | 对64位原子数据加1并返回运算结果 更多...
 
STATIC INLINE VOID LOS_Atomic64Dec (Atomic64 *v)
 Atomic64 auto-decrement. | 对64位原子数据减1 更多...
 
STATIC INLINE INT64 LOS_Atomic64DecRet (Atomic64 *v)
 Atomic64 auto-decrement. | 对64位原子数据减1并返回运算结果 更多...
 
STATIC INLINE INT32 LOS_AtomicXchgByte (volatile INT8 *v, INT32 val)
 Atomic exchange for 8-bit variable. | 交换8位原子数据,原内存中的值以返回值的方式返回 更多...
 
STATIC INLINE INT32 LOS_AtomicXchg16bits (volatile INT16 *v, INT32 val)
 Atomic exchange for 16-bit variable. | 交换16位原子数据,原内存中的值以返回值的方式返回 更多...
 
STATIC INLINE INT32 LOS_AtomicXchg32bits (Atomic *v, INT32 val)
 Atomic exchange for 32-bit variable. | 交换32位原子数据,原内存中的值以返回值的方式返回 更多...
 
STATIC INLINE INT64 LOS_AtomicXchg64bits (Atomic64 *v, INT64 val)
 Atomic exchange for 64-bit variable. | 交换64位原子数据,原内存中的值以返回值的方式返回 更多...
 
STATIC INLINE BOOL LOS_AtomicCmpXchgByte (volatile INT8 *v, INT32 val, INT32 oldVal)
 Atomic exchange for 8-bit variable with compare. | 比较并交换8位原子数据,返回比较结果 更多...
 
STATIC INLINE BOOL LOS_AtomicCmpXchg16bits (volatile INT16 *v, INT32 val, INT32 oldVal)
 Atomic exchange for 16-bit variable with compare. | 比较并交换16位原子数据,返回比较结果 更多...
 
STATIC INLINE BOOL LOS_AtomicCmpXchg32bits (Atomic *v, INT32 val, INT32 oldVal)
 Atomic exchange for 32-bit variable with compare. | 比较并交换32位原子数据,返回比较结果 更多...
 
STATIC INLINE BOOL LOS_AtomicCmpXchg64bits (Atomic64 *v, INT64 val, INT64 oldVal)
 Atomic exchange for 64-bit variable with compare. | 比较并交换64位原子数据,返回比较结果 更多...
 

详细描述

函数说明

◆ LOS_Atomic64Add()

STATIC INLINE INT64 LOS_Atomic64Add ( Atomic64 v,
INT64  addVal 
)

Atomic64 addition. | 对64位内存数据做加法

Description:
This API is used to implement the atomic64 addition and return the result value of the augend.
注意
  • The pointer v must not be NULL.
  • If the addtion result is not in the range of representable values for 64-bit signed integer, an int integer overflow may occur to the return value
参数
v[IN] The augend pointer.
addVal[IN] The addend.
返回值
INT64The result value of the augend.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h460 行定义.

461{
462 INT64 val;
463 UINT32 status;
464
465 do {
466 __asm__ __volatile__("ldrexd %1, %H1, [%2]\n"
467 "adds %Q1, %Q1, %Q3\n"
468 "adc %R1, %R1, %R3\n"
469 "strexd %0, %1, %H1, [%2]"
470 : "=&r"(status), "=&r"(val)
471 : "r"(v), "r"(addVal)
472 : "cc");
473 } while (__builtin_expect(status != 0, 0));
474
475 return val;
476}
unsigned int UINT32
Definition: los_typedef.h:57
long signed int INT64
Definition: los_typedef.h:67

◆ LOS_Atomic64Dec()

STATIC INLINE VOID LOS_Atomic64Dec ( Atomic64 v)

Atomic64 auto-decrement. | 对64位原子数据减1

Description:
This API is used to implementating the atomic64 auto-decrement.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT64_MIN to avoid overflow after reducing 1.
参数
v[IN] The auto-decrement variable pointer.
返回值
none.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h608 行定义.

609{
610 INT64 val;
611 UINT32 status;
612
613 do {
614 __asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
615 "subs %Q0, %Q0, #1\n"
616 "sbc %R0, %R0, #0\n"
617 "strexd %1, %0, %H0, [%3]"
618 : "=&r"(val), "=&r"(status), "+m"(*v)
619 : "r"(v)
620 : "cc");
621 } while (__builtin_expect(status != 0, 0));
622}

◆ LOS_Atomic64DecRet()

STATIC INLINE INT64 LOS_Atomic64DecRet ( Atomic64 v)

Atomic64 auto-decrement. | 对64位原子数据减1并返回运算结果

Description:
This API is used to implementating the atomic64 auto-decrement and return the result of auto-decrement.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT64_MIN to avoid overflow after reducing 1.
参数
v[IN] The auto-decrement variable pointer.
返回值
INT64The return value of variable auto-decrement.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h643 行定义.

644{
645 INT64 val;
646 UINT32 status;
647
648 do {
649 __asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
650 "subs %Q0, %Q0, #1\n"
651 "sbc %R0, %R0, #0\n"
652 "strexd %1, %0, %H0, [%3]"
653 : "=&r"(val), "=&r"(status), "+m"(*v)
654 : "r"(v)
655 : "cc");
656 } while (__builtin_expect(status != 0, 0));
657
658 return val;
659}

◆ LOS_Atomic64Inc()

STATIC INLINE VOID LOS_Atomic64Inc ( Atomic64 v)

Atomic64 addSelf. | 对64位原子数据加1

Description:
This API is used to implement the atomic64 addSelf .
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT64_MAX to avoid integer overflow after adding 1.
参数
v[IN] The addSelf variable pointer.
返回值
none.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h536 行定义.

537{
538 INT64 val;
539 UINT32 status;
540
541 do {
542 __asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
543 "adds %Q0, %Q0, #1\n"
544 "adc %R0, %R0, #0\n"
545 "strexd %1, %0, %H0, [%3]"
546 : "=&r"(val), "=&r"(status), "+m"(*v)
547 : "r"(v)
548 : "cc");
549 } while (__builtin_expect(status != 0, 0));
550}

◆ LOS_Atomic64IncRet()

STATIC INLINE INT64 LOS_Atomic64IncRet ( Atomic64 v)

Atomic64 addSelf. | 对64位原子数据加1并返回运算结果

Description:
This API is used to implement the atomic64 addSelf and return the result of addSelf.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT64_MAX to avoid integer overflow after adding 1.
参数
v[IN] The addSelf variable pointer.
返回值
INT64The return value of variable addSelf.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h571 行定义.

572{
573 INT64 val;
574 UINT32 status;
575
576 do {
577 __asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
578 "adds %Q0, %Q0, #1\n"
579 "adc %R0, %R0, #0\n"
580 "strexd %1, %0, %H0, [%3]"
581 : "=&r"(val), "=&r"(status), "+m"(*v)
582 : "r"(v)
583 : "cc");
584 } while (__builtin_expect(status != 0, 0));
585
586 return val;
587}

◆ LOS_Atomic64Read()

STATIC INLINE INT64 LOS_Atomic64Read ( const Atomic64 v)

Atomic64 read. | 读取64bit原子数据

Description:
This API is used to implement the atomic64 read and return the result value of the read.
注意
  • The pointer v must not be NULL.
参数
v[IN] The reading pointer.
返回值
INT64The result value of the read.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h392 行定义.

393{
394 INT64 val;
395
396 do {
397 __asm__ __volatile__("ldrexd %0, %H0, [%1]"
398 : "=&r"(val)
399 : "r"(v)
400 : "cc");
401 } while (0);
402
403 return val;
404}

◆ LOS_Atomic64Set()

STATIC INLINE VOID LOS_Atomic64Set ( Atomic64 v,
INT64  setVal 
)

Atomic64 setting. | 写入64位内存数据

Description:
This API is used to implement the atomic64 setting operation.
注意
  • The pointer v must not be NULL.
参数
v[IN] The variable pointer to be setting.
setVal[IN] The value to be setting.
返回值
none.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h425 行定义.

426{
427 INT64 tmp;
428 UINT32 status;
429
430 do {
431 __asm__ __volatile__("ldrexd %1, %H1, [%2]\n"
432 "strexd %0, %3, %H3, [%2]"
433 : "=&r"(status), "=&r"(tmp)
434 : "r"(v), "r"(setVal)
435 : "cc");
436 } while (__builtin_expect(status != 0, 0));
437}

◆ LOS_Atomic64Sub()

STATIC INLINE INT64 LOS_Atomic64Sub ( Atomic64 v,
INT64  subVal 
)

Atomic64 subtraction. | 对64位原子数据做减法

Description:
This API is used to implement the atomic64 subtraction and return the result value of the minuend.
注意
  • The pointer v must not be NULL.
  • If the subtraction result is not in the range of representable values for 64-bit signed integer, an int integer overflow may occur to the return value
参数
v[IN] The minuend pointer.
subVal[IN] The subtrahend.
返回值
INT64The result value of the minuend.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h499 行定义.

500{
501 INT64 val;
502 UINT32 status;
503
504 do {
505 __asm__ __volatile__("ldrexd %1, %H1, [%2]\n"
506 "subs %Q1, %Q1, %Q3\n"
507 "sbc %R1, %R1, %R3\n"
508 "strexd %0, %1, %H1, [%2]"
509 : "=&r"(status), "=&r"(val)
510 : "r"(v), "r"(subVal)
511 : "cc");
512 } while (__builtin_expect(status != 0, 0));
513
514 return val;
515}

◆ LOS_AtomicAdd()

STATIC INLINE INT32 LOS_AtomicAdd ( Atomic v,
INT32  addVal 
)

Atomic addition.

Description:
This API is used to implement the atomic addition and return the result value of the augend.
注意
  • The pointer v must not be NULL.
  • If the addtion result is not in the range of representable values for 32-bit signed integer, an int integer overflow may occur to the return value
参数
v[IN] The augend pointer.
addVal[IN] The addend.
返回值
INT32The result value of the augend.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h173 行定义.

174{
175 INT32 val;
176 UINT32 status;
177
178 do {
179 __asm__ __volatile__("ldrex %1, [%2]\n"
180 "add %1, %1, %3\n"
181 "strex %0, %1, [%2]"
182 : "=&r"(status), "=&r"(val)
183 : "r"(v), "r"(addVal)
184 : "cc");
185 } while (__builtin_expect(status != 0, 0));
186 /****************************************************
187 __builtin_expect是结束循环的判断语句,将最有可能执行的分支告诉编译器。
188 这个指令的写法为:__builtin_expect(EXP, N)。
189 意思是:EXP==N 的概率很大。
190 综合理解__builtin_expect(status != 0, 0)
191 说的是status = 0 的可能性很大,不成功就会重新来一遍,直到strex更新成(status == 0)为止.
192 ****************************************************/
193 return val;
194}
signed int INT32
Definition: los_typedef.h:60
这是这个函数的调用关系图:

◆ LOS_AtomicCmpXchg16bits()

STATIC INLINE BOOL LOS_AtomicCmpXchg16bits ( volatile INT16 v,
INT32  val,
INT32  oldVal 
)

Atomic exchange for 16-bit variable with compare. | 比较并交换16位原子数据,返回比较结果

Description:
This API is used to implement the atomic exchange for 16-bit variable, if the value of variable is equal to oldVal.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The new value.
oldVal[IN] The old value.
返回值
TRUEThe previous value of the atomic variable is not equal to oldVal.
FALSEThe previous value of the atomic variable is equal to oldVal.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h853 行定义.

854{
855 INT32 prevVal;
856 UINT32 status;
857
858 do {
859 __asm__ __volatile__("ldrexh %0, [%3]\n"
860 "mov %1, #0\n"
861 "teq %0, %4\n"
862 "strexheq %1, %5, [%3]"
863 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
864 : "r"(v), "r"(oldVal), "r"(val)
865 : "cc");
866 } while (__builtin_expect(status != 0, 0));
867
868 return prevVal != oldVal;
869}

◆ LOS_AtomicCmpXchg32bits()

STATIC INLINE BOOL LOS_AtomicCmpXchg32bits ( Atomic v,
INT32  val,
INT32  oldVal 
)

Atomic exchange for 32-bit variable with compare. | 比较并交换32位原子数据,返回比较结果

Description:
This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The new value.
oldVal[IN] The old value.
返回值
TRUEThe previous value of the atomic variable is not equal to oldVal.
FALSEThe previous value of the atomic variable is equal to oldVal.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h890 行定义.

891{
892 INT32 prevVal;
893 UINT32 status;
894
895 do {
896 __asm__ __volatile__("ldrex %0, [%3]\n"
897 "mov %1, #0\n"
898 "teq %0, %4\n"
899 "strexeq %1, %5, [%3]"
900 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
901 : "r"(v), "r"(oldVal), "r"(val)
902 : "cc");
903 } while (__builtin_expect(status != 0, 0));
904
905 return prevVal != oldVal;
906}
这是这个函数的调用关系图:

◆ LOS_AtomicCmpXchg64bits()

STATIC INLINE BOOL LOS_AtomicCmpXchg64bits ( Atomic64 v,
INT64  val,
INT64  oldVal 
)

Atomic exchange for 64-bit variable with compare. | 比较并交换64位原子数据,返回比较结果

Description:
This API is used to implement the atomic exchange for 64-bit variable, if the value of variable is equal to oldVal.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The new value.
oldVal[IN] The old value.
返回值
TRUEThe previous value of the atomic variable is not equal to oldVal.
FALSEThe previous value of the atomic variable is equal to oldVal.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h927 行定义.

928{
929 INT64 prevVal;
930 UINT32 status;
931
932 do {
933 __asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
934 "mov %1, #0\n"
935 "teq %0, %4\n"
936 "teqeq %H0, %H4\n"
937 "strexdeq %1, %5, %H5, [%3]"
938 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
939 : "r"(v), "r"(oldVal), "r"(val)
940 : "cc");
941 } while (__builtin_expect(status != 0, 0));
942
943 return prevVal != oldVal;
944}

◆ LOS_AtomicCmpXchgByte()

STATIC INLINE BOOL LOS_AtomicCmpXchgByte ( volatile INT8 v,
INT32  val,
INT32  oldVal 
)

Atomic exchange for 8-bit variable with compare. | 比较并交换8位原子数据,返回比较结果

Description:
This API is used to implement the atomic exchange for 8-bit variable, if the value of variable is equal to oldVal.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The new value.
oldVal[IN] The old value.
返回值
TRUEThe previous value of the atomic variable is not equal to oldVal.
FALSEThe previous value of the atomic variable is equal to oldVal.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h816 行定义.

817{
818 INT32 prevVal;
819 UINT32 status;
820
821 do {
822 __asm__ __volatile__("ldrexb %0, [%3]\n"
823 "mov %1, #0\n"
824 "teq %0, %4\n"
825 "strexbeq %1, %5, [%3]"
826 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
827 : "r"(v), "r"(oldVal), "r"(val)
828 : "cc");
829 } while (__builtin_expect(status != 0, 0));
830
831 return prevVal != oldVal;
832}

◆ LOS_AtomicDec()

STATIC INLINE VOID LOS_AtomicDec ( Atomic v)

Atomic auto-decrement. | 对32bit原子数据做减1

Description:
This API is used to implementating the atomic auto-decrement.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT_MIN to avoid overflow after reducing 1.
参数
v[IN] The auto-decrement variable pointer.
返回值
none.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h323 行定义.

324{
325 INT32 val;
326 UINT32 status;
327
328 do {
329 __asm__ __volatile__("ldrex %0, [%3]\n"
330 "sub %0, %0, #1\n"
331 "strex %1, %0, [%3]"
332 : "=&r"(val), "=&r"(status), "+m"(*v)
333 : "r"(v)
334 : "cc");
335 } while (__builtin_expect(status != 0, 0));
336}
这是这个函数的调用关系图:

◆ LOS_AtomicDecRet()

STATIC INLINE INT32 LOS_AtomicDecRet ( Atomic v)

Atomic auto-decrement. | 对内存数据减1并返回运算结果

Description:
This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT_MIN to avoid overflow after reducing 1.
参数
v[IN] The auto-decrement variable pointer.
返回值
INT32The return value of variable auto-decrement.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h357 行定义.

358{
359 INT32 val;
360 UINT32 status;
361
362 do {
363 __asm__ __volatile__("ldrex %0, [%3]\n"
364 "sub %0, %0, #1\n"
365 "strex %1, %0, [%3]"
366 : "=&r"(val), "=&r"(status), "+m"(*v)
367 : "r"(v)
368 : "cc");
369 } while (__builtin_expect(status != 0, 0));
370
371 return val;
372}
这是这个函数的调用关系图:

◆ LOS_AtomicInc()

STATIC INLINE VOID LOS_AtomicInc ( Atomic v)

Atomic addSelf.

Description:
This API is used to implement the atomic addSelf.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT_MAX to avoid integer overflow after adding 1.
参数
v[IN] The addSelf variable pointer.
返回值
none.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h253 行定义.

254{
255 INT32 val;
256 UINT32 status;
257
258 do {
259 __asm__ __volatile__("ldrex %0, [%3]\n"
260 "add %0, %0, #1\n"
261 "strex %1, %0, [%3]"
262 : "=&r"(val), "=&r"(status), "+m"(*v)
263 : "r"(v)
264 : "cc");
265 } while (__builtin_expect(status != 0, 0));
266}
这是这个函数的调用关系图:

◆ LOS_AtomicIncRet()

STATIC INLINE INT32 LOS_AtomicIncRet ( Atomic v)

Atomic addSelf. | 对内存数据加1并返回运算结果

Description:
This API is used to implement the atomic addSelf and return the result of addSelf.
注意
  • The pointer v must not be NULL.
  • The value which v point to must not be INT_MAX to avoid integer overflow after adding 1.
参数
v[IN] The addSelf variable pointer.
返回值
INT32The return value of variable addSelf.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h287 行定义.

288{
289 INT32 val;
290 UINT32 status;
291
292 do {
293 __asm__ __volatile__("ldrex %0, [%3]\n"
294 "add %0, %0, #1\n"
295 "strex %1, %0, [%3]"
296 : "=&r"(val), "=&r"(status), "+m"(*v)
297 : "r"(v)
298 : "cc");
299 } while (__builtin_expect(status != 0, 0));
300
301 return val;
302}

◆ LOS_AtomicRead()

STATIC INLINE INT32 LOS_AtomicRead ( const Atomic v)

Atomic read. | 读取32bit原子数据

Description:
This API is used to implement the atomic read and return the result value of the read.
注意
  • The pointer v must not be NULL.
参数
v[IN] The reading pointer.
返回值
INT32The result value of the read.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h123 行定义.

124{
125 return *(volatile INT32 *)v; //读取内存数据
126}
这是这个函数的调用关系图:

◆ LOS_AtomicSet()

STATIC INLINE VOID LOS_AtomicSet ( Atomic v,
INT32  setVal 
)

Atomic setting.

Description:
This API is used to implement the atomic setting operation.
注意
  • The pointer v must not be NULL.
参数
v[IN] The variable pointer to be setting.
setVal[IN] The value to be setting.
返回值
none.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h147 行定义.

148{
149 *(volatile INT32 *)v = setVal;
150}
这是这个函数的调用关系图:

◆ LOS_AtomicSub()

STATIC INLINE INT32 LOS_AtomicSub ( Atomic v,
INT32  subVal 
)

Atomic subtraction.

Description:
This API is used to implement the atomic subtraction and return the result value of the minuend.
注意
  • The pointer v must not be NULL.
  • If the subtraction result is not in the range of representable values for 32-bit signed integer, an int integer overflow may occur to the return value
参数
v[IN] The minuend pointer.
subVal[IN] The subtrahend.
返回值
INT32The result value of the minuend.
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h217 行定义.

218{
219 INT32 val;
220 UINT32 status;
221
222 do {
223 __asm__ __volatile__("ldrex %1, [%2]\n"
224 "sub %1, %1, %3\n"
225 "strex %0, %1, [%2]"
226 : "=&r"(status), "=&r"(val)
227 : "r"(v), "r"(subVal)
228 : "cc");
229 } while (__builtin_expect(status != 0, 0));
230
231 return val;
232}
这是这个函数的调用关系图:

◆ LOS_AtomicXchg16bits()

STATIC INLINE INT32 LOS_AtomicXchg16bits ( volatile INT16 v,
INT32  val 
)

Atomic exchange for 16-bit variable. | 交换16位原子数据,原内存中的值以返回值的方式返回

Description:
This API is used to implement the atomic exchange for 16-bit variable and return the previous value of the atomic variable.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The exchange value.
返回值
INT32The previous value of the atomic variable
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h713 行定义.

714{
715 INT32 prevVal;
716 UINT32 status;
717
718 do {
719 __asm__ __volatile__("ldrexh %0, [%3]\n"
720 "strexh %1, %4, [%3]"
721 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
722 : "r"(v), "r"(val)
723 : "cc");
724 } while (__builtin_expect(status != 0, 0));
725
726 return prevVal;
727}

◆ LOS_AtomicXchg32bits()

STATIC INLINE INT32 LOS_AtomicXchg32bits ( Atomic v,
INT32  val 
)

Atomic exchange for 32-bit variable. | 交换32位原子数据,原内存中的值以返回值的方式返回

Description:
This API is used to implement the atomic exchange for 32-bit variable and return the previous value of the atomic variable.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The exchange value.
返回值
INT32The previous value of the atomic variable
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h747 行定义.

748{
749 INT32 prevVal;
750 UINT32 status;
751
752 do {
753 __asm__ __volatile__("ldrex %0, [%3]\n"
754 "strex %1, %4, [%3]"
755 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
756 : "r"(v), "r"(val)
757 : "cc");
758 } while (__builtin_expect(status != 0, 0));
759
760 return prevVal;
761}

◆ LOS_AtomicXchg64bits()

STATIC INLINE INT64 LOS_AtomicXchg64bits ( Atomic64 v,
INT64  val 
)

Atomic exchange for 64-bit variable. | 交换64位原子数据,原内存中的值以返回值的方式返回

Description:
This API is used to implement the atomic exchange for 64-bit variable and return the previous value of the atomic variable.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The exchange value.
返回值
INT64The previous value of the atomic variable
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h781 行定义.

782{
783 INT64 prevVal;
784 UINT32 status;
785
786 do {
787 __asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
788 "strexd %1, %4, %H4, [%3]"
789 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
790 : "r"(v), "r"(val)
791 : "cc");
792 } while (__builtin_expect(status != 0, 0));
793
794 return prevVal;
795}

◆ LOS_AtomicXchgByte()

STATIC INLINE INT32 LOS_AtomicXchgByte ( volatile INT8 v,
INT32  val 
)

Atomic exchange for 8-bit variable. | 交换8位原子数据,原内存中的值以返回值的方式返回

Description:
This API is used to implement the atomic exchange for 8-bit variable and return the previous value of the atomic variable.
注意
pointer v must not be NULL.
参数
v[IN] The variable pointer.
val[IN] The exchange value.
返回值
INT32The previous value of the atomic variable
Dependency:
  • los_atomic.h: the header file that contains the API declaration.
参见

在文件 los_atomic.h679 行定义.

680{
681 INT32 prevVal;
682 UINT32 status;
683
684 do {
685 __asm__ __volatile__("ldrexb %0, [%3]\n"
686 "strexb %1, %4, [%3]"
687 : "=&r"(prevVal), "=&r"(status), "+m"(*v)
688 : "r"(v), "r"(val)
689 : "cc");
690 } while (__builtin_expect(status != 0, 0));
691
692 return prevVal;
693}