OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #ifndef SRC_VM_THREAD_LK_H_ | 5 #ifndef SRC_VM_THREAD_LK_H_ |
6 #define SRC_VM_THREAD_LK_H_ | 6 #define SRC_VM_THREAD_LK_H_ |
7 | 7 |
8 #ifndef SRC_VM_THREAD_H_ | 8 #ifndef SRC_VM_THREAD_H_ |
9 #error "Don't include thread_lk.h directly, include thread.h." | 9 #error "Don't include thread_lk.h directly, include thread.h." |
10 #endif | 10 #endif |
11 | 11 |
12 #include <kernel/thread.h> | 12 #include <kernel/thread.h> |
13 | 13 |
14 namespace fletch { | 14 namespace dartino { |
15 | 15 |
16 // A ThreadIdentifier represents a thread identifier for a thread. | 16 // A ThreadIdentifier represents a thread identifier for a thread. |
17 // The ThreadIdentifier does not own the underlying OS handle. | 17 // The ThreadIdentifier does not own the underlying OS handle. |
18 // Thread handles can be used for referring to threads and testing equality. | 18 // Thread handles can be used for referring to threads and testing equality. |
19 class ThreadIdentifier { | 19 class ThreadIdentifier { |
20 public: | 20 public: |
21 ThreadIdentifier() : thread_(get_current_thread()) {} | 21 ThreadIdentifier() : thread_(get_current_thread()) {} |
22 | 22 |
23 // Test for thread running. | 23 // Test for thread running. |
24 bool IsSelf() const { return thread_ == get_current_thread(); } | 24 bool IsSelf() const { return thread_ == get_current_thread(); } |
25 | 25 |
26 void Join() { | 26 void Join() { |
27 int retcode; | 27 int retcode; |
28 thread_join(thread_, &retcode, INFINITE_TIME); | 28 thread_join(thread_, &retcode, INFINITE_TIME); |
29 } | 29 } |
30 | 30 |
31 private: | 31 private: |
32 friend class Thread; | 32 friend class Thread; |
33 | 33 |
34 explicit ThreadIdentifier(thread_t* thread) : thread_(thread) {} | 34 explicit ThreadIdentifier(thread_t* thread) : thread_(thread) {} |
35 | 35 |
36 thread_t* thread_; | 36 thread_t* thread_; |
37 }; | 37 }; |
38 | 38 |
39 } // namespace fletch | 39 } // namespace dartino |
40 | 40 |
41 #endif // SRC_VM_THREAD_LK_H_ | 41 #endif // SRC_VM_THREAD_LK_H_ |
OLD | NEW |