Skip to content

Commit 01e2855

Browse files
Merge branch 'iss-30' into develop
2 parents bc206ca + a379fb4 commit 01e2855

File tree

10 files changed

+34
-14
lines changed

10 files changed

+34
-14
lines changed

include/pthread/condition_variable.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ namespace pthread {
212212

213213
template<class Lambda> bool condition_variable::wait( lock_guard<pthread::mutex> &lck, Lambda lambda){
214214

215-
return wait( *(lck.mutex()), lambda);
215+
//return wait( *(lck.mutex()), lambda);
216+
return wait( *(lck._mutex), lambda);
216217
};
217218

218219
template<class Lambda> bool condition_variable::wait_for( mutex &mtx, int millis, Lambda lambda){
@@ -253,7 +254,8 @@ namespace pthread {
253254

254255
template<class Lambda> bool condition_variable::wait_for( lock_guard<pthread::mutex> &lck, int millis, Lambda lambda){
255256

256-
return wait_for(*(lck.mutex()),millis, lambda);
257+
// return wait_for(*(lck.mutex()),millis, lambda);
258+
return wait_for(*(lck._mutex),millis, lambda);
257259
};
258260

259261
} // namespace pthread

include/pthread/lock_guard.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
#include <pthread.h>
1313

1414
#include "pthread/config.h"
15-
1615
#include "pthread/mutex.hpp"
1716

1817
namespace pthread {
1918

2019
using namespace std ;
2120

21+
class condition_variable ;
22+
2223
/**
2324
This class was designed to encapsulate a mutex and automatically control the lock attribute.
2425
@@ -29,7 +30,9 @@ namespace pthread {
2930
*/
3031
template<class MutexType>
3132
class lock_guard {
32-
33+
34+
friend class condition_variable;
35+
3336
public:
3437
/**
3538
* The constructor is forced to only accept a mutex object or any object of a subclass.
@@ -38,24 +41,26 @@ namespace pthread {
3841
*
3942
* @param m reference to a valid pthread::mutex
4043
*/
41-
explicit lock_guard(mutex &m) : _mutex(&m) {
42-
_mutex->lock();
44+
explicit lock_guard(MutexType &m): _mutex(&m) {
45+
_mutex->lock();
4346
}
4447

4548
/** release the guared mutex.
4649
*/
47-
~lock_guard() {
50+
virtual ~lock_guard() {
4851
_mutex->unlock();
52+
}
53+
54+
/** @return a const reference to the guarded mutex */
55+
MutexType *internal_mutex() {
56+
return _mutex ;
4957
}
5058

5159
/*
5260
Desabling the = operator.
5361
*/
5462
void operator=(lock_guard &) = delete;
5563

56-
/** @return a const reference to the guarded mutex */
57-
MutexType *mutex() const { return _mutex ;};
58-
5964
private:
6065
MutexType *_mutex;
6166
};

include/pthread/thread.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <pthread.h>
1313
#include <string>
1414
#include <functional>
15-
#include <memory>
15+
#include <memory> // std::auto_ptr, std::unique_ptr
1616
#include <list>
1717

1818
#include "pthread/config.h"

src/condition_variable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ namespace pthread {
77
}
88

99
void condition_variable::wait(lock_guard<pthread::mutex> lck){
10-
wait(*(lck.mutex()));
10+
// wait(*(lck.mutex()));
11+
wait(*(lck._mutex));
1112
}
1213

1314
cv_status condition_variable::wait_for (lock_guard<pthread::mutex> &lck, int millis ){
14-
return wait_for(*(lck.mutex()), millis);
15+
// return wait_for(*(lck.mutex()), millis);
16+
return wait_for(*(lck._mutex), millis);
1517
}
1618

1719
/* Default millis is 0 */

src/configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,7 @@ case "$CXX" in
39373937
$as_echo "yes" >&6; }
39383938
;;
39393939
g++ | gcc)
3940+
#CXXFLAGS="-x c++ -std=c++11 -frtti -fpermissive $CXXFLAGS "
39403941
CXXFLAGS="-x c++ -std=c++11 -frtti $CXXFLAGS "
39413942
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
39423943
$as_echo "yes" >&6; }

src/configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ case "$CXX" in
4444
AC_MSG_RESULT([yes])
4545
;;
4646
g++ | gcc)
47+
#permissive is not required anymore - CXXFLAGS="-x c++ -std=c++11 -frtti -fpermissive $CXXFLAGS "
4748
CXXFLAGS="-x c++ -std=c++11 -frtti $CXXFLAGS "
4849
AC_MSG_RESULT([yes])
4950
;;

src/thread.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ namespace pthread {
123123

124124
thread_group::~thread_group(){
125125
while(! _threads.empty()){
126+
#if __cplusplus < 201103L
126127
std::auto_ptr<pthread::abstract_thread> pat(_threads.front());
128+
#else
129+
std::unique_ptr<pthread::abstract_thread> pat(_threads.front());
130+
#endif
131+
127132
_threads.pop_front();
128133

129134
if ( _destructor_joins_first ){

tests/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ beautifull:
5858
$(CCC) $(CCFLAGS) -c $<
5959

6060
.cpp:
61-
$(CCC) $(CCFLAGS) $(LDFLAGS) $< -o $@
61+
$(CCC) $(CCFLAGS) $< -o $@ $(LDFLAGS)

tests/configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,11 +3904,13 @@ if test $ac_cv_sizeof_long == "8"
39043904
then
39053905
BITS="64"
39063906

3907+
#CXXFLAGS="-m$ac_cv_sizeof_long $CXXFLAGS -I ../include -I ./"
39073908
else
39083909
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: using 32 bits (default)" >&5
39093910
$as_echo "using 32 bits (default)" >&6; }
39103911
BITS="32"
39113912

3913+
#CXXFLAGS="-m$ac_cv_sizeof_long $CXXFLAGS -I ../include -I ./"
39123914
fi
39133915

39143916
OBJECTS=""

tests/configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ AC_CHECK_SIZEOF([long])
2222
if test $ac_cv_sizeof_long == "8"
2323
then
2424
AC_SUBST(BITS,"64")
25+
#CXXFLAGS="-m$ac_cv_sizeof_long $CXXFLAGS -I ../include -I ./"
2526
else
2627
AC_MSG_RESULT([using 32 bits (default)])
2728
AC_SUBST(BITS,"32")
29+
#CXXFLAGS="-m$ac_cv_sizeof_long $CXXFLAGS -I ../include -I ./"
2830
fi
2931

3032
OBJECTS=""

0 commit comments

Comments
 (0)