@@ -260,9 +260,7 @@ static ExecutorRef swift_task_getCurrentExecutorImpl() {
260260 auto currentTracking = ExecutorTrackingInfo::current ();
261261 auto result = (currentTracking ? currentTracking->getActiveExecutor ()
262262 : ExecutorRef::generic ());
263- #if SWIFT_TASK_PRINTF_DEBUG
264- fprintf (stderr, " [%p] getting current executor %p\n " , pthread_self (), result.getIdentity ());
265- #endif
263+ SWIFT_TASK_DEBUG_LOG (" getting current executor %p" , result.getIdentity ());
266264 return result;
267265}
268266
@@ -1158,9 +1156,7 @@ static Job *preprocessQueue(JobRef first,
11581156}
11591157
11601158void DefaultActorImpl::giveUpThread (RunningJobInfo runner) {
1161- #if SWIFT_TASK_PRINTF_DEBUG
1162- fprintf (stderr, " [%p] giving up thread for actor %p\n " , pthread_self (), this );
1163- #endif
1159+ SWIFT_TASK_DEBUG_LOG (" giving up thread for actor %p" , this );
11641160 auto oldState = CurrentState.load (std::memory_order_acquire);
11651161 assert (oldState.Flags .isAnyRunningStatus ());
11661162
@@ -1220,13 +1216,11 @@ void DefaultActorImpl::giveUpThread(RunningJobInfo runner) {
12201216 // Try again.
12211217 continue ;
12221218 }
1223-
1224- #if SWIFT_TASK_PRINTF_DEBUG
1225- # define LOG_STATE_TRANSITION fprintf (stderr, " [%p] actor %p transitioned from %zx to %zx (%s)\n " , \
1226- pthread_self (), this, oldState.Flags.getOpaqueValue(), newState.Flags.getOpaqueValue(), __FUNCTION__)
1227- #else
1228- # define LOG_STATE_TRANSITION ((void )0 )
1229- #endif
1219+
1220+ #define LOG_STATE_TRANSITION \
1221+ SWIFT_TASK_DEBUG_LOG (" actor %p transitioned from %zx to %zx (%s)\n " , this , \
1222+ oldState.Flags .getOpaqueValue (), \
1223+ newState.Flags .getOpaqueValue (), __FUNCTION__)
12301224 LOG_STATE_TRANSITION;
12311225
12321226 // The priority of the remaining work.
@@ -1478,9 +1472,7 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
14781472SWIFT_CC (swiftasync)
14791473static void processDefaultActor(DefaultActorImpl *currentActor,
14801474 RunningJobInfo runner) {
1481- #if SWIFT_TASK_PRINTF_DEBUG
1482- fprintf (stderr, " [%p] processDefaultActor %p\n " , pthread_self (), currentActor);
1483- #endif
1475+ SWIFT_TASK_DEBUG_LOG (" processDefaultActor %p" , currentActor);
14841476 DefaultActorImpl *actor = currentActor;
14851477
14861478 // If we actually have work to do, we'll need to set up tracking info.
@@ -1504,9 +1496,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
15041496 auto job = currentActor->claimNextJobOrGiveUp (threadIsRunningActor,
15051497 runner);
15061498
1507- #if SWIFT_TASK_PRINTF_DEBUG
1508- fprintf (stderr, " [%p] processDefaultActor %p claimed job %p\n " , pthread_self (), currentActor, job);
1509- #endif
1499+ SWIFT_TASK_DEBUG_LOG (" processDefaultActor %p claimed job %p" , currentActor,
1500+ job);
15101501
15111502 // If we failed to claim a job, we have nothing to do.
15121503 if (!job) {
@@ -1526,9 +1517,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
15261517 // If it's become nil, or not a default actor, we have nothing to do.
15271518 auto currentExecutor = trackingInfo.getActiveExecutor ();
15281519
1529- #if SWIFT_TASK_PRINTF_DEBUG
1530- fprintf (stderr, " [%p] processDefaultActor %p current executor now %p\n " , pthread_self (), currentActor, currentExecutor.getIdentity ());
1531- #endif
1520+ SWIFT_TASK_DEBUG_LOG (" processDefaultActor %p current executor now %p" ,
1521+ currentActor, currentExecutor.getIdentity ());
15321522
15331523 if (!currentExecutor.isDefaultActor ()) {
15341524 // The job already gave up the thread for us.
@@ -1827,9 +1817,8 @@ static void runOnAssumedThread(AsyncTask *task, ExecutorRef executor,
18271817 executor = trackingInfo.getActiveExecutor ();
18281818 trackingInfo.leave ();
18291819
1830- #if SWIFT_TASK_PRINTF_DEBUG
1831- fprintf (stderr, " [%p] leaving assumed thread, current executor is %p\n " , pthread_self (), executor.getIdentity ());
1832- #endif
1820+ SWIFT_TASK_DEBUG_LOG (" leaving assumed thread, current executor is %p" ,
1821+ executor.getIdentity ());
18331822
18341823 if (executor.isDefaultActor ())
18351824 asImpl (executor.getDefaultActor ())->giveUpThread (runner);
@@ -1843,9 +1832,9 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
18431832 auto currentExecutor =
18441833 (trackingInfo ? trackingInfo->getActiveExecutor ()
18451834 : ExecutorRef::generic ());
1846- # if SWIFT_TASK_PRINTF_DEBUG
1847- fprintf (stderr, " [%p] trying to switch from executor %p to %p \n " , pthread_self (), currentExecutor.getIdentity (), newExecutor. getIdentity ());
1848- # endif
1835+ SWIFT_TASK_DEBUG_LOG ( " trying to switch from executor %p to %p " ,
1836+ currentExecutor.getIdentity (),
1837+ newExecutor. getIdentity ());
18491838
18501839 // If the current executor is compatible with running the new executor,
18511840 // we can just immediately continue running with the resume function
@@ -1871,19 +1860,18 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
18711860 if (canGiveUpThreadForSwitch (trackingInfo, currentExecutor) &&
18721861 !shouldYieldThread () &&
18731862 tryAssumeThreadForSwitch (newExecutor, runner)) {
1874- # if SWIFT_TASK_PRINTF_DEBUG
1875- fprintf (stderr, " [%p] switch succeeded, task %p assumed thread for executor %p\n " , pthread_self (), task, newExecutor. getIdentity ());
1876- # endif
1863+ SWIFT_TASK_DEBUG_LOG (
1864+ " switch succeeded, task %p assumed thread for executor %p" , task,
1865+ newExecutor. getIdentity ());
18771866 giveUpThreadForSwitch (currentExecutor, runner);
18781867 // 'return' forces tail call
18791868 return runOnAssumedThread (task, newExecutor, trackingInfo, runner);
18801869 }
18811870
18821871 // Otherwise, just asynchronously enqueue the task on the given
18831872 // executor.
1884- #if SWIFT_TASK_PRINTF_DEBUG
1885- fprintf (stderr, " [%p] switch failed, task %p enqueued on executor %p\n " , pthread_self (), task, newExecutor.getIdentity ());
1886- #endif
1873+ SWIFT_TASK_DEBUG_LOG (" switch failed, task %p enqueued on executor %p" , task,
1874+ newExecutor.getIdentity ());
18871875 task->flagAsSuspended ();
18881876 swift_task_enqueue (task, newExecutor);
18891877}
@@ -1902,9 +1890,8 @@ void _swift_task_enqueueOnExecutor(Job *job, HeapObject *executor,
19021890
19031891SWIFT_CC (swift)
19041892static void swift_task_enqueueImpl(Job *job, ExecutorRef executor) {
1905- #if SWIFT_TASK_PRINTF_DEBUG
1906- fprintf (stderr, " [%p] enqueue job %p on executor %p\n " , pthread_self (), job, executor.getIdentity ());
1907- #endif
1893+ SWIFT_TASK_DEBUG_LOG (" enqueue job %p on executor %p" , job,
1894+ executor.getIdentity ());
19081895
19091896 assert (job && " no job provided" );
19101897
0 commit comments