struct return type version

This commit is contained in:
tqchen 2015-01-14 15:43:28 -08:00
parent a57c5c5425
commit 797fe27efe
3 changed files with 19 additions and 4 deletions

View File

@ -561,8 +561,9 @@ AllreduceBase::TryBroadcast(void *sendrecvbuf_, size_t total_size, int root) {
} else {
// read from in link
if (in_link >= 0 && selecter.CheckRead(links[in_link].sock)) {
if (!links[in_link].ReadToArray(sendrecvbuf_, total_size)) {
return kSockError;
ReturnType ret = links[in_link].ReadToArray(sendrecvbuf_, total_size);
if (ret != kSuccess) {
return ReportError(&links[in_link], ret);
}
size_in = links[in_link].size_read;
}

View File

@ -198,7 +198,7 @@ class AllreduceBase : public IEngine {
protected:
/*! \brief enumeration of possible returning results from Try functions */
enum ReturnType {
enum ReturnTypeEnum {
/*! \brief execution is successful */
kSuccess,
/*! \brief a link was reset by peer */
@ -213,6 +213,20 @@ class AllreduceBase : public IEngine {
*/
kGetExcept
};
/*! \brief struct return type to avoid implicit conversion to int/bool */
struct ReturnType {
/*! \brief internal return type */
ReturnTypeEnum value;
// constructor
ReturnType() {}
ReturnType(ReturnTypeEnum value) : value(value){}
inline bool operator==(const ReturnTypeEnum &v) const {
return value == v;
}
inline bool operator!=(const ReturnTypeEnum &v) const {
return value != v;
}
};
/*! \brief translate errno to return type */
inline static ReturnType Errno2Return(int errsv) {
if (errsv == EAGAIN || errsv == EWOULDBLOCK) return kSuccess;

View File

@ -432,7 +432,7 @@ bool AllreduceRobust::CheckAndRecover(ReturnType err_type) {
// this was old way
// TryResetLinks still causes possible errors, so not use this one
while (err_type != kSuccess) {
switch (err_type) {
switch (err_type.value) {
case kGetExcept: err_type = TryResetLinks(); break;
case kSockError: {
TryResetLinks();