OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
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 file. | |
4 | |
5 #include "vm/isolate.h" | |
6 | |
7 #include <errno.h> | |
8 #include <pthread.h> | |
9 | |
10 #include "platform/assert.h" | |
11 | |
12 namespace dart { | |
13 | |
14 #define VALIDATE_PTHREAD_RESULT(result) \ | |
15 if (result != 0) { \ | |
16 FATAL2("pthread error: %d (%s)", result, strerror(result)); \ | |
17 } | |
18 | |
19 | |
20 // The single pthread key which stores all the thread local data for a | |
21 // thread. Since an Isolate is the central repository for storing all | |
22 // isolate specific information a single pthread key is sufficient. | |
23 pthread_key_t isolate_key = PTHREAD_KEY_UNSET; | |
24 | |
25 | |
26 void Isolate::SetCurrent(Isolate* current) { | |
27 ASSERT(isolate_key != PTHREAD_KEY_UNSET); | |
28 int result = pthread_setspecific(isolate_key, current); | |
29 VALIDATE_PTHREAD_RESULT(result); | |
30 } | |
31 | |
32 | |
33 void Isolate::InitOnce() { | |
34 ASSERT(isolate_key == PTHREAD_KEY_UNSET); | |
35 int result = pthread_key_create(&isolate_key, NULL); | |
36 // Make sure creating a key was successful. | |
37 VALIDATE_PTHREAD_RESULT(result); | |
38 ASSERT(isolate_key != PTHREAD_KEY_UNSET); | |
39 create_callback_ = NULL; | |
40 } | |
41 | |
42 } // namespace dart | |
OLD | NEW |