git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Architectural Support: x86_64 (#37)
[lunaix-os.git]
/
lunaix-os
/
usr
/
test_pthread.c
diff --git
a/lunaix-os/usr/test_pthread.c
b/lunaix-os/usr/test_pthread.c
index 247c36862ddfd846e913f2998c96fc9999594090..0c1dfe64286540fe231f3ec05597de893c7e5c27 100644
(file)
--- a/
lunaix-os/usr/test_pthread.c
+++ b/
lunaix-os/usr/test_pthread.c
@@
-8,11
+8,14
@@
Test payloads
*/
Test payloads
*/
+#define __int(ptr) ((int)(unsigned long)(ptr))
+#define __ptr(ptr) ((void*)(unsigned long)(ptr))
+
static void*
__print_and_sleep_randsec(void* value)
{
pthread_t tid = pthread_self();
static void*
__print_and_sleep_randsec(void* value)
{
pthread_t tid = pthread_self();
- printf("thread %d: gets number %d\n", tid,
(int)value
);
+ printf("thread %d: gets number %d\n", tid,
__int(value)
);
int fd = open("/dev/rand", O_RDONLY | O_DIRECT);
if (fd < 0) {
int fd = open("/dev/rand", O_RDONLY | O_DIRECT);
if (fd < 0) {
@@
-40,9
+43,9
@@
static void*
__print_and_sleep_seq(void* value)
{
pthread_t tid = pthread_self();
__print_and_sleep_seq(void* value)
{
pthread_t tid = pthread_self();
- printf("thread %d: gets number %d\n", tid,
(int)value
);
+ printf("thread %d: gets number %d\n", tid,
__int(value)
);
- int second =
(int)value
% 30;
+ int second =
__int(value)
% 30;
printf("thread %d: going to sleep %ds\n", tid, second);
sleep(second);
printf("thread %d: going to sleep %ds\n", tid, second);
sleep(second);
@@
-55,7
+58,7
@@
static void*
__print_and_sleep(void* value)
{
pthread_t tid = pthread_self();
__print_and_sleep(void* value)
{
pthread_t tid = pthread_self();
- printf("thread %d: gets number %d\n", tid,
(int)value
);
+ printf("thread %d: gets number %d\n", tid,
__int(value)
);
sleep(1);
printf("thread %d: exit\n", tid);
sleep(1);
printf("thread %d: exit\n", tid);
@@
-95,7
+98,7
@@
spawn_detached_thread(void* (*fn)(void *), int amount)
int err;
pthread_t created;
for (int i = 0; i < amount; i++) {
int err;
pthread_t created;
for (int i = 0; i < amount; i++) {
- err = pthread_create(&created, NULL, fn,
(void*)i
);
+ err = pthread_create(&created, NULL, fn,
__ptr(i)
);
if (err) {
printf("unable to create thread: %d\n", err);
continue;
if (err) {
printf("unable to create thread: %d\n", err);
continue;
@@
-136,7
+139,7
@@
pthread_test_join(int param)
void* v;
for (int i = 0; i < param; i++)
{
void* v;
for (int i = 0; i < param; i++)
{
- err = pthread_create(&created, NULL, __print_and_sleep,
(void*)i
);
+ err = pthread_create(&created, NULL, __print_and_sleep,
__ptr(i)
);
if (err) {
printf("unable to create thread: %d\n", err);
}
if (err) {
printf("unable to create thread: %d\n", err);
}
@@
-169,7
+172,7
@@
pthread_test_quit(int param)
do { \
printf("** [%s] test start\n", note); \
pthread_test_##testn(__VA_ARGS__); \
do { \
printf("** [%s] test start\n", note); \
pthread_test_##testn(__VA_ARGS__); \
- printf("** [%s] test passed\n"
);
\
+ printf("** [%s] test passed\n"
, note);
\
} while (0)
int main()
} while (0)
int main()