Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(931)

Unified Diff: ppapi/native_client/src/untrusted/irt_stub/thread_creator.c

Issue 10914053: Relocating files in the nacl repo that belong in chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/native_client/src/untrusted/irt_stub/thread_creator.c
diff --git a/ppapi/native_client/src/untrusted/irt_stub/thread_creator.c b/ppapi/native_client/src/untrusted/irt_stub/thread_creator.c
new file mode 100644
index 0000000000000000000000000000000000000000..629131686ef123fe33ad528ab4c6690da39e5156
--- /dev/null
+++ b/ppapi/native_client/src/untrusted/irt_stub/thread_creator.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "native_client/src/untrusted/irt_stub/thread_creator.h"
+
+#include <pthread.h>
+
+#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/untrusted/irt/irt.h"
+
+
+static int thread_create(uintptr_t *tid,
+ void (*func)(void *thread_argument),
+ void *thread_argument) {
+ /*
+ * We know that newlib and glibc use a small pthread_t type, so we
+ * do not need to wrap pthread_t values.
+ */
+ NACL_ASSERT_SAME_SIZE(pthread_t, uintptr_t);
+
+ return pthread_create((pthread_t *) tid, NULL,
+ (void *(*)(void *thread_argument)) func,
+ thread_argument);
+}
+
+static int thread_join(uintptr_t tid) {
+ return pthread_join((pthread_t) tid, NULL);
+}
+
+const static struct PP_ThreadFunctions thread_funcs = {
+ thread_create,
+ thread_join
+};
+
+/*
+ * We cannot tell at link time whether the application uses PPB_Audio,
+ * because of the way that PPAPI is defined via runtime interface
+ * query rather than a set of static functions. This means that we
+ * register the audio thread functions unconditionally. This adds the
+ * small overhead of pulling in pthread_create() even if the
+ * application does not use PPB_Audio or libpthread.
+ *
+ * If an application developer wants to avoid that cost, they can
+ * override this function with an empty definition.
+ */
+void __nacl_register_thread_creator(const struct nacl_irt_ppapihook *hooks) {
+ hooks->ppapi_register_thread_creator(&thread_funcs);
+}

Powered by Google App Engine
This is Rietveld 408576698