mirror of
https://gitee.com/openharmony/resourceschedule_ffrt
synced 2024-11-30 08:40:40 +00:00
新增ffrt_get_cur_cached_task_id接口
Signed-off-by: chendi <cdrom000@126,com>
This commit is contained in:
parent
f193b551df
commit
38991d3315
@ -113,4 +113,12 @@ FFRT_C_API bool ffrt_task_attr_get_local(ffrt_task_attr_t* attr);
|
||||
* @version 1.0
|
||||
*/
|
||||
FFRT_C_API pthread_t ffrt_task_get_tid(void* task_handle);
|
||||
|
||||
/**
|
||||
* @brief Obtains the task id cached by the current thread.
|
||||
*
|
||||
* @return Returns the task id.
|
||||
* @version 1.0
|
||||
*/
|
||||
FFRT_C_API uint64_t ffrt_get_cur_cached_task_id();
|
||||
#endif
|
@ -636,6 +636,17 @@ pthread_t ffrt_task_get_tid(void* task_handle)
|
||||
auto task = reinterpret_cast<ffrt::CPUEUTask*>(task_handle);
|
||||
return task->runningTid.load();
|
||||
}
|
||||
|
||||
API_ATTRIBUTE((visibility("default")))
|
||||
uint64_t ffrt_get_cur_cached_task_id()
|
||||
{
|
||||
uint64_t gid = ffrt_this_task_get_id();
|
||||
if (gid == 0) {
|
||||
return ffrt::ExecuteCtx::Cur()->lastGid_;
|
||||
}
|
||||
|
||||
return gid;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -115,6 +115,7 @@ void CPUWorker::RunTask(ffrt_executor_task_t* curtask, CPUWorker* worker)
|
||||
case ffrt_normal_task:
|
||||
case ffrt_queue_task: {
|
||||
ctx->task = task;
|
||||
ctx->lastGid_ = task->gid;
|
||||
Run(task);
|
||||
ctx->task = nullptr;
|
||||
break;
|
||||
|
@ -91,6 +91,7 @@ struct ExecuteCtx {
|
||||
QoS qos;
|
||||
CPUEUTask* task; // 当前正在执行的Task
|
||||
WaitUntilEntry wn;
|
||||
uint64_t lastGid_ = 0;
|
||||
|
||||
inline bool PushTaskToPriorityStack(ffrt_executor_task_t* task)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "dfx/log/ffrt_log_api.h"
|
||||
#include "dfx/bbox/bbox.h"
|
||||
#include "tm/cpu_task.h"
|
||||
#include "tm/scpu_task.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
@ -96,4 +97,22 @@ HWTEST_F(CoreTest, ffrt_submit_wait_success_01, TestSize.Level1)
|
||||
ffrt_task_attr_destroy(attr);
|
||||
free(attr);
|
||||
attr = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* 测试用例名称:ffrt_get_cur_cached_task_id_test
|
||||
* 测试用例描述:测试ffrt_get_cur_cached_task_id接口
|
||||
* 预置条件 :设置ExecuteCtx::Cur->lastGid_为自定义值
|
||||
* 操作步骤 :调用ffrt_get_cur_cached_task_id接口
|
||||
* 预期结果 :ffrt_get_cur_cached_task_id返回值与自定义值相同
|
||||
*/
|
||||
HWTEST_F(CoreTest, ffrt_get_cur_cached_task_id_test, TestSize.Level1)
|
||||
{
|
||||
auto ctx = ffrt::ExecuteCtx::Cur();
|
||||
ctx->lastGid_ = 15;
|
||||
EXPECT_EQ(ffrt_get_cur_cached_task_id(), 15);
|
||||
|
||||
ffrt::CPUEUTask* task = new ffrt::SCPUEUTask(nullptr, nullptr, 20, ffrt::QoS(2));
|
||||
ctx->task = task;
|
||||
EXPECT_EQ(ffrt_get_cur_cached_task_id(), 1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user