diff options
| author | bors <bors@rust-lang.org> | 2013-11-05 08:56:08 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-05 08:56:08 -0800 |
| commit | 7fb583be7b0df80c91df026c6a2bde550bc27a7c (patch) | |
| tree | 5471652a73737a511636093172321b7d1dc06130 /src/rt | |
| parent | 92065ceb634872f53a1a402cf306fbf02550b00d (diff) | |
| parent | 47e0bd403a04d26506f723ac44ee9ea0aa5d3ad5 (diff) | |
auto merge of #10290 : dbussink/rust/thread_in_rust, r=alexcrichton
This binds to the appropriate pthreads_* and Windows specific functions and calls them from Rust. This allows for removal of the C++ support code for threads. This needs to be reviewed for the Windows parts, I've tested on OS X and Linux. Fixes #10162
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 37 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 3 | ||||
| -rw-r--r-- | src/rt/sync/rust_thread.cpp | 65 | ||||
| -rw-r--r-- | src/rt/sync/rust_thread.h | 38 |
4 files changed, 0 insertions, 143 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 90cfd98bc48..486c95a548d 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -11,7 +11,6 @@ /* Foreign builtins. */ #include "rust_util.h" -#include "sync/rust_thread.h" #include "sync/lock_and_signal.h" #include "vg/valgrind.h" @@ -385,42 +384,6 @@ rust_signal_little_lock(lock_and_signal *lock) { lock->signal(); } -typedef void(startfn)(void*, void*); - -class raw_thread: public rust_thread { -public: - startfn *raw_start; - void *rust_fn; - void *rust_env; - - raw_thread(startfn *raw_start, void *rust_fn, void *rust_env) - : raw_start(raw_start), rust_fn(rust_fn), rust_env(rust_env) { } - - virtual void run() { - raw_start(rust_fn, rust_env); - } -}; - -extern "C" raw_thread* -rust_raw_thread_start(startfn *raw_start, void *rust_start, void *rust_env) { - assert(raw_start && rust_start); - raw_thread *thread = new raw_thread(raw_start, rust_start, rust_env); - thread->start(); - return thread; -} - -extern "C" void -rust_raw_thread_join(raw_thread *thread) { - assert(thread); - thread->join(); -} - -extern "C" void -rust_raw_thread_delete(raw_thread *thread) { - assert(thread); - delete thread; -} - #ifndef _WIN32 #include <sys/types.h> #include <dirent.h> diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 275966583d9..3b581e94be7 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -42,9 +42,6 @@ rust_signal_little_lock rust_wait_little_lock tdefl_compress_mem_to_heap tinfl_decompress_mem_to_heap -rust_raw_thread_start -rust_raw_thread_join -rust_raw_thread_delete swap_registers rust_readdir rust_opendir diff --git a/src/rt/sync/rust_thread.cpp b/src/rt/sync/rust_thread.cpp deleted file mode 100644 index 7223d187137..00000000000 --- a/src/rt/sync/rust_thread.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#include "rust_thread.h" -#include <limits.h> - -const size_t default_stack_sz = 1024*1024; - -rust_thread::rust_thread() : thread(0) { -} - -rust_thread::~rust_thread() { -} - -#if defined(__WIN32__) -static DWORD WINAPI -#elif defined(__GNUC__) -static void * -#else -#error "Platform not supported" -#endif -rust_thread_start(void *ptr) { - rust_thread *thread = (rust_thread *) ptr; - thread->run(); - return 0; -} - -void -rust_thread::start() { -#if defined(__WIN32__) - thread = CreateThread(NULL, default_stack_sz, rust_thread_start, this, 0, NULL); -#else - // PTHREAD_STACK_MIN of some system is larger than default size - // so we check stack_sz to prevent assertion failure. - size_t stack_sz = default_stack_sz; - if (stack_sz < PTHREAD_STACK_MIN) { - stack_sz = PTHREAD_STACK_MIN; - } - pthread_attr_t attr; - CHECKED(pthread_attr_init(&attr)); - CHECKED(pthread_attr_setstacksize(&attr, stack_sz)); - CHECKED(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE)); - CHECKED(pthread_create(&thread, &attr, rust_thread_start, (void *) this)); -#endif -} - -void -rust_thread::join() { -#if defined(__WIN32__) - if (thread) - WaitForSingleObject(thread, INFINITE); -#else - if (thread) - CHECKED(pthread_join(thread, NULL)); -#endif - thread = 0; -} diff --git a/src/rt/sync/rust_thread.h b/src/rt/sync/rust_thread.h deleted file mode 100644 index 257eefceb43..00000000000 --- a/src/rt/sync/rust_thread.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#ifndef RUST_THREAD_H -#define RUST_THREAD_H - -#include "rust_globals.h" - -/** - * Thread utility class. Derive and implement your own run() method. - */ -class rust_thread { - private: -#if defined(__WIN32__) - HANDLE thread; -#else - pthread_t thread; -#endif - public: - - rust_thread(); - virtual ~rust_thread(); - - void start(); - - virtual void run() = 0; - - void join(); -}; - -#endif /* RUST_THREAD_H */ |
