Skip to content

Commit 8117748

Browse files
author
Herbert Koelman
committed
Merge branch 'iss-41' into develop
2 parents 3ef8ab8 + 25f12a2 commit 8117748

17 files changed

+181
-591
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ cd tests
4343

4444
### Usefull links
4545

46+
#### Memory management on AIX
47+
48+
Memory management on AIX is quite sophisticated making it possible to fine tuned very precisely the way your program uses memory. Consider using these compiler/linker options when using pthreads:
49+
* -bmaxdata:0xN0000000 this option activates the large memory model, N is a number in the range of [1-8].
50+
* -bmaxmem=-1 this option tell the compiler to use as much memory it needs (usefull when -O option is used).
51+
52+
Thread stack size:
53+
* 32bits programs allocate 96KB per thread on the program's heap.
54+
* 64bits programs allocate 192KB per thread on the program's heap.
55+
56+
On many Linux implementations and on Mac OS X the stack size is defaulted to 8MB. You may consider setting this as a default.
57+
58+
More detailed information can be found in this [RedBook](http://www.redbooks.ibm.com/redbooks/pdfs/sg245674.pdf) (chapter 8).
59+
4660
#### project links
4761

4862
* [project's home](https://github.com/HerbertKoelman/cpp-pthread)

include/pthread/condition_variable.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
#ifndef pthread_condition_variable_hpp
77
#define pthread_condition_variable_hpp
88

9+
// must be include as first hearder file of each source code file (see IBM's
10+
// recommandation for more info p.285 §8.3.1).
911
#include <pthread.h>
1012
#include <string>
1113
#include <time.h>
1214
#include <sys/time.h>
1315

1416
#include "pthread/config.h"
1517

16-
#include "pthread/pthread_exception.hpp"
18+
#include "pthread/exceptions.hpp"
1719
#include "pthread/mutex.hpp"
1820
#include "pthread/lock_guard.hpp"
1921

include/pthread/pthread_exception.hpp renamed to include/pthread/exceptions.hpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
//
2-
// mutex.hpp
2+
// exceptions.hpp
33
// cpp-pthread
44
//
55
// Created by herbert koelman on 18/03/2016.
66
//
77
//
88

9-
#ifndef pthread_pthread_exception_hpp
10-
#define pthread_pthread_exception_hpp
9+
#ifndef PTHREAD_EXCEPTIONS_HPP
10+
#define PTHREAD_EXCEPTIONS_HPP
1111

12-
#include "pthread/config.h"
12+
#include <pthread.h>
1313

1414
#include <errno.h>
15+
#include <string> // std::string
1516
#include <cstring>
17+
#include <exception> // std::exception
1618

1719
namespace pthread {
1820

@@ -28,26 +30,33 @@ namespace pthread {
2830
* @param message error message
2931
* @param pthread_errno a pthread function return code.
3032
*/
31-
pthread_exception( const string message, const int pthread_errno = 0 ): _message(message), _pthread_errno(pthread_errno){};
33+
pthread_exception( const char *message, const int pthread_errno = 0 );
3234

33-
virtual ~pthread_exception(){};
35+
/**
36+
* @param message error message
37+
* @param pthread_errno a pthread function return code.
38+
*/
39+
pthread_exception( const string message, const int pthread_errno = 0 );
40+
41+
virtual ~pthread_exception();
3442

3543
/** @return exception's error message. */
3644
#if __cplusplus < 201103L
37-
virtual const char *what() const throw() { return _message.c_str();};
45+
virtual const char *what() const throw() ;
3846
#else
39-
virtual const char *what() const noexcept override{ return _message.c_str();};
47+
virtual const char *what() const noexcept override ;
4048
#endif
4149

4250
/** @return pthread error code that was at the orgin of the error */
43-
virtual int pthread_errno(){ return _pthread_errno ;};
51+
virtual int pthread_errno() ;
4452

4553
/** @return related pthread_errno error message using strerror */
46-
virtual const char *pthread_errmsg(){ return strerror(_pthread_errno );};
54+
virtual const char *pthread_errmsg() ;
4755

4856
private:
49-
string _message;
50-
int _pthread_errno;
57+
//std::string _message;
58+
const char *_message;
59+
int _pthread_errno;
5160

5261
};
5362

@@ -59,7 +68,7 @@ namespace pthread {
5968
*
6069
* @param message timeout condition
6170
*/
62-
timeout_exception(const string message): pthread_exception(message, ETIMEDOUT){};
71+
timeout_exception(const string message);
6372
};
6473

6574
} // namespace pthread

include/pthread/lock_guard.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef pthread_lock_guard_H
1010
#define pthread_lock_guard_H
1111

12+
// must be include as first hearder file of each source code file (see IBM's
13+
// recommandation for more info p.285 §8.3.1).
1214
#include <pthread.h>
1315

1416
#include "pthread/config.h"

include/pthread/mutex.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
#ifndef pthread_mutex_hpp
1010
#define pthread_mutex_hpp
1111

12+
// must be include as first hearder file of each source code file (see IBM's
13+
// recommandation for more info p.285 §8.3.1).
1214
#include <pthread.h>
15+
1316
#include <exception>
1417
#include <string>
1518

1619
#include "pthread/config.h"
1720

18-
#include "pthread/pthread_exception.hpp"
21+
#include "pthread/exceptions.hpp"
1922

2023
namespace pthread {
2124

include/pthread/pthread.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
#ifndef pthread_pthread_hpp
1515
#define pthread_pthread_hpp
1616

17-
#include <errno.h>
18-
#include <exception>
19-
#include <string>
17+
// must be include as first hearder file of each source code file (see IBM's
18+
// recommandation for more info p.285 §8.3.1).
19+
#include <pthread.h>
2020

2121
#include "pthread/config.h"
22-
2322
#include "pthread/mutex.hpp"
2423
#include "pthread/lock_guard.hpp"
2524
#include "pthread/condition_variable.hpp"
2625
#include "pthread/thread.hpp"
26+
#include "pthread/exceptions.hpp"
2727

2828
/** \namespace pthread
2929
*

include/pthread/thread.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
// Copyright © 2016 urbix-software. All rights reserved.
77
//
88

9-
#ifndef pthread_thread_hpp
10-
#define pthread_thread_hpp
9+
#ifndef PTHREAD_THREAD_HPP
10+
#define PTHREAD_THREAD_HPP
11+
12+
// must be include as first hearder file of each source code file (see IBM's
13+
// recommandation for more info p.285 §8.3.1).
14+
#include <pthread.h>
15+
1116
#include <iostream>
12-
#include <pthread.h>
1317
#include <string>
1418
#include <functional>
1519
#include <memory> // std::auto_ptr, std::unique_ptr
1620
#include <list>
1721
#include <cstddef>
1822

1923
#include "pthread/config.h"
20-
21-
#include "pthread/pthread_exception.hpp"
24+
#include "pthread/exceptions.hpp"
2225
#include "pthread/mutex.hpp"
2326
#include "pthread/lock_guard.hpp"
2427

@@ -164,6 +167,7 @@ namespace pthread {
164167
void swap ( thread& other );
165168

166169
pthread_t _thread;
170+
pthread_attr_t _attr;
167171

168172
thread_status _status;
169173
};

src/Makefile.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ CFLAGS=$(OPTIONS) @CFLAGS@
3434
CPPFLAGS=$(OPTIONS) @CPPFLAGS@
3535

3636
LDFLAGS=@LDFLAGS@
37+
LIBS=@LIBS@
3738

3839
OBJECTS=@OBJECTS@
3940

@@ -61,4 +62,7 @@ beautifull:
6162

6263
# cpp build rule
6364
.cpp.o:
64-
$(CCC) $(CPPFLAGS) $(CXXFLAGS) -c $<
65+
$(CCC) $(CPPFLAGS) $(CFLAGS) -c $<
66+
67+
.cpp:
68+
$(CCC) $(CPPFLAGS) $(CFLAGS) $< -o $@ $(LDFLAGS) $(LIBS)

src/configure

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ EGREP
630630
GREP
631631
CXXCPP
632632
RANLIB
633-
BEAUTIFIER
634633
MV
635634
AR
636635
ac_ct_CC
@@ -3347,44 +3346,6 @@ $as_echo "no" >&6; }
33473346
fi
33483347
33493348
3350-
# Extract the first word of "uncrustify", so it can be a program name with args.
3351-
set dummy uncrustify; ac_word=$2
3352-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
3353-
$as_echo_n "checking for $ac_word... " >&6; }
3354-
if ${ac_cv_prog_BEAUTIFIER+:} false; then :
3355-
$as_echo_n "(cached) " >&6
3356-
else
3357-
if test -n "$BEAUTIFIER"; then
3358-
ac_cv_prog_BEAUTIFIER="$BEAUTIFIER" # Let the user override the test.
3359-
else
3360-
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
3361-
for as_dir in $PATH
3362-
do
3363-
IFS=$as_save_IFS
3364-
test -z "$as_dir" && as_dir=.
3365-
for ac_exec_ext in '' $ac_executable_extensions; do
3366-
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
3367-
ac_cv_prog_BEAUTIFIER="uncrustify -l CPP --replace -c ../crust.cfg *.bsr *.bcl *.cpp *.hpp"
3368-
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
3369-
break 2
3370-
fi
3371-
done
3372-
done
3373-
IFS=$as_save_IFS
3374-
3375-
test -z "$ac_cv_prog_BEAUTIFIER" && ac_cv_prog_BEAUTIFIER="echo \"install crustify to run beautifier\""
3376-
fi
3377-
fi
3378-
BEAUTIFIER=$ac_cv_prog_BEAUTIFIER
3379-
if test -n "$BEAUTIFIER"; then
3380-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $BEAUTIFIER" >&5
3381-
$as_echo "$BEAUTIFIER" >&6; }
3382-
else
3383-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
3384-
$as_echo "no" >&6; }
3385-
fi
3386-
3387-
33883349
if test -n "$ac_tool_prefix"; then
33893350
# Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
33903351
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
@@ -3478,8 +3439,7 @@ else
34783439
fi
34793440
34803441
3481-
CPPFLAGS="$CPPFLAGS -I ../include -I ./"
3482-
LDFLAGS="$LDFLAGS -L ../lib"
3442+
CFLAGS="-I ../include -I ./"
34833443
34843444
34853445
ac_ext=cpp
@@ -3934,14 +3894,14 @@ OBJECTS=$OBJECTS
39343894
$as_echo_n "checking for specific $CXX compiler options... " >&6; }
39353895
case "$CXX" in
39363896
xlC_r | xlC)
3937-
CPPFLAGS="-bh:5 -q$bits -O $CPPFLAGS"
3938-
CXXFLAGS="-qlanglvl=extended0x:decltype:static_assert::rvaluereferences:rvaluereferences -qwarn0x -qsourcetype=c++ $CXXFLAGS"
3939-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
3940-
$as_echo "yes" >&6; }
3897+
CPPFLAGS="-qlanglvl=extended0x:decltype:static_assert:rvaluereferences:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
3898+
CFLAGS="-bh:5 -O -qmaxmem=-1 -q$BITS $CFLAGS"
3899+
LDFLAGS="$LDFLAGS -brtl -bmaxdata:0x80000000"
3900+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: using large memory model (maxdata:0x80000000), optimising level 2 (-O),using run-time link method (-brtl)" >&5
3901+
$as_echo "using large memory model (maxdata:0x80000000), optimising level 2 (-O),using run-time link method (-brtl)" >&6; }
39413902
;;
39423903
g++ | gcc)
3943-
#permissive is not required anymore - CXXFLAGS="-x c++ -std=c++11 -frtti -fpermissive $CXXFLAGS "
3944-
CXXFLAGS="-x c++ -std=c++11 -frtti $CXXFLAGS "
3904+
CPPFLAGS="-x c++ -std=c++11 -frtti $CPPFLAGS "
39453905
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
39463906
$as_echo "yes" >&6; }
39473907
;;
@@ -4155,8 +4115,6 @@ fi
41554115
done
41564116
41574117
4158-
LDFLAGS="$LDFLAGS $LIBS"
4159-
41604118
ac_config_files="$ac_config_files Makefile pthread.cpp"
41614119
41624120
cat >confcache <<\_ACEOF

src/configure.ac

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ AC_PROG_CXX([xlC_r xlC g++ c++ gcc cl KCC CC cxx cc++ aCC ])
1414
AC_PROG_CC([xlc xlc_r gcc cl cc])
1515
AC_CHECK_PROG([AR],[ar],[ar -rv])
1616
AC_CHECK_PROG([MV],[mv],[mv],[echo "no mv command found"])
17-
AC_CHECK_PROG([BEAUTIFIER],[uncrustify],[uncrustify -l CPP --replace -c ../crust.cfg *.bsr *.bcl *.cpp *.hpp],[echo \"install crustify to run beautifier\"])
1817
AC_PROG_RANLIB
1918

20-
CPPFLAGS="$CPPFLAGS -I ../include -I ./"
21-
LDFLAGS="$LDFLAGS -L ../lib"
19+
CFLAGS="-I ../include -I ./"
2220

2321
AC_CHECK_SIZEOF([long])
2422
if test $ac_cv_sizeof_long == "8"
@@ -42,13 +40,13 @@ AC_SUBST(OBJECTS,$OBJECTS)
4240
AC_MSG_CHECKING([for specific $CXX compiler options])
4341
case "$CXX" in
4442
xlC_r | xlC)
45-
CPPFLAGS="-bh:5 -q$bits -O $CPPFLAGS"
46-
CXXFLAGS="-qlanglvl=extended0x:decltype:static_assert::rvaluereferences:rvaluereferences -qwarn0x -qsourcetype=c++ $CXXFLAGS"
47-
AC_MSG_RESULT([yes])
43+
CPPFLAGS="-qlanglvl=extended0x:decltype:static_assert:rvaluereferences:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
44+
CFLAGS="-bh:5 -O -qmaxmem=-1 -q$BITS $CFLAGS"
45+
LDFLAGS="$LDFLAGS -brtl -bmaxdata:0x80000000"
46+
AC_MSG_RESULT([using large memory model (maxdata:0x80000000), optimising level 2 (-O),using run-time link method (-brtl)])
4847
;;
4948
g++ | gcc)
50-
#permissive is not required anymore - CXXFLAGS="-x c++ -std=c++11 -frtti -fpermissive $CXXFLAGS "
51-
CXXFLAGS="-x c++ -std=c++11 -frtti $CXXFLAGS "
49+
CPPFLAGS="-x c++ -std=c++11 -frtti $CPPFLAGS "
5250
AC_MSG_RESULT([yes])
5351
;;
5452
*)
@@ -82,8 +80,6 @@ AC_HEADER_STDBOOL
8280
#AC_FUNC_MALLOC
8381
AC_CHECK_FUNCS([gettimeofday])
8482

85-
LDFLAGS="$LDFLAGS $LIBS"
86-
8783
AC_CONFIG_FILES([Makefile pthread.cpp])
8884
AC_OUTPUT
8985

0 commit comments

Comments
 (0)