summaryrefslogtreecommitdiff
path: root/includes/Local.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-03 14:48:05 -0700
committerPixel <pixel@nobis-crew.org>2011-10-03 14:48:05 -0700
commit342b273234405ab76dc159d2e402bfb1ddfa1d8f (patch)
treef10d6857960313d6fc3b0aaa325ed46b8ad481fb /includes/Local.h
First commit - very basic features.
Diffstat (limited to 'includes/Local.h')
-rw-r--r--includes/Local.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/includes/Local.h b/includes/Local.h
new file mode 100644
index 0000000..f3b7250
--- /dev/null
+++ b/includes/Local.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <Main.h>
+
+namespace Balau {
+
+class TLSManager {
+ public:
+ virtual void * getTLS();
+ virtual void * setTLS(void * val);
+};
+
+extern TLSManager * tlsManager;
+
+class Local : public AtStart {
+ public:
+ static int getSize() { return s_size; }
+ protected:
+ Local() : AtStart(0) { }
+ void * getGlobal() { return m_globals[m_idx]; }
+ void * getLocal() { return reinterpret_cast<void **>(getTLS())[m_idx]; }
+ void * get() { if (getTLS()) { void * l = getLocal(); return l ? l : getGlobal(); } else return getGlobal(); }
+ void setGlobal(void * obj) { m_globals[m_idx] = obj; }
+ void setLocal(void * obj) { void * r = getTLS(); reinterpret_cast<void **>(r)[m_idx] = obj; }
+ void set(void * obj) { void * r = getTLS(); if (r) setGlobal(obj); else setLocal(obj); }
+ int getIndex() { return m_idx; }
+ private:
+ static void * create() { void * r = malloc(s_size * sizeof(void *)); setTLS(r); return r; }
+ static void * getTLS() { return tlsManager->getTLS(); }
+ static void * setTLS(void * val) { return tlsManager->setTLS(val); }
+ virtual void doStart();
+ int m_idx;
+ static int s_size;
+ static void ** m_globals;
+};
+
+};