Skip to content

Commit

Permalink
[examples] Add recursive static initialization example
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Mar 13, 2020
1 parent e845448 commit 2ba4543
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/stm32f469_discovery/threadsafe_statics/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2020, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <modm/board.hpp>

void constructDummy();
class Dummy
{
public:
Dummy()
{
MODM_LOG_INFO << "Dummy class constructed" << modm::endl;
constructDummy(); // recursive initialization
}
};

void
constructDummy()
{
static Dummy dummy;
MODM_LOG_INFO << "constructDummy() called" << modm::endl;
}

int
main()
{
Board::initialize();
uint32_t counter(0);

while (true)
{
Board::LedGreen::toggle();
modm::delayMilliseconds(Board::Button::read() ? 125 : 500);

MODM_LOG_INFO << "loop: " << counter++ << modm::endl;
constructDummy();
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/stm32f469_discovery/threadsafe_statics/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:disco-f469ni</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f469_discovery/threadsafe_statics</option>
</options>
<modules>
<module>modm:platform:gpio</module>
<module>modm:build:scons</module>
</modules>
</library>

0 comments on commit 2ba4543

Please sign in to comment.