about summary refs log tree commit diff
path: root/src/rt/sync
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-02-09 14:24:19 -0800
committerBrian Anderson <banderson@mozilla.com>2012-02-09 19:00:16 -0800
commit421c8db14430011d40f8f8499ca4aefbcc26d07e (patch)
treec6cc3269f99dd70e83a10335ac6bc8a6aa64c255 /src/rt/sync
parent8ad9cf8087f2d1f1badfb7c8616c0b11cc4aa6db (diff)
downloadrust-421c8db14430011d40f8f8499ca4aefbcc26d07e.tar.gz
rust-421c8db14430011d40f8f8499ca4aefbcc26d07e.zip
rt: Move rust_thread to its own files
Diffstat (limited to 'src/rt/sync')
-rw-r--r--src/rt/sync/rust_thread.cpp43
-rw-r--r--src/rt/sync/rust_thread.h26
-rw-r--r--src/rt/sync/sync.cpp41
-rw-r--r--src/rt/sync/sync.h22
4 files changed, 69 insertions, 63 deletions
diff --git a/src/rt/sync/rust_thread.cpp b/src/rt/sync/rust_thread.cpp
new file mode 100644
index 00000000000..49daaa5c96d
--- /dev/null
+++ b/src/rt/sync/rust_thread.cpp
@@ -0,0 +1,43 @@
+#include "globals.h"
+#include "rust_thread.h"
+
+rust_thread::rust_thread() : thread(0) {
+}
+
+#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, 0, rust_thread_start, this, 0, NULL);
+#else
+   pthread_attr_t attr;
+   pthread_attr_init(&attr);
+   pthread_attr_setstacksize(&attr, 1024 * 1024);
+   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+   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)
+     pthread_join(thread, NULL);
+#endif
+   thread = 0;
+}
diff --git a/src/rt/sync/rust_thread.h b/src/rt/sync/rust_thread.h
new file mode 100644
index 00000000000..1c27d1b6597
--- /dev/null
+++ b/src/rt/sync/rust_thread.h
@@ -0,0 +1,26 @@
+#ifndef RUST_THREAD_H
+#define RUST_THREAD_H
+
+/**
+ * Thread utility class. Derive and implement your own run() method.
+ */
+class rust_thread {
+public:
+#if defined(__WIN32__)
+    HANDLE thread;
+#else
+    pthread_t thread;
+#endif
+    rust_thread();
+    void start();
+
+    virtual void run() {
+        return;
+    }
+
+    void join();
+
+    virtual ~rust_thread() {}   // quiet the compiler
+};
+
+#endif /* RUST_THREAD_H */
diff --git a/src/rt/sync/sync.cpp b/src/rt/sync/sync.cpp
index 31162d35b03..3bf37986161 100644
--- a/src/rt/sync/sync.cpp
+++ b/src/rt/sync/sync.cpp
@@ -18,44 +18,3 @@ void sync::sleep(size_t timeout_in_ms) {
     usleep(timeout_in_ms * 1000);
 #endif
 }
-
-rust_thread::rust_thread() : thread(0) {
-}
-
-#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, 0, rust_thread_start, this, 0, NULL);
-#else
-   pthread_attr_t attr;
-   pthread_attr_init(&attr);
-   pthread_attr_setstacksize(&attr, 1024 * 1024);
-   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-   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)
-     pthread_join(thread, NULL);
-#endif
-   thread = 0;
-}
diff --git a/src/rt/sync/sync.h b/src/rt/sync/sync.h
index 9c911e2c929..3bd36f5c566 100644
--- a/src/rt/sync/sync.h
+++ b/src/rt/sync/sync.h
@@ -33,26 +33,4 @@ public:
     }
 };
 
-/**
- * Thread utility class. Derive and implement your own run() method.
- */
-class rust_thread {
-public:
-#if defined(__WIN32__)
-    HANDLE thread;
-#else
-    pthread_t thread;
-#endif
-    rust_thread();
-    void start();
-
-    virtual void run() {
-        return;
-    }
-
-    void join();
-
-    virtual ~rust_thread() {}   // quiet the compiler
-};
-
 #endif /* SYNC_H */