From 47e0bd403a04d26506f723ac44ee9ea0aa5d3ad5 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Tue, 5 Nov 2013 14:13:02 +0100 Subject: Move implementation for threads to Rust 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. Fixes #10162 --- src/rt/sync/rust_thread.cpp | 65 --------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 src/rt/sync/rust_thread.cpp (limited to 'src/rt/sync/rust_thread.cpp') 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#include "rust_thread.h" -#include - -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; -} -- cgit 1.4.1-3-g733a5