6.1.1 android的原子操作函式
1.原子變數的加法操作
int32_t android_atomic_add(int32_t value, volatile int32_t* addr);原子變數的減法操作可以通過傳遞負值給加法操作函式來完成。
2.原子變數的自增和自減操作
int32_t android_atomic_inc(volatile int32_t* addr);3.原子變數的與操作int32_t android_atomic_dec(volatile int32_t* addr);
int32_t android_atomic_and(int32_t value, volatile int32_t* addr);4.原子變數的或操作
int32_t android_atomic_or(int32_t value, volatile int32_t* addr);5.原子變數的設定
void android_atomic_acquire_store(int32_t value, volatile int32_t* addr);6.原子變數的讀取void android_atomic_release_store(int32_t value, volatile int32_t* addr);
int32_t android_atomic_acquire_load(volatile const int32_t* addr);注意 上面這兩個函式從功能上看是一樣的,區別只是記憶體屏障位於讀取前還是讀取後,下面的兩組函式也類似。int32_t android_atomic_release_load(volatile const int32_t* addr);
7.原子變數的比較並交換
int android_atomic_acquire_cas(int32_t oldvalue, int32_t newvalue, volatile int32_t* addr);8.還有兩個原子變數的巨集定義int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue, volatile int32_t* addr);
#define android_atomic_write android_atomic_release_store#define android_atomic_cmpxchg android_atomic_release_cas
Android的原子操作函式
1 原子變數的加法操作 int32 t android atomic add int32 t value,volatile int32 t addr 原子變數的減法操作可以通過傳遞負值給加法操作函式來完成。2 原子變數的自增和自減操作 int32 t android atomic inc volat...
gcc提供的原子操作函式
gcc從4.1.2提供了 sync 系列的built in函式,用於提供加減和邏輯運算的原子操作。其宣告如下 type sync fetch and add type ptr,type value,type sync fetch and sub type ptr,type value,type sy...
原子性,原子操作
舉個例子 a想要從自己的帳戶中轉1000塊錢到b的帳戶裡。那個從a開始轉帳,到轉帳結束的這乙個過程,稱之為乙個事務。在這個事務裡,要做如下操作 從a的帳戶中減去1000塊錢。如果a的帳戶原來有3000塊錢,現在就變成2000塊錢了。在b的帳戶裡加1000塊錢。如果b的帳戶如果原來有2000塊錢,現在...