From: Akira Yokosawa <akiyks@gmail.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: perfbook@vger.kernel.org, Akira Yokosawa <akiyks@gmail.com>
Subject: [RFC PATCH v2 1/2] CodeSamples: Use 'intptr_t' to be compatible with 'void *'
Date: Tue, 30 May 2017 21:06:58 +0900 [thread overview]
Message-ID: <06a5601a-e908-a808-adbb-3605199028c7@gmail.com> (raw)
In-Reply-To: <8e20cd05-59f8-f651-d0e0-1db2a7105d33@gmail.com>
From 177ee2891184f0a97b66d748763dbc7af75033ff Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <akiyks@gmail.com>
Date: Tue, 30 May 2017 20:21:41 +0900
Subject: [RFC PATCH v2 1/2] CodeSamples: Use 'intptr_t' to be compatible with 'void *'
On x86_64, casting between "int" and "void *" in threadcreate.c
causes GCC to emit warnings such as:
warning: cast from pointer to integer of different size
warning: cast from integer to pointer of different size
Let's adopt C99 way of writing portable code.
Also do the same changes where appropriate. (Other than
threadcreate.c, no warnings were observed on x86_64.)
[Revised according to Paul's suggestion to keep intptr_t usage
confined.]
Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
CodeSamples/SMPdesign/matmul.c | 4 ++--
CodeSamples/SMPdesign/smpalloc.c | 4 ++--
CodeSamples/defer/gettimestampmp.c | 2 +-
CodeSamples/intro/threadcreate.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/CodeSamples/SMPdesign/matmul.c b/CodeSamples/SMPdesign/matmul.c
index 6a07730..3f70807 100644
--- a/CodeSamples/SMPdesign/matmul.c
+++ b/CodeSamples/SMPdesign/matmul.c
@@ -38,7 +38,7 @@ atomic_t nstarted;
void *matmul_thread(void *me_in)
{
- long me = (long)me_in;
+ long me = (intptr_t)me_in;
int i, j, k;
atomic_inc(&nstarted);
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
goflag = GOFLAG_INIT;
startcreatetime = get_microseconds();
for (i = 0; i < nthread; i++)
- create_thread(matmul_thread, (void *)(long)i);
+ create_thread(matmul_thread, (void *)(intptr_t)i);
while (atomic_read(&nstarted) != nthread)
barrier();
starttime = get_microseconds();
diff --git a/CodeSamples/SMPdesign/smpalloc.c b/CodeSamples/SMPdesign/smpalloc.c
index 95b21a1..454846b 100644
--- a/CodeSamples/SMPdesign/smpalloc.c
+++ b/CodeSamples/SMPdesign/smpalloc.c
@@ -123,7 +123,7 @@ void *memblock_test(void *arg)
long cnt = 0;
long cntfail = 0;
int i;
- int runlength = (int)(long)arg;
+ int runlength = (intptr_t)arg;
struct memblock *p[MAX_RUN];
if (runlength > MAX_RUN)
@@ -189,7 +189,7 @@ int main(int argc, char *argv[])
goflag = 1;
for (i = 0; i < nkids; i++)
- create_thread(memblock_test, (void *)(long)runlength);
+ create_thread(memblock_test, (void *)(intptr_t)runlength);
sleep(1);
goflag = 0;
diff --git a/CodeSamples/defer/gettimestampmp.c b/CodeSamples/defer/gettimestampmp.c
index bc0b9ea..2abade4 100644
--- a/CodeSamples/defer/gettimestampmp.c
+++ b/CodeSamples/defer/gettimestampmp.c
@@ -29,7 +29,7 @@ long curtimestamp = 0;
void *collect_timestamps(void *mask_in)
{
- long mask = (long)mask_in;
+ long mask = (intptr_t)mask_in;
while (curtimestamp < MAX_TIMESTAMPS) {
while ((curtimestamp & CURTIMESTAMP_MASK) != mask)
diff --git a/CodeSamples/intro/threadcreate.c b/CodeSamples/intro/threadcreate.c
index 26b7ba9..94cde89 100644
--- a/CodeSamples/intro/threadcreate.c
+++ b/CodeSamples/intro/threadcreate.c
@@ -22,7 +22,7 @@
void *thread_test(void *arg)
{
- int myarg = (int)arg;
+ int myarg = (intptr_t)arg;
printf("child thread %d: smp_thread_id() = %d\n",
myarg, smp_thread_id());
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
printf("Parent thread spawning %d threads.\n", nkids);
for (i = 0; i < nkids; i++)
- create_thread(thread_test, (void *)i);
+ create_thread(thread_test, (void *)(intptr_t)i);
wait_all_threads();
--
2.7.4
next prev parent reply other threads:[~2017-05-30 12:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-29 22:13 [RFC PATCH 0/4] CodeSamples: Cleanups and fixes Akira Yokosawa
2017-05-29 22:14 ` [RFC PATCH 1/4] CodeSamples: Add rule to generate Makefile.arch and api.h Akira Yokosawa
2017-05-29 22:16 ` [RFC PATCH 2/4] CodeSamples: Remove generated files from repository Akira Yokosawa
2017-05-29 22:17 ` [RFC PATCH 3/4] CodeSamples: Use 'intptr_t' to be compatible with 'void *' Akira Yokosawa
2017-05-30 0:10 ` Paul E. McKenney
2017-05-29 22:18 ` [RFC PATCH 4/4] CodeSamples/defer: Add compiler barriers in gettimestampmp.c Akira Yokosawa
2017-05-30 0:12 ` Paul E. McKenney
2017-05-30 0:02 ` [RFC PATCH 0/4] CodeSamples: Cleanups and fixes Paul E. McKenney
2017-05-30 1:44 ` Akira Yokosawa
2017-05-30 12:05 ` [RFC PATCH v2 0/2] " Akira Yokosawa
2017-05-30 12:06 ` Akira Yokosawa [this message]
2017-05-30 12:07 ` [RFC PATCH v2 2/2] CodeSamples/defer: Add compiler barriers in gettimestampmp.c Akira Yokosawa
2017-05-31 18:46 ` [RFC PATCH v2 0/2] CodeSamples: Cleanups and fixes Paul E. McKenney
2017-05-31 21:19 ` Akira Yokosawa
2017-06-01 0:05 ` Paul E. McKenney
2017-06-01 1:45 ` Junchang Wang
2017-06-01 4:19 ` Paul E. McKenney
2017-06-01 4:34 ` Junchang Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=06a5601a-e908-a808-adbb-3605199028c7@gmail.com \
--to=akiyks@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=perfbook@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.