Permalink
Browse files

src: add missing files

  • Loading branch information...
1 parent d94b3cf commit 84445468c8ff255c70bd3e8bdf71a29649a2f15d @indutny committed Dec 8, 2012
Showing with 76 additions and 0 deletions.
  1. +44 −0 src/isolate.cc
  2. +32 −0 src/isolate.h
View
@@ -0,0 +1,44 @@
+#include "isolate.h"
+
+#include <pthread.h>
+#include <stdlib.h> // abort
+#include <assert.h> // assert
+
+namespace candor {
+namespace internal {
+
+static pthread_once_t isolate_once = PTHREAD_ONCE_INIT;
+static pthread_key_t isolate_key;
+
+IsolateData::IsolateData() : isolate(NULL), zone(NULL) {
+}
+
+
+IsolateData::~IsolateData() {
+ pthread_setspecific(isolate_key, NULL);
+}
+
+
+void IsolateData::Init() {
+ if (pthread_key_create(&isolate_key, NULL)) {
+ abort();
+ }
+}
+
+
+IsolateData* IsolateData::GetCurrent() {
+ if (pthread_once(&isolate_once, IsolateData::Init))
+ abort();
+
+ IsolateData* data =
+ reinterpret_cast<IsolateData*>(pthread_getspecific(isolate_key));
+ if (data == NULL) {
+ data = new IsolateData();
+ pthread_setspecific(isolate_key, data);
+ }
+
+ return data;
+}
+
+} // namespace internal
+} // namespace candor
View
@@ -0,0 +1,32 @@
+#ifndef _SRC_ISOLATE_H_
+#define _SRC_ISOLATE_H_
+
+namespace candor {
+
+// Forward declaratons
+class Isolate;
+
+namespace internal {
+
+// Forward declarations
+class Zone;
+
+class IsolateData {
+ public:
+ ~IsolateData();
+
+ static IsolateData* GetCurrent();
+
+ Isolate* isolate;
+ Zone* zone;
+
+ protected:
+ IsolateData();
+
+ static void Init();
+};
+
+} // namespace internal
+} // namespace candor
+
+#endif // _SRC_ISOLATE_H_

0 comments on commit 8444546

Please sign in to comment.