#include <Pegasus/Common/Linkage.h>
#include <Pegasus/Common/List.h>
#include <Pegasus/Common/Condition.h>
+#include <Pegasus/Common/IPCExceptions.h>
PEGASUS_NAMESPACE_BEGIN
{
_modules.insert_front(new_mod.get());
}
- catch (IPCException&)
+ catch (...)
{
result = async_results::INTERNAL_ERROR;
new_mod.reset();
// empty out the queue
while (1)
{
- AsyncOpNode *operation;
+ AsyncOpNode* operation = 0;
try
{
operation = service->_routed_ops.dequeue();
}
- catch (IPCException&)
+ catch (...)
{
break;
}
ThreadType _owner;
};
-class PEGASUS_COMMON_LINKAGE WaitFailed: public IPCException
-{
-public:
- WaitFailed(ThreadType owner) : IPCException(owner) {}
-private:
- WaitFailed();
-};
-
class PEGASUS_COMMON_LINKAGE ListClosed: public IPCException
{
public:
// empty out the queue
while (1)
{
- AsyncOpNode *operation;
+ AsyncOpNode* operation = 0;
try
{
operation = service->_incoming.dequeue();
}
- catch (IPCException&)
+ catch (...)
{
break;
}
#include "Time.h"
#include "PegasusAssert.h"
#include "Once.h"
+#include "Exception.h"
+#include "System.h"
+
+#define MUTEX_LOCK_FAILED_KEY "Common.InternalException.MUTEX_LOCK_FAILED"
+#define MUTEX_LOCK_FAILED_MSG "Failed to acquire mutex lock: $0"
PEGASUS_NAMESPACE_BEGIN
{
PEGASUS_DEBUG_ASSERT(_magic);
- switch (pthread_mutex_lock(&_rep.mutex))
+ int r = pthread_mutex_lock(&_rep.mutex);
+
+ if (r == 0)
{
- case 0:
#if defined(PEGASUS_DEBUG)
- _rep.count++;
+ _rep.count++;
#endif
- break;
+ }
+ else
+ {
+ if (r != -1)
+ {
+ // Special behavior for Single UNIX Specification, Version 3
+ errno = r;
+ }
- default:
- throw WaitFailed(Threads::self());
+ throw Exception(MessageLoaderParms(
+ MUTEX_LOCK_FAILED_KEY,
+ MUTEX_LOCK_FAILED_MSG,
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
}
PEGASUS_DEBUG_ASSERT(_magic);
int r = pthread_mutex_trylock(&_rep.mutex);
- if (r == -1)
- r=errno;
if (r == 0)
{
return true;
}
- if (r == EBUSY)
+ if (r != -1)
+ {
+ // Special behavior for Single UNIX Specification, Version 3
+ errno = r;
+ }
+
+ if (errno == EBUSY)
{
return false;
}
- throw WaitFailed(Threads::self());
+ throw Exception(MessageLoaderParms(
+ MUTEX_LOCK_FAILED_KEY,
+ MUTEX_LOCK_FAILED_MSG,
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
Boolean Mutex::timed_lock(Uint32 milliseconds)
{
- PEGASUS_DEBUG_ASSERT(_magic);
-
struct timeval now;
struct timeval finish;
struct timeval remaining;
finish.tv_usec = usec % 1000000;
}
- for (;;)
+ while (!try_lock())
{
- int r=pthread_mutex_trylock(&_rep.mutex);
- if (r == -1)
- r = errno;
+ gettimeofday(&now, NULL);
- if (r == 0)
+ if (Time::subtract(&remaining, &finish, &now))
{
- break;
+ return false;
}
- else if (r == EBUSY)
- {
- gettimeofday(&now, NULL);
-
- if (Time::subtract(&remaining, &finish, &now))
- {
- return false;
- }
- Threads::yield();
- }
- else
- {
- throw WaitFailed(Threads::self());
- }
+ Threads::yield();
}
-#if defined(PEGASUS_DEBUG)
- _rep.count++;
-#endif
return true;
}
DWORD rc = WaitForSingleObject(_rep.handle, INFINITE);
if (rc == WAIT_FAILED)
- throw WaitFailed(Threads::self());
+ {
+ throw Exception(MessageLoaderParms(
+ MUTEX_LOCK_FAILED_KEY,
+ MUTEX_LOCK_FAILED_MSG,
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
+ }
_rep.count++;
}
if (rc == WAIT_FAILED)
{
- throw WaitFailed(Threads::self());
+ throw Exception(MessageLoaderParms(
+ MUTEX_LOCK_FAILED_KEY,
+ MUTEX_LOCK_FAILED_MSG,
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
_rep.count++;
return false;
if (rc == WAIT_FAILED)
- throw WaitFailed(Threads::self());
+ {
+ throw Exception(MessageLoaderParms(
+ MUTEX_LOCK_FAILED_KEY,
+ MUTEX_LOCK_FAILED_MSG,
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
+ }
_rep.count++;
return true;
#include <Pegasus/Common/Config.h>
#include <Pegasus/Common/Linkage.h>
-#include <Pegasus/Common/IPCExceptions.h>
#include <Pegasus/Common/Magic.h>
#include <Pegasus/Common/Threads.h>
#include "Time.h"
#include "PegasusAssert.h"
#include "Threads.h"
+#include "Exception.h"
+#include "System.h"
PEGASUS_NAMESPACE_BEGIN
void ReadWriteSem::waitRead()
{
- if (pthread_rwlock_rdlock(&_rwlock.rwlock) != 0)
+ int r = pthread_rwlock_rdlock(&_rwlock.rwlock);
+
+ if (r != 0)
{
- throw WaitFailed(Threads::self());
+ if (r != -1)
+ {
+ // Special behavior for Single UNIX Specification, Version 3
+ errno = r;
+ }
+
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.READ_LOCK_FAILED",
+ "Failed to acquire read lock: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
}
void ReadWriteSem::waitWrite()
{
- if (pthread_rwlock_wrlock(&_rwlock.rwlock) != 0)
+ int r = pthread_rwlock_wrlock(&_rwlock.rwlock);
+
+ if (r != 0)
{
- throw WaitFailed(Threads::self());
+ if (r != -1)
+ {
+ // Special behavior for Single UNIX Specification, Version 3
+ errno = r;
+ }
+
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.WRITE_LOCK_FAILED",
+ "Failed to acquire write lock: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
}
{
_rwlock._internal_lock.lock();
}
- catch (IPCException &)
+ catch (...)
{
PEGASUS_ASSERT(0);
}
~ReadWriteSem();
- // @exception WaitFailed
void waitRead();
- // @exception WaitFailed
void waitWrite();
void unlockRead();
//%/////////////////////////////////////////////////////////////////////////////
#include <Pegasus/Common/Time.h>
-#include <Pegasus/Common/IPCExceptions.h>
+#include <Pegasus/Common/Exception.h>
+#include <Pegasus/Common/System.h>
#include "Semaphore.h"
PEGASUS_NAMESPACE_BEGIN
if (initial > PEGASUS_SEM_VALUE_MAX)
{
- _count = PEGASUS_SEM_VALUE_MAX - 1;
+ _rep.count = PEGASUS_SEM_VALUE_MAX - 1;
}
else
{
- _count = initial;
+ _rep.count = initial;
}
_rep.owner = Threads::self();
// Wait until the semaphore count is > 0, then atomically release
// <lock_> and wait for <count_nonzero_> to be signaled.
- while (_count == 0)
+ while (_rep.count == 0)
{
pthread_cond_wait(&_rep.cond, &_rep.mutex);
}
_rep.waiters--;
// Decrement the semaphore's count.
- _count--;
+ _rep.count--;
// Since we push an unlock onto the cleanup stack
// We will pop it off to release the mutex when leaving the critical
waittime.tv_nsec = (waittime.tv_nsec % 1000000); // the "seconds" part
waittime.tv_nsec = waittime.tv_nsec * 1000; // convert to nanoseconds
- while ((_count == 0) && !timedOut)
+ while ((_rep.count == 0) && !timedOut)
{
int r = pthread_cond_timedwait(&_rep.cond, &_rep.mutex, &waittime);
if (((r == -1 && errno == ETIMEDOUT) || (r == ETIMEDOUT)) &&
- _count == 0)
+ _rep.count == 0)
{
timedOut = true;
}
if (!timedOut)
{
// Decrement the semaphore's count.
- _count--;
+ _rep.count--;
}
// Decrement the waiters count.
}
// Increment the semaphore's count.
- _count++;
+ _rep.count++;
pthread_mutex_unlock(&_rep.mutex);
}
-// return the count of the semaphore
-int Semaphore::count() const
-{
- return _count;
-}
-
#endif /* PEGASUS_USE_PTHREAD_SEMAPHORE */
//==============================================================================
_rep.owner = Threads::self();
if (sem_init(&_rep.sem, 0, initial) == -1)
{
- throw(IPCException(_rep.owner));
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.SEMAPHORE_INIT_FAILED",
+ "Semaphore initialization failed: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
}
if (errno != EINTR)
{
- throw WaitFailed(_rep.owner);
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.SEMAPHORE_WAIT_FAILED",
+ "Semaphore wait failed: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
// keep going if above conditions fail
if (retcode == -1 && errno != EAGAIN)
{
- throw WaitFailed(Threads::self());
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.SEMAPHORE_WAIT_FAILED",
+ "Semaphore wait failed: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
gettimeofday(&now, NULL);
{
if (sem_post(&_rep.sem) == -1)
{
- throw(IPCException(_rep.owner));
- }
-}
-
-// return the count of the semaphore
-int Semaphore::count() const
-{
- if (sem_getvalue(&_rep.sem, &_count) == -1)
- {
- throw(IPCException(_rep.owner));
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.SEMAPHORE_SIGNAL_FAILED",
+ "Failed to signal semaphore: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
- return _count;
}
#endif /* PEGASUS_USE_POSIX_SEMAPHORE */
{
initial = PEGASUS_SEM_VALUE_MAX - 1;
}
- _count = initial;
_rep.owner = Threads::self();
_rep.sem = CreateSemaphore(NULL, initial, PEGASUS_SEM_VALUE_MAX, NULL);
}
void Semaphore::wait()
{
DWORD errorcode = WaitForSingleObject(_rep.sem, INFINITE);
- if (errorcode != WAIT_FAILED)
- {
- _count--;
- }
- else
+ if (errorcode == WAIT_FAILED)
{
- throw WaitFailed(Threads::self());
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.SEMAPHORE_WAIT_FAILED",
+ "Semaphore wait failed: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
}
if (errorcode == WAIT_FAILED)
{
- throw WaitFailed(Threads::self());
+ throw Exception(MessageLoaderParms(
+ "Common.InternalException.SEMAPHORE_WAIT_FAILED",
+ "Semaphore wait failed: $0",
+ PEGASUS_SYSTEM_ERRORMSG_NLS));
}
- _count--;
return true;
}
// increment the count of the semaphore
void Semaphore::signal()
{
- _count++;
ReleaseSemaphore(_rep.sem, 1, NULL);
}
-// return the count of the semaphore
-int Semaphore::count() const
-{
- return _count;
-}
-
#endif /* PEGASUS_USE_WINDOWS_SEMAPHORE */
PEGASUS_NAMESPACE_END
#if defined(PEGASUS_USE_PTHREAD_SEMAPHORE)
struct SemaphoreRep
{
+ int count;
Uint32 waiters;
pthread_mutex_t mutex;
pthread_cond_t cond;
/** Blocks until this Semaphore is in a signalled state. Interrupt
signals are ignored.
- @exception WaitFailed If unable to block on the semaphore.
+ @exception Exception If unable to block on the semaphore.
*/
void wait();
@param milliseconds The time interval to wait (in milliseconds).
@return True if the Semaphore has a non-zero count or is signalled
during the specified time interval, false otherwise.
- @exception TimeOut If the wait operation does not succeed within
- the specified time interval.
*/
Boolean time_wait(Uint32 milliseconds);
*/
void signal();
- /** Return the count of the semaphore.
- */
- int count() const;
-
private:
Semaphore(const Semaphore& x); // Unimplemented
Semaphore& operator=(const Semaphore& x); // Unimplemented
- mutable int _count;
mutable SemaphoreRep _rep;
friend class Condition;
};
{
cu.reset(_cleanup.remove_front());
}
- catch (IPCException &)
+ catch (...)
{
PEGASUS_ASSERT(0);
}
{
cleanup_pop(true);
}
- catch (IPCException &)
+ catch (...)
{
PEGASUS_ASSERT(0);
break;
{
my_handle->dereference_tsd();
}
- catch(IPCException& e)
+ catch(...)
{
- e = e;
cout << "exception dereferencing the tsd " << endl;
abort();
}
{
my_handle->cleanup_push(exit_one , my_handle );
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to push cleanup handler" << endl;
abort();
my_handle->cleanup_push(exit_two , my_handle );
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to push cleanup handler" << endl;
abort();
256, my_storage);
#endif
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to put local storage: "
<< Threads::id(myself).buffer << endl;
{
my_parm->waitRead();
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to get a read lock" << endl;
abort();
{
my_handle->cleanup_push(deref , my_handle );
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to push cleanup handler" << endl;
abort();
my_handle->reference_tsd(keys[i % 4]);
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to reference local storage" << endl;
abort();
{
my_handle->cleanup_pop(true);
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to pop cleanup handler" << endl;
abort();
{
my_parm->unlockRead();
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to release a read lock" << endl;
abort();
{
my_handle->delete_tsd(keys[i % 4]);
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to delete local storage: "
<< Threads::id(myself).buffer << endl;
{
my_parm->waitWrite();
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to get a write lock" << endl;
abort();
{
my_parm->unlockWrite();
}
- catch (IPCException&)
+ catch (...)
{
cout << "Exception while trying to release a write lock" << endl;
abort();
#include <Pegasus/Common/Logger.h>
#include <Pegasus/Common/System.h>
#include <Pegasus/Common/Tracer.h>
-#include <Pegasus/Common/IPCExceptions.h>
#include <Pegasus/Config/ConfigManager.h>
// at any given time
//
- try
- {
- if (!_mutex->timed_lock(_MUTEX_TIMEOUT))
- {
- throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
- MessageLoaderParms(
- "Security.UserManager.UserFileHandler.TIMEOUT",
- "Timed out while attempting to perform the requested "
- "operation. Try the operation again."));
- }
- }
- catch (WaitFailed&)
+ if (!_mutex->timed_lock(_MUTEX_TIMEOUT))
{
- // ATTN: This is an error case, not a timeout scenario
throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
MessageLoaderParms(
"Security.UserManager.UserFileHandler.TIMEOUT",
Common.InternalException.UNAUTHORIZED_ACCESS:string {"PGS00233: Unauthorized access."}
+ /**
+ * @note PGS00234:
+ * Substitution {0} is an error message string
+ */
+ Common.InternalException.MUTEX_LOCK_FAILED:string {"PGS00234: Failed to acquire mutex lock: {0}"}
+
+ /**
+ * @note PGS00235:
+ * Substitution {0} is an error message string
+ */
+ Common.InternalException.READ_LOCK_FAILED:string {"PGS00235: Failed to acquire read lock: {0}"}
+
+ /**
+ * @note PGS00236:
+ * Substitution {0} is an error message string
+ */
+ Common.InternalException.WRITE_LOCK_FAILED:string {"PGS00236: Failed to acquire write lock: {0}"}
+
+ /**
+ * @note PGS00237:
+ * Substitution {0} is an error message string
+ */
+ Common.InternalException.SEMAPHORE_INIT_FAILED:string {"PGS00237: Semaphore initialization failed: {0}"}
+
+ /**
+ * @note PGS00238:
+ * Substitution {0} is an error message string
+ */
+ Common.InternalException.SEMAPHORE_WAIT_FAILED:string {"PGS00238: Semaphore wait failed: {0}"}
+
+ /**
+ * @note PGS00239:
+ * Substitution {0} is an error message string
+ */
+ Common.InternalException.SEMAPHORE_SIGNAL_FAILED:string {"PGS00239: Failed to signal semaphore: {0}"}
+
// ==========================================================
// Messages for Exception