@@ -269,10 +269,7 @@ static ExecutorRef swift_task_getCurrentExecutorImpl() {
269
269
auto currentTracking = ExecutorTrackingInfo::current ();
270
270
auto result = (currentTracking ? currentTracking->getActiveExecutor ()
271
271
: 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 ());
276
273
return result;
277
274
}
278
275
@@ -1172,10 +1169,7 @@ static Job *preprocessQueue(JobRef first,
1172
1169
}
1173
1170
1174
1171
void 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 );
1179
1173
auto oldState = CurrentState.load (std::memory_order_acquire);
1180
1174
assert (oldState.Flags .isAnyRunningStatus ());
1181
1175
@@ -1236,14 +1230,10 @@ void DefaultActorImpl::giveUpThread(RunningJobInfo runner) {
1236
1230
continue ;
1237
1231
}
1238
1232
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__)
1247
1237
LOG_STATE_TRANSITION;
1248
1238
1249
1239
// The priority of the remaining work.
@@ -1494,10 +1484,7 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
1494
1484
SWIFT_CC (swiftasync)
1495
1485
static void processDefaultActor(DefaultActorImpl *currentActor,
1496
1486
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);
1501
1488
DefaultActorImpl *actor = currentActor;
1502
1489
1503
1490
// If we actually have work to do, we'll need to set up tracking info.
@@ -1521,10 +1508,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
1521
1508
auto job = currentActor->claimNextJobOrGiveUp (threadIsRunningActor,
1522
1509
runner);
1523
1510
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);
1528
1513
1529
1514
// If we failed to claim a job, we have nothing to do.
1530
1515
if (!job) {
@@ -1544,10 +1529,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
1544
1529
// If it's become nil, or not a default actor, we have nothing to do.
1545
1530
auto currentExecutor = trackingInfo.getActiveExecutor ();
1546
1531
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 ());
1551
1534
1552
1535
if (!currentExecutor.isDefaultActor ()) {
1553
1536
// The job already gave up the thread for us.
@@ -1851,10 +1834,8 @@ static void runOnAssumedThread(AsyncTask *task, ExecutorRef executor,
1851
1834
executor = trackingInfo.getActiveExecutor ();
1852
1835
trackingInfo.leave ();
1853
1836
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 ());
1858
1839
1859
1840
if (executor.isDefaultActor ())
1860
1841
asImpl (executor.getDefaultActor ())->giveUpThread (runner);
@@ -1868,11 +1849,9 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
1868
1849
auto currentExecutor =
1869
1850
(trackingInfo ? trackingInfo->getActiveExecutor ()
1870
1851
: 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 ());
1876
1855
1877
1856
// If the current executor is compatible with running the new executor,
1878
1857
// we can just immediately continue running with the resume function
@@ -1898,21 +1877,18 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
1898
1877
if (canGiveUpThreadForSwitch (trackingInfo, currentExecutor) &&
1899
1878
!shouldYieldThread () &&
1900
1879
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 ());
1905
1883
giveUpThreadForSwitch (currentExecutor, runner);
1906
1884
// 'return' forces tail call
1907
1885
return runOnAssumedThread (task, newExecutor, trackingInfo, runner);
1908
1886
}
1909
1887
1910
1888
// Otherwise, just asynchronously enqueue the task on the given
1911
1889
// 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 ());
1916
1892
task->flagAsSuspended ();
1917
1893
_swift_task_clearCurrent ();
1918
1894
swift_task_enqueue (task, newExecutor);
@@ -1932,10 +1908,8 @@ void _swift_task_enqueueOnExecutor(Job *job, HeapObject *executor,
1932
1908
1933
1909
SWIFT_CC (swift)
1934
1910
static 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 ());
1939
1913
1940
1914
assert (job && " no job provided" );
1941
1915
0 commit comments