From 7812651bdcb9923d46a7e711603447c785d8ff47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AE=87=E6=89=AC?= Date: Thu, 9 May 2024 01:09:23 +0800 Subject: [PATCH] modify barrier for x86 --- include/devices/cpu/alivethreadpool.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/devices/cpu/alivethreadpool.h b/include/devices/cpu/alivethreadpool.h index de6560d6..224f44ec 100644 --- a/include/devices/cpu/alivethreadpool.h +++ b/include/devices/cpu/alivethreadpool.h @@ -11,6 +11,13 @@ #include namespace fastllm { + static void barrier() { +#ifdef __aarch64__ + asm volatile("dmb ish"); +#else + __asm__ __volatile__("": : :"memory"); +#endif + } struct MultiThreadBaseOp { virtual void Run() = 0; }; @@ -38,11 +45,11 @@ namespace fastllm { void operator()() { auto lastRunTime = std::chrono::system_clock::now(); while (true) { - asm volatile("dmb ish"); + barrier(); if (task->signal == 1) { task->op->Run(); task->signal = 0; - asm volatile("dmb ish"); + barrier(); lastRunTime = std::chrono::system_clock::now(); } @@ -56,9 +63,9 @@ namespace fastllm { void PushOp(MultiThreadBaseOp *op) { this->task->op = op; - asm volatile("dmb ish"); + barrier(); this->task->signal = 1; - asm volatile("dmb ish"); + barrier(); } void Wait() {