Skip to content

[rtos] Add default constructor for Semaphore #2189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2016

Conversation

geky
Copy link
Contributor

@geky geky commented Jul 18, 2016

Currently Semaphore can not be instantiated without an explicit count as a constructor argument. This limits where Semaphores can be declared and requires explicit initialization in several annoying places, such as in member variables and SingletonPtr targets.

This adds a default count of 0, which has shown to be the most common initial value used for semaphores.

cc @0xc0170, @c1728p9

Currently Semaphore can not be instantiated without an explicit count
as a constructor argument. This limits where Semaphores can be declared
and requires explicit initialization in several annoying places, such
as in member variables and SingletonPtr targets.

This adds a default count of 0, which has shown to be the most common
initial value used for semaphores.
@geky
Copy link
Contributor Author

geky commented Jul 18, 2016

@mbed-bot: TEST

HOST_OSES=windows
BUILD_TOOLCHAINS=GCC_ARM,ARM,IAR
TARGETS=K64F,LPC1768

@mbed-bot
Copy link

[Build 647]
SUCCESS: Building succeeded and tests were run! Be sure to check the test results

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 19, 2016

This limits where Semaphores can be declared

More details?

cc @bogdanm

@geky
Copy link
Contributor Author

geky commented Jul 19, 2016

This mostly limits Semaphores being declared in naive data-structures. Properly handling initialization of C++ objects is annoying and often skimmed over. Normally this isn't a problem since classes are usually passed around by reference, but in this case Semaphores is primitive to be passed around by value.

For example, just try to create an array of Semaphores and you'll have a hard time:

Semaphore semas[SEMA_COUNT];

This initial motivation for this change was use in the SingletonPtr class (#2158, example) which would require a syntactical change to support non-default constructors:

SingletonPtr<Semaphore> sema;

Additionally, storing a Semaphore as a member variable requires explicit construction (example), which can get annoying.

All of these have workarounds, but providing a default constructor avoids the reoccuring issue.

@0xc0170
Copy link
Contributor

0xc0170 commented Jul 19, 2016

Thanks for providing more info

LGTM

@geky
Copy link
Contributor Author

geky commented Jul 19, 2016

no problem : )

@sg- sg- merged commit 518afae into ARMmbed:master Jul 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants