util: Don’t reference errno when pthread fails. #19194
pull miztake wants to merge 1 commits into bitcoin:master from miztake:prototype changing 1 files +3 −2-
miztake commented at 5:56 pm on June 6, 2020: contributorPthread library does not set errno. Pthread library’s errno is returned by return value.
-
DrahtBot added the label Utils/log/libs on Jun 6, 2020
-
practicalswift commented at 7:31 pm on June 6, 2020: contributor
Concept ACK: nice catch and nice first-time contribution!
May I ask how did you found this issue? :)
Warm welcome as a contributor @miztake :)
-
pstratem commented at 0:21 am on June 7, 2020: contributor
ACK c7601aba89972f71464c9809cc3607b96b5975ab
you can move the declaration into the if statement like this:
if ((int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) != 0) {
-
in src/util/system.cpp:1167 in c7601aba89 outdated
1162@@ -1163,8 +1163,9 @@ void ScheduleBatchPriority() 1163 { 1164 #ifdef SCHED_BATCH 1165 const static sched_param param{}; 1166- if (pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m) != 0) { 1167- LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno)); 1168+ int rc; 1169+ if ((rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) != 0) {
hebasto commented at 10:44 am on June 7, 2020:nit: could look clearer
0 const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m); 1 if (rc != 0) {
… until switching to C++17 :)
hebasto commented at 10:47 am on June 7, 2020: memberACK c7601aba89972f71464c9809cc3607b96b5975ab, tested on Linux Mint 19.3 (x86_64).
From the
pthread_setschedparam()
docs:On success, these functions return 0; on error, they return a nonzero error number.
hebasto commented at 10:50 am on June 7, 2020: memberyou can move the declaration into the if statement like this:
if ((int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) != 0) {
It won’t compile :) (at least on GCC 7.5).
miztake commented at 3:26 pm on June 7, 2020: contributorHi, @practicalswift
May I ask how did you found this issue? :)
Thank you for your comment. I didn’t actually output this log. It’s a common bug when using pthread and I found it in a code review. ( just greped “pthread” :) )
donaloconnor commented at 3:49 pm on June 7, 2020: contributorACK 0e7b64b64db00d03489a72c988dc7ef53433f69dhebasto approvedhebasto commented at 3:52 pm on June 7, 2020: memberACK 0e7b64b64db00d03489a72c988dc7ef53433f69d.
Mind squashing commits into one commit?
kristapsk commented at 4:29 pm on June 7, 2020: contributorConcept ACK, checkedman pthread_setschedparam
, change seems correct, but commits should be squashed into one.util: Don't reference errno when pthread fails.
Pthread library does not set errno. Pthread library's errno is returned by return value. Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
miztake commented at 7:42 am on June 8, 2020: contributorHi, @kristapsk
Thank you for your comment. I squashed the commits into one.
hebasto approvedMarcoFalke commented at 10:41 am on June 8, 2020: memberreview ACK cb38b069b0f41b1a26264784b1c1303c8ac6ab08practicalswift commented at 11:13 am on June 8, 2020: contributorACK cb38b069b0f41b1a26264784b1c1303c8ac6ab08 – patch looks correctfanquake merged this on Jun 8, 2020fanquake closed this on Jun 8, 2020
fanquake added the label Needs backport (0.20) on Jun 8, 2020laanwj commented at 11:58 am on June 9, 2020: memberPoshumous ACK, good catch!fanquake referenced this in commit 0596a6eeb5 on Jun 9, 2020fanquake removed the label Needs backport (0.20) on Jun 9, 2020fanquake referenced this in commit 01c563708f on Jul 10, 2020backpacker69 referenced this in commit 278f2eeffe on Sep 8, 2020fanquake referenced this in commit a825377c8a on Oct 14, 2020fanquake referenced this in commit fa5f91a4ec on Oct 15, 2020fanquake referenced this in commit 27bb2cc3b6 on Oct 16, 2020Bushstar referenced this in commit 77ef85cf89 on Oct 21, 2020Platinumwrist referenced this in commit 05e2740d92 on Oct 25, 2020MarcoFalke referenced this in commit 5baaea4410 on Dec 2, 2020Fabcien referenced this in commit 1fbbcdcdaa on May 14, 2021DrahtBot locked this on Feb 15, 2022
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 09:12 UTC
More mirrored repositories can be found on mirror.b10c.me