Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f10dec

Browse files
author
Octavian Purdila
committed
Merge pull request torvalds#125 from pscollins/return-pthread-tid
lkl: Return thread id from thread_create host op
2 parents a4349bf + 0b78db8 commit 2f10dec

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

arch/lkl/include/uapi/asm/host_ops.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/* Defined in {posix,nt}-host.c */
55
struct lkl_mutex_t;
66
struct lkl_sem_t;
7+
typedef unsigned long lkl_thread_t;
78

89
/**
910
* lkl_host_operations - host operations used by the Linux kernel
@@ -31,7 +32,7 @@ struct lkl_sem_t;
3132
* @mutex_unlock - release the mutex
3233
*
3334
* @thread_create - create a new thread and run f(arg) in its context; returns a
34-
* thread handle or NULL if the thread could not be created
35+
* thread handle or 0 if the thread could not be created
3536
* @thread_exit - terminates the current thread
3637
*
3738
* @tls_alloc - allocate a thread local storage key; returns 0 if succesful
@@ -74,7 +75,7 @@ struct lkl_host_operations {
7475
void (*mutex_lock)(struct lkl_mutex_t *mutex);
7576
void (*mutex_unlock)(struct lkl_mutex_t *mutex);
7677

77-
int (*thread_create)(void (*f)(void *), void *arg);
78+
lkl_thread_t (*thread_create)(void (*f)(void *), void *arg);
7879
void (*thread_exit)(void);
7980

8081
int (*tls_alloc)(unsigned int *key);

arch/lkl/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,
8181
}
8282

8383
ret = lkl_ops->thread_create(lkl_run_kernel, NULL);
84-
if (ret) {
84+
if (!ret) {
8585
ret = -ENOMEM;
8686
goto out_free_idle_sem;
8787
}

arch/lkl/kernel/threads.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int copy_thread(unsigned long clone_flags, unsigned long esp,
144144
tba->ti = ti;
145145

146146
ret = lkl_ops->thread_create(thread_bootstrap, tba);
147-
if (ret) {
147+
if (!ret) {
148148
kfree(tba);
149149
return -ENOMEM;
150150
}

tools/lkl/lib/nt-host.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ static void mutex_free(struct lkl_mutex_t *_mutex)
6363
free(_mutex);
6464
}
6565

66-
static int thread_create(void (*fn)(void *), void *arg)
66+
static lkl_thread_t thread_create(void (*fn)(void *), void *arg)
6767
{
6868
DWORD WINAPI (*win_fn)(LPVOID arg) = (DWORD WINAPI (*)(LPVOID))fn;
6969

70-
return CreateThread(NULL, 0, win_fn, arg, 0, NULL) ? 0 : -1;
70+
return CreateThread(NULL, 0, win_fn, arg, 0, NULL);
7171
}
7272

7373
static void thread_exit(void)

tools/lkl/lib/posix-host.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ struct lkl_sem_t {
5353
lkl_printf("%s: %s\n", #exp, strerror(errno)); \
5454
} while (0)
5555

56-
/* pthread_* functions use the reverse convention */
57-
#define WARN_PTHREAD(exp) do { \
58-
int __ret = exp; \
59-
if (__ret > 0) \
60-
lkl_printf("%s: %s\n", #exp, strerror(__ret)); \
61-
} while (0)
56+
static int _warn_pthread(int ret, char *str_exp)
57+
{
58+
if (ret > 0)
59+
lkl_printf("%s: %s\n", str_exp, strerror(ret));
6260

61+
return ret;
62+
}
63+
64+
65+
/* pthread_* functions use the reverse convention */
66+
#define WARN_PTHREAD(exp) _warn_pthread(exp, #exp)
6367

6468
static struct lkl_sem_t *sem_alloc(int count)
6569
{
@@ -176,11 +180,13 @@ static void mutex_free(struct lkl_mutex_t *_mutex)
176180
free(_mutex);
177181
}
178182

179-
static int thread_create(void (*fn)(void *), void *arg)
183+
static lkl_thread_t thread_create(void (*fn)(void *), void *arg)
180184
{
181185
pthread_t thread;
182-
183-
return pthread_create(&thread, NULL, (void* (*)(void *))fn, arg);
186+
if (WARN_PTHREAD(pthread_create(&thread, NULL, (void* (*)(void *))fn, arg)))
187+
return 0;
188+
else
189+
return (lkl_thread_t) thread;
184190
}
185191

186192
static void thread_exit(void)

tools/lkl/lib/virtio_net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ int lkl_netdev_add(struct lkl_netdev *nd, void *mac)
198198
if (ret)
199199
goto out_free;
200200

201-
if (lkl_host_ops.thread_create(poll_thread, &dev->rx_poll) < 0)
201+
if (lkl_host_ops.thread_create(poll_thread, &dev->rx_poll) == 0)
202202
goto out_cleanup_dev;
203203

204-
if (lkl_host_ops.thread_create(poll_thread, &dev->tx_poll) < 0)
204+
if (lkl_host_ops.thread_create(poll_thread, &dev->tx_poll) == 0)
205205
goto out_cleanup_dev;
206206

207207
/* RX/TX thread polls will exit when the host netdev handle is closed */

tools/lkl/tests/boot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ static int test_syscall_thread(char *str, int len)
667667
}
668668

669669
ret = lkl_host_ops.thread_create(test_thread, pipe_fds);
670-
if (ret) {
670+
if (!ret) {
671671
snprintf(str, len, "failed to create thread");
672672
return TEST_FAILURE;
673673
}

0 commit comments

Comments
 (0)