forked from mindspore-Ecosystem/mindspore
!13141 Mindrt Status Bug
From: @ling_qiao_min Reviewed-by: Signed-off-by:
This commit is contained in:
commit
8eb3e396e5
|
@ -62,7 +62,7 @@ class Collected {
|
|||
void Discarded() {
|
||||
auto iter = futures.begin();
|
||||
for (; iter != futures.end(); ++iter) {
|
||||
iter->SetFailed(Status::KERROR);
|
||||
iter->SetFailed(MindrtStatus::KERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ class Collected {
|
|||
template <typename T>
|
||||
inline Future<std::list<T>> Collect(const std::list<Future<T>> &futures) {
|
||||
if (futures.empty()) {
|
||||
return std::list<T>();
|
||||
return Future(std::list<T>());
|
||||
}
|
||||
|
||||
Promise<std::list<T>> *promise = new (std::nothrow) Promise<std::list<T>>();
|
||||
|
|
|
@ -44,7 +44,7 @@ class Option;
|
|||
template <typename T>
|
||||
class Future : public FutureBase {
|
||||
public:
|
||||
typedef Status WaitForStatus;
|
||||
typedef MindrtStatus WaitForStatus;
|
||||
typedef typename FutureData<T>::CompleteCallback CompleteCallback;
|
||||
typedef typename FutureData<T>::AbandonedCallback AbandonedCallback;
|
||||
typedef FutureData<T> Data;
|
||||
|
@ -57,22 +57,24 @@ class Future : public FutureBase {
|
|||
|
||||
Future(Future<T> &&f) : data(std::move(f.data)) {}
|
||||
|
||||
Future(const T &t) : data(new (std::nothrow) Data()) {
|
||||
explicit Future(const T &t) : data(new (std::nothrow) Data()) {
|
||||
BUS_OOM_EXIT(data);
|
||||
SetValue(std::move(t));
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
Future(const V &value) : data(new (std::nothrow) Data()) {
|
||||
explicit Future(const V &value) : data(new (std::nothrow) Data()) {
|
||||
BUS_OOM_EXIT(data);
|
||||
SetValue(value);
|
||||
}
|
||||
|
||||
Future(const Status &s) : data(new (std::nothrow) Data()) {
|
||||
explicit Future(const MindrtStatus &s) : data(new (std::nothrow) Data()) {
|
||||
BUS_OOM_EXIT(data);
|
||||
SetFailed(s.GetCode());
|
||||
}
|
||||
|
||||
explicit Future(const std::shared_ptr<Data> &t) : data(t) {}
|
||||
|
||||
~Future() override {}
|
||||
|
||||
Future<T> &operator=(const Future<T> &f) {
|
||||
|
@ -123,10 +125,10 @@ class Future : public FutureBase {
|
|||
|
||||
bool IsError() const { return data->status.IsError(); }
|
||||
|
||||
Status GetStatus() const { return data->status; }
|
||||
MindrtStatus GetStatus() const { return data->status; }
|
||||
|
||||
int32_t GetErrorCode() const {
|
||||
const Status &status_ = data->status;
|
||||
const MindrtStatus &status_ = data->status;
|
||||
if (status_.IsError()) {
|
||||
return status_.GetCode();
|
||||
}
|
||||
|
@ -211,7 +213,7 @@ class Future : public FutureBase {
|
|||
}
|
||||
|
||||
void SetFailed(int32_t errCode) const {
|
||||
BUS_ASSERT(errCode != Status::KINIT && errCode != Status::KOK);
|
||||
BUS_ASSERT(errCode != MindrtStatus::KINIT && errCode != MindrtStatus::KOK);
|
||||
|
||||
bool call = false;
|
||||
|
||||
|
@ -382,8 +384,6 @@ class Future : public FutureBase {
|
|||
friend class Future;
|
||||
friend class Promise<T>;
|
||||
|
||||
Future(const std::shared_ptr<Data> &t) : data(t) {}
|
||||
|
||||
std::shared_ptr<Data> data;
|
||||
};
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ struct FutureData {
|
|||
typedef std::function<void(const Future<T> &)> AbandonedCallback;
|
||||
|
||||
FutureData()
|
||||
: status(Status::KINIT),
|
||||
: status(MindrtStatus::KINIT),
|
||||
associated(false),
|
||||
abandoned(false),
|
||||
gotten(false),
|
||||
|
@ -83,7 +83,7 @@ struct FutureData {
|
|||
|
||||
// status of future
|
||||
SpinLock lock;
|
||||
Status status;
|
||||
MindrtStatus status;
|
||||
|
||||
bool associated;
|
||||
bool abandoned;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
namespace mindspore {
|
||||
|
||||
class Status {
|
||||
class MindrtStatus {
|
||||
public:
|
||||
typedef int32_t Code;
|
||||
|
||||
|
@ -28,11 +28,11 @@ class Status {
|
|||
static const Code KERROR = -1;
|
||||
|
||||
// Create a success status.
|
||||
Status(int32_t c) : code(c) {}
|
||||
explicit MindrtStatus(int32_t c) : code(c) {}
|
||||
|
||||
Status() : code(KINIT) {}
|
||||
MindrtStatus() : code(KINIT) {}
|
||||
|
||||
virtual ~Status() {}
|
||||
virtual ~MindrtStatus() {}
|
||||
|
||||
// Returns true iff the status indicates success.
|
||||
bool IsInit() const { return (code == KINIT); }
|
||||
|
@ -42,9 +42,9 @@ class Status {
|
|||
bool IsError() const { return (code != KINIT && code != KOK); }
|
||||
|
||||
// Return a success status.
|
||||
Status OK() const { return Status(KOK); }
|
||||
MindrtStatus OK() const { return MindrtStatus(KOK); }
|
||||
|
||||
Status Error() const { return Status(KERROR); }
|
||||
MindrtStatus Error() const { return MindrtStatus(KERROR); }
|
||||
|
||||
void SetError() {
|
||||
code = KERROR;
|
||||
|
|
Loading…
Reference in New Issue