return aLen == bLen; // strings are equal (in length)
}
+// lifted from boost, with thanks
+class AtomicCounter
+{
+public:
+
+ explicit AtomicCounter( unsigned int v = 0) : value_( v ) {}
+
+ void operator++()
+ {
+ __sync_add_and_fetch( &value_, 1 );
+ }
+
+ unsigned int operator--()
+ {
+ return __sync_add_and_fetch( &value_, -1 );
+ }
+
+ operator unsigned int() const
+ {
+ return __sync_fetch_and_add( &value_, 0 );
+ }
+
+private:
+ AtomicCounter(AtomicCounter const &);
+ AtomicCounter &operator=(AtomicCounter const &);
+
+ mutable unsigned int value_;
+};
+
struct CIStringCompare: public binary_function<string, string, bool>
{
TCPConnection::TCPConnection(int fd, const ComboAddress& addr) : d_remote(addr), d_fd(fd)
{
- s_currentConnections++;
+ ++s_currentConnections;
(*t_tcpClientCounts)[d_remote]++;
}
unixDie("closing socket for TCPConnection");
if(t_tcpClientCounts->count(d_remote) && !(*t_tcpClientCounts)[d_remote]--)
t_tcpClientCounts->erase(d_remote);
- s_currentConnections--;
+ --s_currentConnections;
}
-volatile unsigned int TCPConnection::s_currentConnections;
+AtomicCounter TCPConnection::s_currentConnections;
void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var);
void updateRcodeStats(int res)
static unsigned int getCurrentConnections() { return s_currentConnections; }
private:
const int d_fd;
- static volatile unsigned int s_currentConnections; //!< total number of current TCP connections
+ static AtomicCounter s_currentConnections; //!< total number of current TCP connections
};