@@ -269,10 +269,7 @@ static ExecutorRef swift_task_getCurrentExecutorImpl() {
269269 auto currentTracking = ExecutorTrackingInfo::current ();
270270 auto result = (currentTracking ? currentTracking->getActiveExecutor ()
271271 : ExecutorRef::generic ());
272- #if SWIFT_TASK_PRINTF_DEBUG
273- fprintf (stderr, " [%lu] getting current executor %p\n " ,
274- _swift_get_thread_id (), result.getIdentity ());
275- #endif
272+ SWIFT_TASK_DEBUG_LOG (" getting current executor %p" , result.getIdentity ());
276273 return result;
277274}
278275
@@ -1172,10 +1169,7 @@ static Job *preprocessQueue(JobRef first,
11721169}
11731170
11741171void DefaultActorImpl::giveUpThread (RunningJobInfo runner) {
1175- #if SWIFT_TASK_PRINTF_DEBUG
1176- fprintf (stderr, " [%lu] giving up thread for actor %p\n " ,
1177- _swift_get_thread_id (), this );
1178- #endif
1172+ SWIFT_TASK_DEBUG_LOG (" giving up thread for actor %p" , this );
11791173 auto oldState = CurrentState.load (std::memory_order_acquire);
11801174 assert (oldState.Flags .isAnyRunningStatus ());
11811175
@@ -1236,14 +1230,10 @@ void DefaultActorImpl::giveUpThread(RunningJobInfo runner) {
12361230 continue ;
12371231 }
12381232
1239- #if SWIFT_TASK_PRINTF_DEBUG
1240- # define LOG_STATE_TRANSITION \
1241- fprintf (stderr, " [%lu] actor %p transitioned from %zx to %zx (%s)\n " , \
1242- _swift_get_thread_id (), this , oldState.Flags .getOpaqueValue (), \
1243- newState.Flags .getOpaqueValue (), __FUNCTION__)
1244- #else
1245- # define LOG_STATE_TRANSITION ((void )0 )
1246- #endif
1233+ #define LOG_STATE_TRANSITION \
1234+ SWIFT_TASK_DEBUG_LOG (" actor %p transitioned from %zx to %zx (%s)\n " , this , \
1235+ oldState.Flags .getOpaqueValue (), \
1236+ newState.Flags .getOpaqueValue (), __FUNCTION__)
12471237 LOG_STATE_TRANSITION;
12481238
12491239 // The priority of the remaining work.
@@ -1494,10 +1484,7 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
14941484SWIFT_CC (swiftasync)
14951485static void processDefaultActor(DefaultActorImpl *currentActor,
14961486 RunningJobInfo runner) {
1497- #if SWIFT_TASK_PRINTF_DEBUG
1498- fprintf (stderr, " [%lu] processDefaultActor %p\n " ,
1499- _swift_get_thread_id (), currentActor);
1500- #endif
1487+ SWIFT_TASK_DEBUG_LOG (" processDefaultActor %p" , currentActor);
15011488 DefaultActorImpl *actor = currentActor;
15021489
15031490 // If we actually have work to do, we'll need to set up tracking info.
@@ -1521,10 +1508,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
15211508 auto job = currentActor->claimNextJobOrGiveUp (threadIsRunningActor,
15221509 runner);
15231510
1524- #if SWIFT_TASK_PRINTF_DEBUG
1525- fprintf (stderr, " [%lu] processDefaultActor %p claimed job %p\n " ,
1526- _swift_get_thread_id (), currentActor, job);
1527- #endif
1511+ SWIFT_TASK_DEBUG_LOG (" processDefaultActor %p claimed job %p" , currentActor,
1512+ job);
15281513
15291514 // If we failed to claim a job, we have nothing to do.
15301515 if (!job) {
@@ -1544,10 +1529,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
15441529 // If it's become nil, or not a default actor, we have nothing to do.
15451530 auto currentExecutor = trackingInfo.getActiveExecutor ();
15461531
1547- #if SWIFT_TASK_PRINTF_DEBUG
1548- fprintf (stderr, " [%lu] processDefaultActor %p current executor now %p\n " ,
1549- _swift_get_thread_id (), currentActor, currentExecutor.getIdentity ());
1550- #endif
1532+ SWIFT_TASK_DEBUG_LOG (" processDefaultActor %p current executor now %p" ,
1533+ currentActor, currentExecutor.getIdentity ());
15511534
15521535 if (!currentExecutor.isDefaultActor ()) {
15531536 // The job already gave up the thread for us.
@@ -1851,10 +1834,8 @@ static void runOnAssumedThread(AsyncTask *task, ExecutorRef executor,
18511834 executor = trackingInfo.getActiveExecutor ();
18521835 trackingInfo.leave ();
18531836
1854- #if SWIFT_TASK_PRINTF_DEBUG
1855- fprintf (stderr, " [%lu] leaving assumed thread, current executor is %p\n " ,
1856- _swift_get_thread_id (), executor.getIdentity ());
1857- #endif
1837+ SWIFT_TASK_DEBUG_LOG (" leaving assumed thread, current executor is %p" ,
1838+ executor.getIdentity ());
18581839
18591840 if (executor.isDefaultActor ())
18601841 asImpl (executor.getDefaultActor ())->giveUpThread (runner);
@@ -1868,11 +1849,9 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
18681849 auto currentExecutor =
18691850 (trackingInfo ? trackingInfo->getActiveExecutor ()
18701851 : ExecutorRef::generic ());
1871- #if SWIFT_TASK_PRINTF_DEBUG
1872- fprintf (stderr, " [%lu] trying to switch from executor %p to %p\n " ,
1873- _swift_get_thread_id (), currentExecutor.getIdentity (),
1874- newExecutor.getIdentity ());
1875- #endif
1852+ SWIFT_TASK_DEBUG_LOG (" trying to switch from executor %p to %p" ,
1853+ currentExecutor.getIdentity (),
1854+ newExecutor.getIdentity ());
18761855
18771856 // If the current executor is compatible with running the new executor,
18781857 // we can just immediately continue running with the resume function
@@ -1898,21 +1877,18 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
18981877 if (canGiveUpThreadForSwitch (trackingInfo, currentExecutor) &&
18991878 !shouldYieldThread () &&
19001879 tryAssumeThreadForSwitch (newExecutor, runner)) {
1901- #if SWIFT_TASK_PRINTF_DEBUG
1902- fprintf (stderr, " [%lu] switch succeeded, task %p assumed thread for executor %p\n " ,
1903- _swift_get_thread_id (), task, newExecutor.getIdentity ());
1904- #endif
1880+ SWIFT_TASK_DEBUG_LOG (
1881+ " switch succeeded, task %p assumed thread for executor %p" , task,
1882+ newExecutor.getIdentity ());
19051883 giveUpThreadForSwitch (currentExecutor, runner);
19061884 // 'return' forces tail call
19071885 return runOnAssumedThread (task, newExecutor, trackingInfo, runner);
19081886 }
19091887
19101888 // Otherwise, just asynchronously enqueue the task on the given
19111889 // executor.
1912- #if SWIFT_TASK_PRINTF_DEBUG
1913- fprintf (stderr, " [%lu] switch failed, task %p enqueued on executor %p\n " ,
1914- _swift_get_thread_id (), task, newExecutor.getIdentity ());
1915- #endif
1890+ SWIFT_TASK_DEBUG_LOG (" switch failed, task %p enqueued on executor %p" , task,
1891+ newExecutor.getIdentity ());
19161892 task->flagAsSuspended ();
19171893 _swift_task_clearCurrent ();
19181894 swift_task_enqueue (task, newExecutor);
@@ -1932,10 +1908,8 @@ void _swift_task_enqueueOnExecutor(Job *job, HeapObject *executor,
19321908
19331909SWIFT_CC (swift)
19341910static void swift_task_enqueueImpl(Job *job, ExecutorRef executor) {
1935- #if SWIFT_TASK_PRINTF_DEBUG
1936- fprintf (stderr, " [%lu] enqueue job %p on executor %p\n " ,
1937- _swift_get_thread_id (), job, executor.getIdentity ());
1938- #endif
1911+ SWIFT_TASK_DEBUG_LOG (" enqueue job %p on executor %p" , job,
1912+ executor.getIdentity ());
19391913
19401914 assert (job && " no job provided" );
19411915
0 commit comments