Skip to content

core: thread_flags: optimize thread_flags_wait_one, fix doxygen#5200

Merged
miri64 merged 2 commits intoRIOT-OS:masterfrom
kaspar030:optimize_thread_flags
Mar 30, 2016
Merged

core: thread_flags: optimize thread_flags_wait_one, fix doxygen#5200
miri64 merged 2 commits intoRIOT-OS:masterfrom
kaspar030:optimize_thread_flags

Conversation

@kaspar030
Copy link
Copy Markdown
Contributor

No need to call expensive bitarithm_lsb() for just keeping the most significant bit in thread_flags_wait_one(). Also fix doxygen explaining wrong order.

@kaspar030 kaspar030 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: core Area: RIOT kernel. Handle PRs marked with this with care! Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer labels Mar 30, 2016
@cgundogan
Copy link
Copy Markdown
Member

ACK

@kaspar030 kaspar030 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 30, 2016
thread_t *me = (thread_t*) sched_active_thread;
unsigned tmp = me->flags & mask;
return _thread_flags_clear_atomic(me, thread_flags_clear(1 << bitarithm_lsb(tmp)));
tmp &= -tmp;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better ~tmp + 1 so it does not break for architectures that don't use two's complement. At least in theory there could be such systems. Even with -O0 gcc understands and optimizes the code, so there is no drawback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm sounds sensible. If someone wants to compile for a PDP, then it might choose one's complement instead of 2's

@kaspar030 kaspar030 force-pushed the optimize_thread_flags branch from 7384f52 to 46e49fa Compare March 30, 2016 12:09
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • addressed @Kijewski's comment, added thread_flags_wait_one() to test application

@cgundogan ACK holds?

@kaspar030
Copy link
Copy Markdown
Contributor Author

Just to make those PDP users happy. ;)

@cgundogan
Copy link
Copy Markdown
Member

yes ACK upholds

@cgundogan
Copy link
Copy Markdown
Member

do we need a second one or is the change minor enough?

return _thread_flags_clear_atomic(me, thread_flags_clear(1 << bitarithm_lsb(tmp)));
thread_flags_t tmp = me->flags & mask;
/* clear all but least significant bit */
tmp &= ~tmp + 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I have parens?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you like them?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correctly ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, how is correctly? "not" has precedence over "plus", so do I parenthise (~tmp) +1?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that was my reason to ask for parentheses. If I don't how this evaluated, I cannot judge if it is correct. ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not creating an additional Github account and acknowledge your own PRs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could someone else please step in and either ACK this or explain which parens help understanding the expression?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess tmp &= (~tmp + 1); would be okay.

@OlegHahm
Copy link
Copy Markdown
Member

I could give a second ACK if my comment is addressed.

@kaspar030 kaspar030 force-pushed the optimize_thread_flags branch from 92fb456 to 412b363 Compare March 30, 2016 15:12
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • addressed comment

@OlegHahm
Copy link
Copy Markdown
Member

ACK

@miri64
Copy link
Copy Markdown
Member

miri64 commented Mar 30, 2016

Three ACKs (by two people) and a happy Murdock. Let's go.

@miri64 miri64 merged commit 3ddff58 into RIOT-OS:master Mar 30, 2016
@kaspar030 kaspar030 deleted the optimize_thread_flags branch February 7, 2017 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants