@@ -260,9 +260,7 @@ static ExecutorRef swift_task_getCurrentExecutorImpl() {
260
260
auto currentTracking = ExecutorTrackingInfo::current ();
261
261
auto result = (currentTracking ? currentTracking->getActiveExecutor ()
262
262
: 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 ());
266
264
return result;
267
265
}
268
266
@@ -1158,9 +1156,7 @@ static Job *preprocessQueue(JobRef first,
1158
1156
}
1159
1157
1160
1158
void 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 );
1164
1160
auto oldState = CurrentState.load (std::memory_order_acquire);
1165
1161
assert (oldState.Flags .isAnyRunningStatus ());
1166
1162
@@ -1220,13 +1216,11 @@ void DefaultActorImpl::giveUpThread(RunningJobInfo runner) {
1220
1216
// Try again.
1221
1217
continue ;
1222
1218
}
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__)
1230
1224
LOG_STATE_TRANSITION;
1231
1225
1232
1226
// The priority of the remaining work.
@@ -1478,9 +1472,7 @@ static void swift_job_runImpl(Job *job, ExecutorRef executor) {
1478
1472
SWIFT_CC (swiftasync)
1479
1473
static void processDefaultActor(DefaultActorImpl *currentActor,
1480
1474
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);
1484
1476
DefaultActorImpl *actor = currentActor;
1485
1477
1486
1478
// If we actually have work to do, we'll need to set up tracking info.
@@ -1504,9 +1496,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
1504
1496
auto job = currentActor->claimNextJobOrGiveUp (threadIsRunningActor,
1505
1497
runner);
1506
1498
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);
1510
1501
1511
1502
// If we failed to claim a job, we have nothing to do.
1512
1503
if (!job) {
@@ -1526,9 +1517,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
1526
1517
// If it's become nil, or not a default actor, we have nothing to do.
1527
1518
auto currentExecutor = trackingInfo.getActiveExecutor ();
1528
1519
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 ());
1532
1522
1533
1523
if (!currentExecutor.isDefaultActor ()) {
1534
1524
// The job already gave up the thread for us.
@@ -1827,9 +1817,8 @@ static void runOnAssumedThread(AsyncTask *task, ExecutorRef executor,
1827
1817
executor = trackingInfo.getActiveExecutor ();
1828
1818
trackingInfo.leave ();
1829
1819
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 ());
1833
1822
1834
1823
if (executor.isDefaultActor ())
1835
1824
asImpl (executor.getDefaultActor ())->giveUpThread (runner);
@@ -1843,9 +1832,9 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
1843
1832
auto currentExecutor =
1844
1833
(trackingInfo ? trackingInfo->getActiveExecutor ()
1845
1834
: 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 ());
1849
1838
1850
1839
// If the current executor is compatible with running the new executor,
1851
1840
// we can just immediately continue running with the resume function
@@ -1871,19 +1860,18 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
1871
1860
if (canGiveUpThreadForSwitch (trackingInfo, currentExecutor) &&
1872
1861
!shouldYieldThread () &&
1873
1862
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 ());
1877
1866
giveUpThreadForSwitch (currentExecutor, runner);
1878
1867
// 'return' forces tail call
1879
1868
return runOnAssumedThread (task, newExecutor, trackingInfo, runner);
1880
1869
}
1881
1870
1882
1871
// Otherwise, just asynchronously enqueue the task on the given
1883
1872
// 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 ());
1887
1875
task->flagAsSuspended ();
1888
1876
swift_task_enqueue (task, newExecutor);
1889
1877
}
@@ -1902,9 +1890,8 @@ void _swift_task_enqueueOnExecutor(Job *job, HeapObject *executor,
1902
1890
1903
1891
SWIFT_CC (swift)
1904
1892
static 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 ());
1908
1895
1909
1896
assert (job && " no job provided" );
1910
1897
0 commit comments