File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed
hardware/arduino/avr/cores/arduino Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 25
25
26
26
extern uint8_t _initEndpoints[];
27
27
28
- PluggableUSB_ PluggableUSB;
29
-
30
28
int PluggableUSB_::getInterface (uint8_t * interfaceNum)
31
29
{
32
30
int sent = 0 ;
@@ -90,6 +88,12 @@ bool PluggableUSB_::plug(PUSBListNode *node)
90
88
// restart USB layer???
91
89
}
92
90
91
+ PluggableUSB_& PluggableUSB ()
92
+ {
93
+ static PluggableUSB_ obj;
94
+ return obj;
95
+ }
96
+
93
97
PluggableUSB_::PluggableUSB_ () : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
94
98
lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
95
99
rootNode(NULL )
Original file line number Diff line number Diff line change @@ -66,7 +66,10 @@ class PluggableUSB_ {
66
66
PUSBListNode* rootNode;
67
67
};
68
68
69
- extern PluggableUSB_ PluggableUSB;
69
+ // Replacement for global singleton.
70
+ // This function prevents static-initialization-order-fiasco
71
+ // https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
72
+ PluggableUSB_& PluggableUSB ();
70
73
71
74
#endif
72
75
Original file line number Diff line number Diff line change @@ -362,7 +362,7 @@ bool ClassInterfaceRequest(USBSetup& setup)
362
362
return CDC_Setup (setup);
363
363
364
364
#ifdef PLUGGABLE_USB_ENABLED
365
- return PluggableUSB.setup (setup, i);
365
+ return PluggableUSB () .setup (setup, i);
366
366
#endif
367
367
return false ;
368
368
}
@@ -440,7 +440,7 @@ static u8 SendInterfaces()
440
440
CDC_GetInterface (&interfaces);
441
441
442
442
#ifdef PLUGGABLE_USB_ENABLED
443
- PluggableUSB.getInterface (&interfaces);
443
+ PluggableUSB () .getInterface (&interfaces);
444
444
#endif
445
445
446
446
return interfaces;
@@ -476,7 +476,7 @@ bool SendDescriptor(USBSetup& setup)
476
476
477
477
InitControl (setup.wLength );
478
478
#ifdef PLUGGABLE_USB_ENABLED
479
- ret = PluggableUSB.getDescriptor (t);
479
+ ret = PluggableUSB () .getDescriptor (t);
480
480
if (ret != 0 ) {
481
481
return (ret > 0 ? true : false );
482
482
}
You can’t perform that action at this time.
0 commit comments