Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/GraphCtrl/GraphElement/GAdapter/GSingleton/GSingleton.inl
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ template <typename T>
CStatus GSingleton<T>::init() {
CGRAPH_FUNCTION_BEGIN
/* 确保仅 GSingletonNode 类型内容,init一次 */
if (s_is_init_) {
if (s_is_init_.load(std::memory_order_acquire)) {
CGRAPH_FUNCTION_END
}

/* 因为采取的是饥汉模式,不需要判断ptr是否为空了 */
auto element = dynamic_cast<T *>(s_singleton_.get());
status = element->init();
if (status.isOK()) {
s_is_init_ = true;
s_is_init_.store(true, std::memory_order_release);
}

CGRAPH_FUNCTION_END
Expand All @@ -59,14 +59,14 @@ CStatus GSingleton<T>::run() {
template <typename T>
CStatus GSingleton<T>::destroy() {
CGRAPH_FUNCTION_BEGIN
if (!s_is_init_) {
if (!s_is_init_.load(std::memory_order_acquire)) {
CGRAPH_FUNCTION_END
}

auto element = dynamic_cast<T *>(s_singleton_.get());
status = element->destroy();
if (status.isOK()) {
s_is_init_ = false;
s_is_init_.store(false, std::memory_order_release);
}

CGRAPH_FUNCTION_END
Expand Down
4 changes: 2 additions & 2 deletions src/GraphCtrl/GraphElement/GElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ GElement::~GElement() {


CVoid GElement::refresh() {
this->done_ = false;
this->left_depend_.store(dependence_.size(), std::memory_order_release);
this->done_.store(false, std::memory_order_relaxed);
this->left_depend_.store(dependence_.size(), std::memory_order_relaxed);
}


Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/Lock/USpinLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class USpinLock : public UThreadObject {
* @return
*/
CBool tryLock() {
return !flag_.test_and_set();
return !flag_.test_and_set(std::memory_order_acquire);
}

private:
Expand Down
6 changes: 3 additions & 3 deletions src/UtilsCtrl/ThreadPool/Thread/UThreadBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UThreadBase : public UThreadObject {
explicit UThreadBase() {
done_ = true;
is_init_ = false;
is_running_ = false;
is_running_.store(false, std::memory_order_relaxed);
pool_task_queue_ = nullptr;
pool_priority_task_queue_ = nullptr;
config_ = nullptr;
Expand Down Expand Up @@ -113,7 +113,7 @@ class UThreadBase : public UThreadObject {
thread_.join(); // 等待线程结束
}
is_init_ = false;
is_running_ = false;
is_running_.store(false, std::memory_order_relaxed);
total_task_num_ = 0;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ class UThreadBase : public UThreadObject {
*/
CVoid loopProcess() {
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(config_)
is_running_ = true;
is_running_.store(true, std::memory_order_relaxed);
if (config_->batch_task_enable_) {
while (done_) {
processTasks(); // 批量任务获取执行接口
Expand Down
8 changes: 4 additions & 4 deletions src/UtilsCtrl/Timer/UTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UTimer : public UtilsObject {
*/
template<typename TTask, typename TMod>
CVoid start(CMSec interval, const TTask& task, const TMod& modify) {
if (!is_stop_.exchange(false)) {
if (!is_stop_.exchange(false, std::memory_order_relaxed)) {
return; // 如果正在执行中,则无法继续执行
}

Expand All @@ -43,10 +43,10 @@ class UTimer : public UtilsObject {
* std::launch::deferred:延迟加载方式创建线程。调用async时不创建线程,直到调用了future的get或者wait时才创建线程。
*/
future_ = std::async(std::launch::async, [this, task, modify]() {
while (!is_stop_) {
while (!is_stop_.load(std::memory_order_relaxed)) {
CGRAPH_UNIQUE_LOCK lk(mutex_);
auto result = cv_.wait_for(lk, std::chrono::milliseconds(left_interval_));
if (std::cv_status::timeout == result && !is_stop_) {
if (std::cv_status::timeout == result && !is_stop_.load(std::memory_order_relaxed)) {
CMSec start = CGRAPH_GET_CURRENT_MS();
task();
CMSec ms = modify();
Expand Down Expand Up @@ -75,7 +75,7 @@ class UTimer : public UtilsObject {
* 关闭定时器
*/
CVoid stop() {
if (is_stop_.exchange(true)) {
if (is_stop_.exchange(true, std::memory_order_relaxed)) {
return;
}

Expand Down
Loading