Skip to content

Commit 9688f79

Browse files
author
Herbert Koelman
committed
Merge branch 'iss-63' into develop
2 parents ae06d82 + 6afc3b5 commit 9688f79

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

include/pthread/sync_queue.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
#include <list> // std::list
1313

1414
#include "pthread/pthread.hpp"
15+
#if __cplusplus < 201103L
16+
#else
1517
#include <atomic>
18+
#endif
1619
#include <string>
1720

1821

@@ -92,9 +95,16 @@ namespace pthread {
9295
*/
9396
void set_max_size( size_t ms ){
9497
if (ms > 0){
98+
#if __cplusplus < 201103L
99+
pthread::lock_guard<pthread::mutex> lck(_mutex);
100+
#endif
95101
_max_size = ms;
96102
}else{
103+
#if __cplusplus < 201103L
104+
throw queue_exception("synchronized_queue's max size must be greater then 0.");
105+
#else
97106
throw queue_exception("synchronized_queue's max size must be greater then 0, max_size " + std::to_string(ms) + " is not.");
107+
#endif
98108
}
99109
}
100110

@@ -113,7 +123,11 @@ namespace pthread {
113123
pthread::condition_variable _not_empty_cv;
114124
pthread::condition_variable _not_full_cv;
115125
std::list<T> _items ;
126+
#if __cplusplus < 201103L
127+
int _max_size ;
128+
#else
116129
std::atomic<int> _max_size ;
130+
#endif
117131

118132
};
119133

@@ -166,7 +180,8 @@ namespace pthread {
166180

167181
#if __cplusplus < 201103L
168182
bool not_full = true;
169-
while ( ! (not_full = (_items.size() < _max_size)) && not_full_cv.wait(_mutex)){
183+
while ( ! (not_full = (_items.size() < _max_size))){
184+
_not_full_cv.wait(_mutex);
170185
}
171186
#else
172187
_not_full_cv.wait(_mutex,[this]{ return _items.size() < _max_size; });

tests/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3675,7 +3675,7 @@ OBJECTS=$OBJECTS
36753675
$as_echo_n "checking for specific $CXX compiler options... " >&6; }
36763676
case "$CXX" in
36773677
xlC_r | xlC)
3678-
CPPFLAGS="-qlanglvl=extended0x:decltype:static_assert:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
3678+
CPPFLAGS="-D__IBMCPP_TR1__ -qlanglvl=extended0x:decltype:static_assert:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
36793679
CFLAGS="-bh:5 -qmaxmem=-1 -q$BITS $CFLAGS"
36803680
CXXFLAGS="-g"
36813681
LDFLAGS="$LDFLAGS -brtl -bmaxdata:0x80000000"

tests/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ AC_SUBST(OBJECTS,$OBJECTS)
3939
AC_MSG_CHECKING([for specific $CXX compiler options])
4040
case "$CXX" in
4141
xlC_r | xlC)
42-
CPPFLAGS="-qlanglvl=extended0x:decltype:static_assert:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
42+
CPPFLAGS="-D__IBMCPP_TR1__ -qlanglvl=extended0x:decltype:static_assert:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
4343
CFLAGS="-bh:5 -qmaxmem=-1 -q$BITS $CFLAGS"
4444
CXXFLAGS="-g"
4545
LDFLAGS="$LDFLAGS -brtl -bmaxdata:0x80000000"

tests/synchronized_queue_tests.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <cstdio>
77
#include <iostream>
88
#include <string>
9-
#include <atomic>
109
#include <memory>
1110
#include <ctime>
1211

@@ -46,7 +45,12 @@ class message {
4645
unsigned long _number;
4746
};
4847

48+
#if __IBMCPP_TR1__
49+
typedef std::tr1::shared_ptr<message> message_ptr;
50+
#else
4951
typedef std::shared_ptr<message> message_ptr;
52+
#endif
53+
5054
typedef pthread::util::sync_queue<message_ptr> sync_message_queue;
5155

5256
class status {
@@ -82,7 +86,11 @@ class producer : public status, public pthread::abstract_thread {
8286
producer(sync_message_queue &queue): status(queue){
8387
};
8488

89+
#if __cplusplus < 201103L
90+
void run() throw() {
91+
#else
8592
void run() noexcept {
93+
#endif
8694
printf ("start producing %d messages\n", MESSAGES_TO_PRODUCE);
8795
for( auto x = MESSAGES_TO_PRODUCE; (x > 0) && running() ; x-- ){
8896
message_ptr pmessage(new message("producer creation...", x));
@@ -103,7 +111,11 @@ class consumer : public status, public pthread::abstract_thread {
103111
consumer(sync_message_queue &queue): status(queue){
104112
};
105113

114+
#if __cplusplus < 201103L
115+
void run() throw() {
116+
#else
106117
void run() noexcept {
118+
#endif
107119
printf ("starting consumer\n");
108120
message_ptr pmessage ; // (new message("hello"));
109121
while( running() ){

0 commit comments

Comments
 (0)