|
|
|
@ -179,7 +179,7 @@ class Activity : public Orphanable { |
|
|
|
|
// locked
|
|
|
|
|
// - back up that assertation with a runtime check in debug builds (it's
|
|
|
|
|
// prohibitively expensive in non-debug builds)
|
|
|
|
|
static Activity* current() { return g_current_activity_; } |
|
|
|
|
static Activity* current() { return *GetCurrentActivity(); } |
|
|
|
|
|
|
|
|
|
// Produce an activity-owning Waker. The produced waker will keep the activity
|
|
|
|
|
// alive until it's awoken or dropped.
|
|
|
|
@ -196,17 +196,17 @@ class Activity : public Orphanable { |
|
|
|
|
protected: |
|
|
|
|
// Check if this activity is the current activity executing on the current
|
|
|
|
|
// thread.
|
|
|
|
|
bool is_current() const { return this == g_current_activity_; } |
|
|
|
|
bool is_current() const { return this == *GetCurrentActivity(); } |
|
|
|
|
// Check if there is an activity executing on the current thread.
|
|
|
|
|
static bool have_current() { return g_current_activity_ != nullptr; } |
|
|
|
|
static bool have_current() { return *GetCurrentActivity() != nullptr; } |
|
|
|
|
// Set the current activity at construction, clean it up at destruction.
|
|
|
|
|
class ScopedActivity { |
|
|
|
|
public: |
|
|
|
|
explicit ScopedActivity(Activity* activity) |
|
|
|
|
: prior_activity_(g_current_activity_) { |
|
|
|
|
g_current_activity_ = activity; |
|
|
|
|
: prior_activity_(*GetCurrentActivity()) { |
|
|
|
|
*GetCurrentActivity() = activity; |
|
|
|
|
} |
|
|
|
|
~ScopedActivity() { g_current_activity_ = prior_activity_; } |
|
|
|
|
~ScopedActivity() { *GetCurrentActivity() = prior_activity_; } |
|
|
|
|
ScopedActivity(const ScopedActivity&) = delete; |
|
|
|
|
ScopedActivity& operator=(const ScopedActivity&) = delete; |
|
|
|
|
|
|
|
|
@ -217,6 +217,7 @@ class Activity : public Orphanable { |
|
|
|
|
private: |
|
|
|
|
// Set during RunLoop to the Activity that's executing.
|
|
|
|
|
// Being set implies that mu_ is held.
|
|
|
|
|
static Activity** GetCurrentActivity(); |
|
|
|
|
static thread_local Activity* g_current_activity_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|