struct return type version
This commit is contained in:
parent
a57c5c5425
commit
797fe27efe
@ -561,8 +561,9 @@ AllreduceBase::TryBroadcast(void *sendrecvbuf_, size_t total_size, int root) {
|
|||||||
} else {
|
} else {
|
||||||
// read from in link
|
// read from in link
|
||||||
if (in_link >= 0 && selecter.CheckRead(links[in_link].sock)) {
|
if (in_link >= 0 && selecter.CheckRead(links[in_link].sock)) {
|
||||||
if (!links[in_link].ReadToArray(sendrecvbuf_, total_size)) {
|
ReturnType ret = links[in_link].ReadToArray(sendrecvbuf_, total_size);
|
||||||
return kSockError;
|
if (ret != kSuccess) {
|
||||||
|
return ReportError(&links[in_link], ret);
|
||||||
}
|
}
|
||||||
size_in = links[in_link].size_read;
|
size_in = links[in_link].size_read;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -198,7 +198,7 @@ class AllreduceBase : public IEngine {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*! \brief enumeration of possible returning results from Try functions */
|
/*! \brief enumeration of possible returning results from Try functions */
|
||||||
enum ReturnType {
|
enum ReturnTypeEnum {
|
||||||
/*! \brief execution is successful */
|
/*! \brief execution is successful */
|
||||||
kSuccess,
|
kSuccess,
|
||||||
/*! \brief a link was reset by peer */
|
/*! \brief a link was reset by peer */
|
||||||
@ -213,6 +213,20 @@ class AllreduceBase : public IEngine {
|
|||||||
*/
|
*/
|
||||||
kGetExcept
|
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 */
|
/*! \brief translate errno to return type */
|
||||||
inline static ReturnType Errno2Return(int errsv) {
|
inline static ReturnType Errno2Return(int errsv) {
|
||||||
if (errsv == EAGAIN || errsv == EWOULDBLOCK) return kSuccess;
|
if (errsv == EAGAIN || errsv == EWOULDBLOCK) return kSuccess;
|
||||||
|
|||||||
@ -432,7 +432,7 @@ bool AllreduceRobust::CheckAndRecover(ReturnType err_type) {
|
|||||||
// this was old way
|
// this was old way
|
||||||
// TryResetLinks still causes possible errors, so not use this one
|
// TryResetLinks still causes possible errors, so not use this one
|
||||||
while (err_type != kSuccess) {
|
while (err_type != kSuccess) {
|
||||||
switch (err_type) {
|
switch (err_type.value) {
|
||||||
case kGetExcept: err_type = TryResetLinks(); break;
|
case kGetExcept: err_type = TryResetLinks(); break;
|
||||||
case kSockError: {
|
case kSockError: {
|
||||||
TryResetLinks();
|
TryResetLinks();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user