Thank you for committing. And for telling me about shortcomings.
BR Justin
On 07/04/2016 06:54 PM, Nadav Har'El wrote:
Hi, thanks. Looks mostly good but some comments below.
On Mon, Jul 4, 2016 at 7:26 PM, Justin Cinkelj <justin.cink...@xlab.si
<mailto:justin.cink...@xlab.si>> wrote:
Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si
<mailto:justin.cink...@xlab.si>>
---
Makefile | 1 +
core/osv_c_wrappers.cc | 39
+++++++++++++++++++++++++++++++++++++++
include/osv/osv_c_wrappers.h | 27 +++++++++++++++++++++++++++
3 files changed, 67 insertions(+)
create mode 100644 core/osv_c_wrappers.cc
create mode 100644 include/osv/osv_c_wrappers.h
diff --git a/Makefile b/Makefile
index 7e15d0e..95da609 100644
--- a/Makefile
+++ b/Makefile
@@ -908,6 +908,7 @@ objects += core/net_trace.o
objects += core/app.o
objects += core/libaio.o
objects += core/osv_execve.o
+objects += core/osv_c_wrappers.o
#include $(src)/libc/build.mk <http://build.mk>:
libc =
diff --git a/core/osv_c_wrappers.cc b/core/osv_c_wrappers.cc
new file mode 100644
index 0000000..79fdc45
--- /dev/null
+++ b/core/osv_c_wrappers.cc
@@ -0,0 +1,39 @@
+
+#include <osv/debug.hh>
+#include <osv/sched.hh>
+#include <osv/app.hh>
+
+using namespace osv;
+using namespace sched;
+
+int get_all_app_threads(unsigned int tid, pid_t* tid_arr[],
size_t *len) {
Since this function already has a C-like interface, there is really no
reason to have both
it and the identical osv_get_all_app_threads function below - you can
have just one of them.
Moreover, you don't need to repeat the "extern C" declaration if it
already appears in the header file.
While the syntax "pid_t* tid_arr[]" is probably legal, I find it as a
confusing way to write a pointer to an array
(it's not really intended to be an array of pointers, right)? Why not
write pid_t** tid_arr?
+ sched::thread* app_thread = tid==0? sched::thread::current():
sched::thread::find_by_id(tid);
Please use either the name sched::thread or thread everywhere in this
file, but not both.
+ if (app_thread==nullptr) {
Please add spaces around operators.
+ return ESRCH;
+ }
+ std::vector<thread*> app_threads;
+ with_all_app_threads([&](thread& th2) {
+ app_threads.push_back(&th2);
+ }, *app_thread);
+
+ *tid_arr = (pid_t*)malloc(app_threads.size()*sizeof(pid_t));
+ if (*tid_arr == nullptr) {
+ *len = 0;
+ return ENOMEM;
+ }
+ *len = 0;
+ for (auto th : app_threads) {
+ (*tid_arr)[(*len)++] = th->id();
+ }
+ return 0;
+}
+
+
+extern "C" {
+
+int osv_get_all_app_threads(unsigned int tid, pid_t* tid_arr[],
size_t* max_len)
+{
+ return get_all_app_threads(tid, tid_arr, max_len);
+}
+
+};
diff --git a/include/osv/osv_c_wrappers.h
b/include/osv/osv_c_wrappers.h
new file mode 100644
index 0000000..cda8414
--- /dev/null
+++ b/include/osv/osv_c_wrappers.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013 Cloudius Systems, Ltd.
The year, and company name, isn't really up to date :-) Feel free to
use your own company's name here.
+ *
+ * This work is open source software, licensed under the terms of the
+ * BSD license as described in the LICENSE file in the top-level
directory.
+ */
+
+#ifndef INCLUDED_OSV_C_WRAPPERS_H
+#define INCLUDED_OSV_C_WRAPPERS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+Save in *tid_arr array TIDs of all threads from app which "owns"
input tid/thread.
+*tid_arr is allocated with malloc, *len holds lenght.
+Caller is responsible to free tid_arr.
+Returns 0 on success, error code on error.
+*/
+int osv_get_all_app_threads(unsigned int tid, pid_t* tid_arr[],
size_t* max_len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_OSV_C_WRAPPERS_H */
--
2.5.0
--
You received this message because you are subscribed to the Google
Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to osv-dev+unsubscr...@googlegroups.com
<mailto:osv-dev%2bunsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.