You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/01/03 03:38:54 UTC

svn commit: r492023 - in /incubator/tuscany/cpp/sca/runtime/core/src: Makefile.am tuscany/sca/util/ThreadLocal.cpp tuscany/sca/util/ThreadLocal.h

Author: jsdelfino
Date: Tue Jan  2 18:38:54 2007
New Revision: 492023

URL: http://svn.apache.org/viewvc?view=rev&rev=492023
Log:
Adding a portable implementation of a ThreadLocal variable.

Added:
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp   (with props)
    incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h   (with props)
Modified:
    incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am

Modified: incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am?view=diff&rev=492023&r1=492022&r2=492023
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am (original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am Tue Jan  2 18:38:54 2007
@@ -65,6 +65,7 @@
 tuscany/sca/util/LogWriter.cpp \
 tuscany/sca/util/Mutex.cpp \
 tuscany/sca/util/SDOUtils.cpp \
+tuscany/sca/util/ThreadLocal.cpp \
 tuscany/sca/util/Utils.cpp
 
 libtuscany_sca_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo

Added: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp?view=auto&rev=492023
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp (added)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp Tue Jan  2 18:38:54 2007
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *   
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#if defined(WIN32)  || defined (_WINDOWS)
+#pragma warning(disable: 4786)
+#else
+#include "tuscany_sca_config.h"
+#endif
+
+#include <errno.h>
+
+#include <sstream>
+
+#include "tuscany/sca/util/ThreadLocal.h"
+#include "tuscany/sca/util/Utils.h"
+#include "tuscany/sca/util/Logging.h"
+#include "tuscany/sca/core/Exceptions.h"
+
+using namespace std;
+
+
+namespace tuscany
+{
+    namespace sca
+    {
+        namespace util
+        {
+            ThreadLocal::ThreadLocal()
+            {
+                logentry();
+#if defined(WIN32)  || defined (_WINDOWS)
+#else
+                int rc = pthread_key_create(&key, NULL);
+                if (rc)
+                {
+                    ostringstream msg;
+                    msg << "Failed to create thread local key, errno: " << errno;
+                    throwException(TuscanyRuntimeException, msg.str().c_str());
+                }
+#endif             
+            }
+            
+            ThreadLocal::~ThreadLocal()
+            {
+                logentry();
+#if defined(WIN32)  || defined (_WINDOWS)
+#else
+                int rc = pthread_key_delete(key);
+                if (rc) {
+                    ostringstream msg;
+                    msg << "Failed to destroy thread local key, errno: " << errno;
+                    throwException(TuscanyRuntimeException, msg.str().c_str());
+                }
+#endif             
+            }
+            
+            void ThreadLocal::setValue(const void* value)
+            {
+                logentry();
+#if defined(WIN32)  || defined (_WINDOWS)
+#else
+                int rc = pthread_setspecific(key, value);
+                if (rc) {
+                    ostringstream msg;
+                    msg << "Failed to set thread local value, errno: " << errno;
+                    throwException(TuscanyRuntimeException, msg.str().c_str());
+                }
+#endif             
+            }    
+        
+            void* ThreadLocal::getValue() const
+            {
+                logentry();
+#if defined(WIN32)  || defined (_WINDOWS)
+#else
+                return pthread_getspecific(key);
+#endif             
+            }    
+        
+        } // End namespace util
+    } // End namespace sca
+} // End namespace tuscany

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h?view=auto&rev=492023
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h (added)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h Tue Jan  2 18:38:54 2007
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *   
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_sca_util_threadlocal_h
+#define tuscany_sca_util_threadlocal_h
+
+#if defined(WIN32)  || defined (_WINDOWS)
+#include <windows.h> 
+#else
+#include <pthread.h>
+#endif
+
+#include "tuscany/sca/export.h"
+
+
+namespace tuscany
+{
+    namespace sca
+    {
+        namespace util
+        {
+            /**
+             * Information about shared libraries and methods to 
+             * access these shared libraries.
+             */
+            class SCA_API ThreadLocal
+            {
+            public:
+                /** 
+                 * Constructor.
+                 */
+                ThreadLocal();
+    
+                /**
+                 * Destructor.
+                 */ 
+                virtual ~ThreadLocal();
+    
+                /**
+                 * Set the ThreadLocal value.
+                 */ 
+                void setValue(const void *value);
+
+                /**
+                 * Get the ThreadLocal value.
+                 */ 
+                void* getValue() const;
+
+            private:
+    
+                /**
+                 * Handle to the thread local key.
+                 */ 
+#if defined(WIN32)  || defined (_WINDOWS)
+#else
+                pthread_key_t key;
+#endif
+    
+            };
+                
+        } // End namespace util
+    } // End namespace sca
+} // End namespace tuscany
+
+#endif // tuscany_sca_util_threadlocal_h

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/ThreadLocal.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org