@@ -335,17 +335,60 @@ struct FlagcxP2pXfer {
335335 std::vector<void *> openedIpcPtrs;
336336};
337337
338- static std::vector<FlagcxP2pNotifyMsg> gNotifyList ;
339- static std::mutex gNotifyMutex ;
338+ static std::vector<FlagcxP2pNotifyMsg> ¬ifyList () {
339+ static std::vector<FlagcxP2pNotifyMsg> list;
340+ return list;
341+ }
342+
343+ static std::mutex ¬ifyMutex () {
344+ static std::mutex mu;
345+ return mu;
346+ }
347+
348+ static std::unordered_map<uintptr_t , FlagcxP2pMemRegEntry> &memRegInfo () {
349+ static std::unordered_map<uintptr_t , FlagcxP2pMemRegEntry> info;
350+ return info;
351+ }
352+
353+ static std::unordered_map<FlagcxP2pMr, uintptr_t > &mrToBaseAddr () {
354+ static std::unordered_map<FlagcxP2pMr, uintptr_t > map;
355+ return map;
356+ }
357+
358+ static std::mutex &memMutex () {
359+ static std::mutex mu;
360+ return mu;
361+ }
362+
363+ static uint64_t &nextMrId () {
364+ static uint64_t id = 1 ;
365+ return id;
366+ }
367+
368+ static std::unordered_map<uint64_t , FlagcxP2pXfer> &xferMap () {
369+ static std::unordered_map<uint64_t , FlagcxP2pXfer> map;
370+ return map;
371+ }
372+
373+ static std::mutex &xferMutex () {
374+ static std::mutex mu;
375+ return mu;
376+ }
340377
341- static std::unordered_map< uintptr_t , FlagcxP2pMemRegEntry> gMemRegInfo ;
342- static std::unordered_map<FlagcxP2pMr, uintptr_t > gMrToBaseAddr ;
343- static std::mutex gMemMutex ;
344- static uint64_t gNextMrId = 1 ;
378+ static uint64_t & nextXferId () {
379+ static uint64_t id = 1 ;
380+ return id ;
381+ }
345382
346- static std::unordered_map<uint64_t , FlagcxP2pXfer> gXferMap ;
347- static std::mutex gXferMutex ;
348- static uint64_t gNextXferId = 1 ;
383+ #define gNotifyList notifyList ()
384+ #define gNotifyMutex notifyMutex ()
385+ #define gMemRegInfo memRegInfo ()
386+ #define gMrToBaseAddr mrToBaseAddr ()
387+ #define gMemMutex memMutex ()
388+ #define gNextMrId nextMrId ()
389+ #define gXferMap xferMap ()
390+ #define gXferMutex xferMutex ()
391+ #define gNextXferId nextXferId ()
349392
350393struct FlagcxSliceCache {
351394 static constexpr size_t kCap = 4096 ;
@@ -973,8 +1016,18 @@ void FlagcxWorkerPool::performPollCq() {
9731016
9741017// ---- Per-ibDev singleton plumbing -----------------------------------
9751018
976- static std::unique_ptr<FlagcxWorkerPool> gPools [MAX_IB_DEVS ];
977- static std::mutex gPoolMu ;
1019+ static std::unique_ptr<FlagcxWorkerPool> *p2pPools () {
1020+ static std::unique_ptr<FlagcxWorkerPool> pools[MAX_IB_DEVS ];
1021+ return pools;
1022+ }
1023+
1024+ static std::mutex &poolMutex () {
1025+ static std::mutex mu;
1026+ return mu;
1027+ }
1028+
1029+ #define gPools p2pPools ()
1030+ #define gPoolMu poolMutex ()
9781031
9791032static FlagcxWorkerPool *getOrCreatePool(int ibDevN, struct ibv_context *ctx) {
9801033 if (ibDevN < 0 || ibDevN >= MAX_IB_DEVS || ctx == NULL )
@@ -1105,8 +1158,18 @@ buildAndSubmitToPool(PoolTransferTask *task, const std::vector<void *> &dataVec,
11051158
11061159static constexpr uint64_t kPoolXferTag = 1ull << 63 ;
11071160
1108- static std::mutex gPoolTaskFreeMu ;
1109- static PoolTransferTask *gPoolTaskFreeHead = nullptr ;
1161+ static std::mutex &poolTaskFreeMutex () {
1162+ static std::mutex mu;
1163+ return mu;
1164+ }
1165+
1166+ static PoolTransferTask *&poolTaskFreeHead () {
1167+ static PoolTransferTask *head = nullptr ;
1168+ return head;
1169+ }
1170+
1171+ #define gPoolTaskFreeMu poolTaskFreeMutex ()
1172+ #define gPoolTaskFreeHead poolTaskFreeHead ()
11101173
11111174static PoolTransferTask *acquirePoolTask() {
11121175 {
0 commit comments