GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — muduo/armlinux.diff at master · feirendada/muduo Expand file tree/ Copy patharmlinux.diffMore file actions 137 lines (130 loc) · 2.76 KB / Copy patharmlinux.diffFile metadata and controls137 lines (130 loc) · 2.76 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c8880a..af0d174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ set(CXX_FLAGS -Wpointer-arith -Wshadow -Wwrite-strings - -march=native + -march=armv4 # -MMD # -std=c++0x -rdynamic @@ -31,7 +31,7 @@ if(CMAKE_BUILD_BITS EQUAL 32) endif() string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}") -set(CMAKE_CXX_COMPILER "g++") +set(CMAKE_CXX_COMPILER "arm-g++") #set(CMAKE_CXX_COMPILER "icpc") set(CMAKE_CXX_FLAGS_DEBUG "-O0") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -finline-limit=1000 -DNDEBUG") diff --git a/muduo/base/Atomic.h b/muduo/base/Atomic.h index 3478da0..cc1dd45 100644 --- a/muduo/base/Atomic.h +++ b/muduo/base/Atomic.h @@ -8,6 +8,7 @@ #include <boost/noncopyable.hpp> #include <stdint.h> +#include <muduo/base/Mutex.h> namespace muduo { @@ -83,10 +84,88 @@ class AtomicIntegerT : boost::noncopyable private: volatile T value_; }; + +template<typename T> +class AtomicIntegerLock : boost::noncopyable +{ + public: + AtomicIntegerLock() + : value_(0) + { + } + + // uncomment if you need copying and assignment + // + // AtomicIntegerT(const AtomicIntegerT& that) + // : value_(that.get()) + // {} + // + // AtomicIntegerT& operator=(const AtomicIntegerT& that) + // { + // getAndSet(that.get()); + // return *this; + // } + + T get() + { + MutexLockGuard lock(mutex_); + return value_; + } + + T getAndAdd(T x) + { + MutexLockGuard lock(mutex_); + T old = value_; + value_ += x; + return old; + } + + T addAndGet(T x) + { + return getAndAdd(x) + x; + } + + T incrementAndGet() + { + return addAndGet(1); + } + + T decrementAndGet() + { + return addAndGet(-1); + } + + void add(T x) + { + getAndAdd(x); + } + + void increment() + { + incrementAndGet(); + } + + void decrement() + { + decrementAndGet(); + } + + T getAndSet(T newValue) + { + MutexLockGuard lock(mutex_); + T old = value_; + value_ = newValue; + return old; + } + + private: + volatile T value_; + MutexLock mutex_; +}; } typedef detail::AtomicIntegerT<int32_t> AtomicInt32; -typedef detail::AtomicIntegerT<int64_t> AtomicInt64; +typedef detail::AtomicIntegerLock<int64_t> AtomicInt64; } #endif // MUDUO_BASE_ATOMIC_H diff --git a/muduo/base/tests/CMakeLists.txt b/muduo/base/tests/CMakeLists.txt index 2c3f1c4..73d90fd 100644 --- a/muduo/base/tests/CMakeLists.txt +++ b/muduo/base/tests/CMakeLists.txt @@ -2,7 +2,7 @@ target_link_libraries(asynclogging_test muduo_base) add_executable(atomic_unittest Atomic_unittest.cc) -# target_link_libraries(atomic_unittest muduo_base) +target_link_libraries(atomic_unittest muduo_base) add_executable(blockingqueue_test BlockingQueue_test.cc) target_link_libraries(blockingqueue_test muduo_base) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |