summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/posix
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/sys/posix')
-rw-r--r--cpp/src/qpid/sys/posix/Condition.h10
-rw-r--r--cpp/src/qpid/sys/posix/Mutex.h26
-rw-r--r--cpp/src/qpid/sys/posix/Socket.cpp4
-rw-r--r--cpp/src/qpid/sys/posix/Thread.h8
-rw-r--r--cpp/src/qpid/sys/posix/check.h18
5 files changed, 40 insertions, 26 deletions
diff --git a/cpp/src/qpid/sys/posix/Condition.h b/cpp/src/qpid/sys/posix/Condition.h
index 1c8d1a80b1..86d6500ee9 100644
--- a/cpp/src/qpid/sys/posix/Condition.h
+++ b/cpp/src/qpid/sys/posix/Condition.h
@@ -52,15 +52,15 @@ class Condition
};
Condition::Condition() {
- QPID_POSIX_THROW_IF(pthread_cond_init(&condition, 0));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_cond_init(&condition, 0));
}
Condition::~Condition() {
- QPID_POSIX_THROW_IF(pthread_cond_destroy(&condition));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_cond_destroy(&condition));
}
void Condition::wait(Mutex& mutex) {
- QPID_POSIX_THROW_IF(pthread_cond_wait(&condition, &mutex.mutex));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_cond_wait(&condition, &mutex.mutex));
}
bool Condition::wait(Mutex& mutex, const AbsTime& absoluteTime){
@@ -75,11 +75,11 @@ bool Condition::wait(Mutex& mutex, const AbsTime& absoluteTime){
}
void Condition::notify(){
- QPID_POSIX_THROW_IF(pthread_cond_signal(&condition));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_cond_signal(&condition));
}
void Condition::notifyAll(){
- QPID_POSIX_THROW_IF(pthread_cond_broadcast(&condition));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_cond_broadcast(&condition));
}
}}
diff --git a/cpp/src/qpid/sys/posix/Mutex.h b/cpp/src/qpid/sys/posix/Mutex.h
index 4cf0c3a3b0..590fd14bd0 100644
--- a/cpp/src/qpid/sys/posix/Mutex.h
+++ b/cpp/src/qpid/sys/posix/Mutex.h
@@ -136,11 +136,11 @@ struct PODMutex
#define QPID_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
void PODMutex::lock() {
- QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_lock(&mutex));
}
void PODMutex::unlock() {
- QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_unlock(&mutex));
}
bool PODMutex::trylock() {
@@ -148,19 +148,19 @@ bool PODMutex::trylock() {
}
Mutex::Mutex() {
- QPID_POSIX_THROW_IF(pthread_mutex_init(&mutex, recursiveMutexattr));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_init(&mutex, recursiveMutexattr));
}
Mutex::~Mutex(){
- QPID_POSIX_THROW_IF(pthread_mutex_destroy(&mutex));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_destroy(&mutex));
}
void Mutex::lock() {
- QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_lock(&mutex));
}
void Mutex::unlock() {
- QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_mutex_unlock(&mutex));
}
bool Mutex::trylock() {
@@ -169,31 +169,31 @@ bool Mutex::trylock() {
RWlock::RWlock() {
- QPID_POSIX_THROW_IF(pthread_rwlock_init(&rwlock, recursiveRWlockattr));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_init(&rwlock, recursiveRWlockattr));
}
RWlock::~RWlock(){
- QPID_POSIX_THROW_IF(pthread_rwlock_destroy(&rwlock));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_destroy(&rwlock));
}
void RWlock::wlock() {
- QPID_POSIX_THROW_IF(pthread_rwlock_wrlock(&rwlock));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_wrlock(&rwlock));
}
void RWlock::rlock() {
- QPID_POSIX_THROW_IF(pthread_rwlock_rdlock(&rwlock));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_rdlock(&rwlock));
}
void RWlock::unlock() {
- QPID_POSIX_THROW_IF(pthread_rwlock_unlock(&rwlock));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_unlock(&rwlock));
}
void RWlock::trywlock() {
- QPID_POSIX_THROW_IF(pthread_rwlock_trywrlock(&rwlock));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_trywrlock(&rwlock));
}
void RWlock::tryrlock() {
- QPID_POSIX_THROW_IF(pthread_rwlock_tryrdlock(&rwlock));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_rwlock_tryrdlock(&rwlock));
}
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp
index 6e872c4fbc..ccb07bdafc 100644
--- a/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/cpp/src/qpid/sys/posix/Socket.cpp
@@ -231,6 +231,10 @@ std::string Socket::getPeerAddress() const
return impl->getName(false, true);
}
+int Socket::toFd() const {
+ return impl->fd;
+}
+
int toFd(const SocketPrivate* s)
{
return s->fd;
diff --git a/cpp/src/qpid/sys/posix/Thread.h b/cpp/src/qpid/sys/posix/Thread.h
index 631a5d5378..e199c0eef6 100644
--- a/cpp/src/qpid/sys/posix/Thread.h
+++ b/cpp/src/qpid/sys/posix/Thread.h
@@ -60,16 +60,16 @@ class Thread
Thread::Thread() : thread(0) {}
Thread::Thread(Runnable* runnable) {
- QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, runnable));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_create(&thread, NULL, runRunnable, runnable));
}
Thread::Thread(Runnable& runnable) {
- QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, &runnable));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_create(&thread, NULL, runRunnable, &runnable));
}
void Thread::join(){
if (thread != 0)
- QPID_POSIX_THROW_IF(pthread_join(thread, 0));
+ QPID_POSIX_ASSERT_THROW_IF(pthread_join(thread, 0));
}
long Thread::id() {
@@ -84,7 +84,7 @@ Thread Thread::current() {
void Thread::yield()
{
- QPID_POSIX_THROW_IF(pthread_yield());
+ QPID_POSIX_ASSERT_THROW_IF(pthread_yield());
}
diff --git a/cpp/src/qpid/sys/posix/check.h b/cpp/src/qpid/sys/posix/check.h
index 40aa0d4d27..5de8863345 100644
--- a/cpp/src/qpid/sys/posix/check.h
+++ b/cpp/src/qpid/sys/posix/check.h
@@ -23,16 +23,26 @@
*/
#include "qpid/Exception.h"
-
#include <cerrno>
+#include <assert.h>
-#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::strError(ERRNO)));
+#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::strError(ERRNO)))
/** THROW QPID_POSIX_ERROR(errno) if RESULT is less than zero */
#define QPID_POSIX_CHECK(RESULT) \
if ((RESULT) < 0) throw QPID_POSIX_ERROR((errno))
-/** Throw a posix error if errNo is non-zero */
+/** Throw a posix error if ERRNO is non-zero */
#define QPID_POSIX_THROW_IF(ERRNO) \
- if ((ERRNO) != 0) throw QPID_POSIX_ERROR((ERRNO))
+ do { int e=(ERRNO); if (e) throw QPID_POSIX_ERROR(e); } while(0)
+
+/** Same as _THROW_IF in a release build, but abort a debug build */
+#ifdef NDEBUG
+#define QPID_POSIX_ASSERT_THROW_IF(ERRNO) qpid_posix \
+ QPID_POSIX_THROW_IF(ERRNO)
+#else
+#define QPID_POSIX_ASSERT_THROW_IF(ERRNO) \
+ do { int e=(ERRNO); if (e) { errno=e; perror(0); assert(0); } } while(0)
+#endif
+
#endif /*!_posix_check_h*/