Added NamedLockPattern to BlockingTCPConnector and resolved some warnings and compilation/linker errors.

Reference to '__sync_add_and_fetch' and '__sync_sub_and_fetch' removed for now, since it is glibc version specific.
This commit is contained in:
miha_vitorovic
2011-01-05 09:20:51 +01:00
parent 5ec1adfacb
commit 544fc6bd73
4 changed files with 61 additions and 23 deletions

View File

@@ -14,6 +14,7 @@
#include "growingCircularBuffer.h"
#include "transportRegistry.h"
#include "introspectionRegistry.h"
#include "namedLockPattern.h"
/* pvData */
#include <byteBuffer.h>
@@ -473,6 +474,20 @@ namespace epics {
void responsiveTransport();
};
/**
* comparator for osiSockAddr*
*/
struct comp_osiSockAddrPtr
{
bool operator()(osiSockAddr const *a, osiSockAddr const *b)
{
if (a->sa.sa_family < b->sa.sa_family) return true;
if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr < b->ia.sin_addr.s_addr )) return true;
if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr == b->ia.sin_addr.s_addr ) && ( a->ia.sin_port < b->ia.sin_port )) return true;
return false;
}
};
/**
* Channel Access TCP connector.
* @author <a href="mailto:matej.sekoranjaATcosylab.com">Matej Sekoranja</a>
@@ -500,9 +515,9 @@ namespace epics {
Context* _context;
/**
* Context instance.
* named lock
*/
//NamedLockPattern* _namedLocker;
NamedLockPattern<const osiSockAddr*, comp_osiSockAddrPtr>* _namedLocker;
/**
* Receive buffer size.

View File

@@ -7,6 +7,7 @@
#include "blockingTCP.h"
#include "remote.h"
#include "namedLockPattern.h"
#include <epicsThread.h>
#include <osiSock.h>
@@ -21,14 +22,14 @@ namespace epics {
BlockingTCPConnector::BlockingTCPConnector(Context* context,
int receiveBufferSize, float beaconInterval) :
_context(context), _receiveBufferSize(receiveBufferSize),
_beaconInterval(beaconInterval)
//TODO , _namedLocker(new NamedLockPattern())
{
_context(context), _namedLocker(new NamedLockPattern<
const osiSockAddr*, comp_osiSockAddrPtr> ()),
_receiveBufferSize(receiveBufferSize), _beaconInterval(
beaconInterval) {
}
BlockingTCPConnector::~BlockingTCPConnector() {
// TODO delete _namedLocker;
delete _namedLocker;
}
SOCKET BlockingTCPConnector::tryConnect(osiSockAddr* address, int tries) {
@@ -86,10 +87,8 @@ namespace epics {
if(transport->acquire(client)) return transport;
}
bool lockAcquired = true;
// TODO comment out
//bool lockAcquired = _namedLocker->acquireSynchronizationObject(
// address, LOCK_TIMEOUT);
bool lockAcquired = _namedLocker->acquireSynchronizationObject(
address, LOCK_TIMEOUT);
if(lockAcquired) {
try {
// ... transport created during waiting in lock
@@ -157,11 +156,10 @@ namespace epics {
} catch(...) {
// close socket, if open
if(socket!=INVALID_SOCKET) epicsSocketDestroy(socket);
// TODO namedLocker.releaseSynchronizationObject(address);
_namedLocker->releaseSynchronizationObject(address);
throw;
}
_namedLocker->releaseSynchronizationObject(address);
}
else {
ostringstream temp;

View File

@@ -46,6 +46,9 @@ namespace epics {
*/
class TransportSendControl : public epics::pvData::SerializableControl {
public:
virtual ~TransportSendControl() {
}
virtual void startMessage(int8 command, int ensureCapacity) =0;
virtual void endMessage() =0;
@@ -61,6 +64,8 @@ namespace epics {
*/
class TransportSender {
public:
virtual ~TransportSender() {}
/**
* Called by transport.
* By this call transport gives callee ownership over the buffer.
@@ -69,8 +74,7 @@ namespace epics {
* of this method.
* NOTE: these limitations allows efficient implementation.
*/
virtual void
send(epics::pvData::ByteBuffer* buffer,
virtual void send(epics::pvData::ByteBuffer* buffer,
TransportSendControl* control) =0;
virtual void lock() =0;
@@ -213,6 +217,8 @@ namespace epics {
*/
class ResponseHandler {
public:
virtual ~ResponseHandler() {}
/**
* Handle response.
* @param[in] responseFrom remote address of the responder, <code>null</code> if unknown.
@@ -224,9 +230,10 @@ namespace epics {
* Code must not manipulate buffer.
*/
virtual void
handleResponse(osiSockAddr* responseFrom, Transport* transport,
int8 version, int8 command, int payloadSize,
epics::pvData::ByteBuffer* payloadBuffer) =0;
handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command,
int payloadSize,
epics::pvData::ByteBuffer* payloadBuffer) =0;
};
/**
@@ -341,6 +348,8 @@ namespace epics {
*/
class TransportClient {
public:
virtual ~TransportClient();
/**
* Notification of unresponsive transport (e.g. no heartbeat detected) .
*/
@@ -372,6 +381,9 @@ namespace epics {
*/
class Connector {
public:
virtual ~Connector() {
}
/**
* Connect.
* @param[in] client client requesting connection (transport).
@@ -390,6 +402,8 @@ namespace epics {
class Context {
public:
virtual ~Context() {
}
/**
* Get timer.
* @return timer.
@@ -410,6 +424,8 @@ namespace epics {
*/
class ReferenceCountingTransport {
public:
virtual ~ReferenceCountingTransport() {}
/**
* Acquires transport.
* @param client client (channel) acquiring the transport
@@ -426,6 +442,8 @@ namespace epics {
class ServerChannel {
public:
virtual ~ServerChannel() {
}
/**
* Get channel SID.
* @return channel SID.
@@ -446,6 +464,9 @@ namespace epics {
*/
class ChannelHostingTransport {
public:
virtual ~ChannelHostingTransport() {
}
/**
* Get security token.
* @return security token, can be <code>null</code>.

View File

@@ -66,15 +66,19 @@ void ReferenceCountingLock::release()
int ReferenceCountingLock::increment()
{
//TODO does it really has to be atomic?
//return ++_references;
return __sync_add_and_fetch(&_references,1);
return ++_references;
// commented because linking depends on specific version of glibc library
// on i386 target
//return __sync_add_and_fetch(&_references,1);
}
int ReferenceCountingLock::decrement()
{
//TODO does it really has to be atomic?
//return --_references;
return __sync_sub_and_fetch(&_references,1);
return --_references;
// commented because linking depends on specific version of glibc library
// on i386 target
//return __sync_sub_and_fetch(&_references,1);
}
}}