Thread safe initialization of the channels

This commit is contained in:
Alexey Rybalchenko
2015-06-18 15:10:01 +02:00
parent 295d9bba57
commit d6a413534a
13 changed files with 171 additions and 50 deletions

View File

@@ -17,6 +17,8 @@
#include <string>
#include <boost/thread/mutex.hpp>
#include "FairMQSocket.h"
class FairMQChannel
@@ -28,14 +30,35 @@ class FairMQChannel
FairMQChannel(const std::string& type, const std::string& method, const std::string& address);
virtual ~FairMQChannel();
std::string GetType();
std::string GetMethod();
std::string GetAddress();
int GetSndBufSize();
int GetRcvBufSize();
int GetRateLogging();
void UpdateType(const std::string& type);
void UpdateMethod(const std::string& method);
void UpdateAddress(const std::string& address);
void UpdateSndBufSize(const int sndBufSize);
void UpdateRcvBufSize(const int rcvBufSize);
void UpdateRateLogging(const int rateLogging);
bool IsValid();
bool ValidateChannel();
void ResetChannel();
FairMQSocket* fSocket;
// Wrappers for the socket methods to simplify the usage of channels
int Send(FairMQMessage* msg, const std::string& flag = "");
int Send(FairMQMessage* msg, const int flags);
int Receive(FairMQMessage* msg, const std::string& flag = "");
int Receive(FairMQMessage* msg, const int flags);
private:
std::string fType;
std::string fMethod;
std::string fAddress;
@@ -43,10 +66,14 @@ class FairMQChannel
int fRcvBufSize;
int fRateLogging;
FairMQSocket* fSocket;
private:
std::string fChannelName;
bool fIsValid;
// use static mutex to make the class easily copyable
// implication: same mutex is used for all instances of the class
// this does not hurt much, because mutex is used only during initialization with very low contention
// possible TODO: improve this
static boost::mutex channelMutex;
};
#endif /* FAIRMQCHANNEL_H_ */