31 mSchedulerRunning(false), mSchedulerThread(), mExMutex(),
32 mExLock(mExMutex, std::defer_lock), mNextTaskId(AAMP_SCHEDULER_ID_DEFAULT),
33 mCurrentTaskId(AAMP_TASK_ID_INVALID), mLockOut(false),
55 std::lock_guard<std::mutex>lock(
mQMutex);
58 AAMPLOG_WARN(
"Started Async Worker Thread");
66 int id = AAMP_TASK_ID_INVALID;
73 std::lock_guard<std::mutex>lock(
mQMutex);
89 AAMPLOG_INFO(
"Warning: Attempting to schedule a task when scheduler is locked out, skipping operation %s!!", obj.mTaskName.c_str());
94 AAMPLOG_ERR(
"Attempting to schedule a task when scheduler is not running, undefined behavior, task ignored:%s",obj.mTaskName.c_str());
104 std::unique_lock<std::mutex>queueLock(
mQMutex);
119 std::lock_guard<std::mutex>executionLock(
mExMutex);
127 if (obj.mId != AAMP_TASK_ID_INVALID)
130 AAMPLOG_INFO(
"Found entry in function queue!!, task:%s. State:%d",obj.mTaskName.c_str(),
mState);
136 AAMPLOG_WARN(
"SchedulerTask Execution:%s",obj.mTaskName.c_str());
138 obj.mTask(obj.mData);
145 AAMPLOG_ERR(
"Scheduler found a task with invalid ID, skip task!");
150 AAMPLOG_INFO(
"Exited Async Worker Thread");
158 std::lock_guard<std::mutex>lock(
mQMutex);
161 AAMPLOG_WARN(
"The scheduler is active. An active task may continue to execute after this function exits. Call SuspendScheduler() prior to this function to prevent this.");
165 AAMPLOG_WARN(
"Clearing up %zu entries from mFuncQueue",
mTaskQueue.size());
175 AAMPLOG_WARN(
"Stopping Async Worker Thread");
201 std::lock_guard<std::mutex>lock(
mQMutex);
211 std::lock_guard<std::mutex>lock(
mQMutex);
221 std::lock_guard<std::mutex>lock(
mQMutex);
247 std::lock_guard<std::mutex>lock(
mQMutex);
259 #ifdef __UNIT_TESTING__
262 void printTask(
const char *str)
264 AAMPLOG_WARN(
"Inside task function :%s\n",str);
265 int seconds = rand() % 10 + 1;
274 printTask(str.c_str());
275 }, (
void *)
nullptr, __FUNCTION__));
280 void task1(
void *inst) {
281 std::string input=
"Task1";
283 for(
int i=0;i<10;i++)
287 printTask(input.c_str());
288 }, (
void *)
nullptr, __FUNCTION__));
290 int state = rand() % 13 + 1;
292 AAMPLOG_WARN(
"setting state:%d",state);
296 void task2(
void *inst) {
297 std::string input=
"Task2";
301 printTask(input.c_str());
302 }, (
void *)
nullptr, __FUNCTION__));
308 AAMPLOG_WARN(
"Testing the Player Scheduler Class\n");
345 std::thread t1(task1,(
void *)&mScheduler);
346 std::thread t2(task2,(
void *)&mScheduler);