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/02 07:22:24 UTC
svn commit: r491752 - in /incubator/tuscany/cpp/sca/runtime/core/src:
Makefile.am tuscany/sca/util/Mutex.cpp tuscany/sca/util/Mutex.h
Author: jsdelfino
Date: Mon Jan 1 22:22:23 2007
New Revision: 491752
URL: http://svn.apache.org/viewvc?view=rev&rev=491752
Log:
Added a Mutex class that we can use to protect critical code sections in a multithreaded environment.
Added:
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp (with props)
incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.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=491752&r1=491751&r2=491752
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am (original)
+++ incubator/tuscany/cpp/sca/runtime/core/src/Makefile.am Mon Jan 1 22:22:23 2007
@@ -63,6 +63,7 @@
tuscany/sca/util/Library.cpp \
tuscany/sca/util/Logger.cpp \
tuscany/sca/util/LogWriter.cpp \
+tuscany/sca/util/Mutex.cpp \
tuscany/sca/util/SDOUtils.cpp \
tuscany/sca/util/Utils.cpp
Added: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp?view=auto&rev=491752
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp (added)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp Mon Jan 1 22:22:23 2007
@@ -0,0 +1,109 @@
+/*
+ * 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/Mutex.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
+ {
+ Mutex::Mutex()
+ {
+ logentry();
+#if defined(WIN32) || defined (_WINDOWS)
+ InitializeCriticalSection(§ion);
+#else
+ int rc = pthread_mutex_init(&mutex, NULL);
+ if (rc)
+ {
+ ostringstream msg;
+ msg << "Failed to create mutex, errno: " << errno;
+ throwException(TuscanyRuntimeException, msg.str().c_str());
+ }
+#endif
+ }
+
+ Mutex::~Mutex()
+ {
+ logentry();
+#if defined(WIN32) || defined (_WINDOWS)
+ DeleteCriticalSection(§ion);
+#else
+ int rc = pthread_mutex_destroy(&mutex);
+ if (rc) {
+ ostringstream msg;
+ msg << "Failed to destroy mutex, errno: " << errno;
+ throwException(TuscanyRuntimeException, msg.str().c_str());
+ }
+#endif
+ }
+
+ void Mutex::lock()
+ {
+ logentry();
+#if defined(WIN32) || defined (_WINDOWS)
+ EnterCriticalSection(§ion);
+#else
+ int rc = pthread_mutex_lock(&mutex);
+ if (rc) {
+ ostringstream msg;
+ msg << "Failed to lock mutex, errno: " << errno;
+ throwException(TuscanyRuntimeException, msg.str().c_str());
+ }
+#endif
+ }
+
+ void Mutex::unlock()
+ {
+ logentry();
+#if defined(WIN32) || defined (_WINDOWS)
+ LeaveCriticalSection(§ion);
+#else
+ int rc = pthread_mutex_unlock(&mutex);
+ if (rc) {
+ ostringstream msg;
+ msg << "Failed to unlock mutex, errno: " << errno;
+ throwException(TuscanyRuntimeException, msg.str().c_str());
+ }
+#endif
+ }
+
+ } // End namespace util
+ } // End namespace sca
+} // End namespace tuscany
Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.h?view=auto&rev=491752
==============================================================================
--- incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.h (added)
+++ incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.h Mon Jan 1 22:22:23 2007
@@ -0,0 +1,87 @@
+/*
+ * 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_mutex_h
+#define tuscany_sca_util_mutex_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 Mutex
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ Mutex();
+
+ /**
+ * Destructor.
+ */
+ virtual ~Mutex();
+
+ Mutex(const Mutex& lib);
+ Mutex& operator=(const Mutex& mutex);
+
+ /**
+ * Lock the mutex.
+ */
+ void lock();
+
+ /**
+ * Unlock the mutex.
+ */
+ void unlock();
+
+ private:
+
+ /**
+ * Handle to the mutex.
+ */
+#if defined(WIN32) || defined (_WINDOWS)
+ CRITICAL_SECTION section;
+#else
+ pthread_mutex_t mutex;
+#endif
+
+ };
+
+ } // End namespace util
+ } // End namespace sca
+} // End namespace tuscany
+
+#endif // tuscany_sca_util_mutex_h
Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/cpp/sca/runtime/core/src/tuscany/sca/util/Mutex.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