国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

atomic integer

2019-11-08 02:04:34
字體:
來源:轉載
供稿:網友
/*************************************************************************    > File Name: AtomicInteger.h    > Author: wangzhicheng    > Mail: 2363702560@QQ.com    > Created Time: 2017-02-20    > statement: PRovide atomic integer and Operation for multithread ************************************************************************/#ifndef _ATOMIC_INTEGER_H_#define _ATMOIC_INTEGER_H_#include <stdio.h>#include <stdint.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <pthread.h>#include <iostream>using namespace std;/** *@brief provide atomic integer and operation for multithread */template<class T>class AtomicInteger {	private:		volatile T value;	// prevent g++ to optimize the value	public:		AtomicInteger():value(0) {		}		/* 		 *@brief get the original value  		 * */		T GetValue() {			// if value == 0 then value = 0 and return the original value			return __sync_val_compare_and_swap(&value, 0, 0);		}		/* 		 *@brief suffix ++ such as a++ 		* */		T operator ++ (int) {			return __sync_fetch_and_add(&value, 1);		}		/* 		 *@brief prefix ++ such as ++a 		* */		T operator ++ () {			return __sync_add_and_fetch(&value, 1);		}		/* 		 *@brief 加某個數 		* */		T operator + (int num) {			return __sync_add_and_fetch(&value, num);		}		/* 		 *@brief 減某個數 		* */		T operator - (int num) {			return __sync_add_and_fetch(&value, -num);		}		/* 		 *@brief suffix -- such as a-- 		* */		T operator -- (int) {			return __sync_fetch_and_add(&value, -1);		}		/* 		 *@brief prefix -- such as --a 		* */		T operator -- () {			return __sync_add_and_fetch(&value, -1);		}		/* 		 *@brief add operation 		* */		T operator + (const T &other) {			return __sync_add_and_fetch(&value, other);		}		/* 		 *@brief = operation 		* */		T operator = (const T &newValue) {			return __sync_lock_test_and_set(&value, newValue);		}		};//nstypedef AtomicInteger<uint64_t>AtomicInt64;typedef AtomicInteger<uint32_t>AtomicInt32;#endif
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德钦县| 武邑县| 华宁县| 华亭县| 平湖市| 兴和县| 海城市| 集安市| 股票| 电白县| 平安县| 巩义市| 嘉荫县| 会泽县| 洪洞县| 海伦市| 柳江县| 怀集县| 扶风县| 崇文区| 曲周县| 翁牛特旗| 杨浦区| 林甸县| 洱源县| 正阳县| 安丘市| 许昌市| 通河县| 隆林| 普兰县| 南岸区| 合阳县| 财经| 永新县| 闽侯县| 香格里拉县| 新兴县| 大余县| 象山县| 方正县|