Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ecb0d20

Browse files
committed
Use unnamed POSIX semaphores, if available, on Linux and FreeBSD.
We've had support for using unnamed POSIX semaphores instead of System V semaphores for quite some time, but it was not used by default on any platform. Since many systems have rather small limits on the number of SysV semaphores allowed, it seems desirable to switch to POSIX semaphores where they're available and don't create performance or kernel resource problems. Experimentation by me shows that unnamed POSIX semaphores are at least as good as SysV semaphores on Linux, and we previously had a report from Maksym Sobolyev that FreeBSD is significantly worse with SysV semaphores than POSIX ones. So adjust those two platforms to use unnamed POSIX semaphores, if configure can find the necessary library functions. If this goes well, we may switch other platforms as well, but it would be advisable to test them individually first. It's not currently contemplated that we'd encourage users to select a semaphore API for themselves, but anyone who wants to experiment can add PREFERRED_SEMAPHORES=UNNAMED_POSIX (or NAMED_POSIX, or SYSV) to their configure command line to do so. I also tweaked configure to report which API it's selected, mainly so that we can tell that from buildfarm reports. I did not touch the user documentation's discussion about semaphores; that will need some adjustment once the dust settles. Discussion: <8536.1475704230@sss.pgh.pa.us>
1 parent ac4a9d9 commit ecb0d20

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

configure

+125
Original file line numberDiff line numberDiff line change
@@ -14855,23 +14855,148 @@ fi
1485514855

1485614856
# Select semaphore implementation type.
1485714857
if test "$PORTNAME" != "win32"; then
14858+
if test x"$PREFERRED_SEMAPHORES" = x"NAMED_POSIX" ; then
14859+
# Need sem_open for this
14860+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing sem_open" >&5
14861+
$as_echo_n "checking for library containing sem_open... " >&6; }
14862+
if ${ac_cv_search_sem_open+:} false; then :
14863+
$as_echo_n "(cached) " >&6
14864+
else
14865+
ac_func_search_save_LIBS=$LIBS
14866+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14867+
/* end confdefs.h. */
14868+
14869+
/* Override any GCC internal prototype to avoid an error.
14870+
Use char because int might match the return type of a GCC
14871+
builtin and then its argument prototype would still apply. */
14872+
#ifdef __cplusplus
14873+
extern "C"
14874+
#endif
14875+
char sem_open ();
14876+
int
14877+
main ()
14878+
{
14879+
return sem_open ();
14880+
;
14881+
return 0;
14882+
}
14883+
_ACEOF
14884+
for ac_lib in '' rt pthread; do
14885+
if test -z "$ac_lib"; then
14886+
ac_res="none required"
14887+
else
14888+
ac_res=-l$ac_lib
14889+
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
14890+
fi
14891+
if ac_fn_c_try_link "$LINENO"; then :
14892+
ac_cv_search_sem_open=$ac_res
14893+
fi
14894+
rm -f core conftest.err conftest.$ac_objext \
14895+
conftest$ac_exeext
14896+
if ${ac_cv_search_sem_open+:} false; then :
14897+
break
14898+
fi
14899+
done
14900+
if ${ac_cv_search_sem_open+:} false; then :
14901+
14902+
else
14903+
ac_cv_search_sem_open=no
14904+
fi
14905+
rm conftest.$ac_ext
14906+
LIBS=$ac_func_search_save_LIBS
14907+
fi
14908+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_sem_open" >&5
14909+
$as_echo "$ac_cv_search_sem_open" >&6; }
14910+
ac_res=$ac_cv_search_sem_open
14911+
if test "$ac_res" != no; then :
14912+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
14913+
USE_NAMED_POSIX_SEMAPHORES=1
14914+
fi
14915+
14916+
fi
14917+
if test x"$PREFERRED_SEMAPHORES" = x"UNNAMED_POSIX" ; then
14918+
# Need sem_init for this
14919+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing sem_init" >&5
14920+
$as_echo_n "checking for library containing sem_init... " >&6; }
14921+
if ${ac_cv_search_sem_init+:} false; then :
14922+
$as_echo_n "(cached) " >&6
14923+
else
14924+
ac_func_search_save_LIBS=$LIBS
14925+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
14926+
/* end confdefs.h. */
14927+
14928+
/* Override any GCC internal prototype to avoid an error.
14929+
Use char because int might match the return type of a GCC
14930+
builtin and then its argument prototype would still apply. */
14931+
#ifdef __cplusplus
14932+
extern "C"
14933+
#endif
14934+
char sem_init ();
14935+
int
14936+
main ()
14937+
{
14938+
return sem_init ();
14939+
;
14940+
return 0;
14941+
}
14942+
_ACEOF
14943+
for ac_lib in '' rt pthread; do
14944+
if test -z "$ac_lib"; then
14945+
ac_res="none required"
14946+
else
14947+
ac_res=-l$ac_lib
14948+
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
14949+
fi
14950+
if ac_fn_c_try_link "$LINENO"; then :
14951+
ac_cv_search_sem_init=$ac_res
14952+
fi
14953+
rm -f core conftest.err conftest.$ac_objext \
14954+
conftest$ac_exeext
14955+
if ${ac_cv_search_sem_init+:} false; then :
14956+
break
14957+
fi
14958+
done
14959+
if ${ac_cv_search_sem_init+:} false; then :
14960+
14961+
else
14962+
ac_cv_search_sem_init=no
14963+
fi
14964+
rm conftest.$ac_ext
14965+
LIBS=$ac_func_search_save_LIBS
14966+
fi
14967+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_sem_init" >&5
14968+
$as_echo "$ac_cv_search_sem_init" >&6; }
14969+
ac_res=$ac_cv_search_sem_init
14970+
if test "$ac_res" != no; then :
14971+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
14972+
USE_UNNAMED_POSIX_SEMAPHORES=1
14973+
fi
14974+
14975+
fi
14976+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking which semaphore API to use" >&5
14977+
$as_echo_n "checking which semaphore API to use... " >&6; }
1485814978
if test x"$USE_NAMED_POSIX_SEMAPHORES" = x"1" ; then
1485914979

1486014980
$as_echo "#define USE_NAMED_POSIX_SEMAPHORES 1" >>confdefs.h
1486114981

1486214982
SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c"
14983+
sematype="named POSIX"
1486314984
else
1486414985
if test x"$USE_UNNAMED_POSIX_SEMAPHORES" = x"1" ; then
1486514986

1486614987
$as_echo "#define USE_UNNAMED_POSIX_SEMAPHORES 1" >>confdefs.h
1486714988

1486814989
SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c"
14990+
sematype="unnamed POSIX"
1486914991
else
1487014992

1487114993
$as_echo "#define USE_SYSV_SEMAPHORES 1" >>confdefs.h
1487214994

1487314995
SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c"
14996+
sematype="System V"
1487414997
fi
14998+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $sematype" >&5
14999+
$as_echo "$sematype" >&6; }
1487515000
fi
1487615001
else
1487715002

configure.in

+13
Original file line numberDiff line numberDiff line change
@@ -1939,17 +1939,30 @@ AC_SUBST(PG_CRC32C_OBJS)
19391939

19401940
# Select semaphore implementation type.
19411941
if test "$PORTNAME" != "win32"; then
1942+
if test x"$PREFERRED_SEMAPHORES" = x"NAMED_POSIX" ; then
1943+
# Need sem_open for this
1944+
AC_SEARCH_LIBS(sem_open, [rt pthread], [USE_NAMED_POSIX_SEMAPHORES=1])
1945+
fi
1946+
if test x"$PREFERRED_SEMAPHORES" = x"UNNAMED_POSIX" ; then
1947+
# Need sem_init for this
1948+
AC_SEARCH_LIBS(sem_init, [rt pthread], [USE_UNNAMED_POSIX_SEMAPHORES=1])
1949+
fi
1950+
AC_MSG_CHECKING([which semaphore API to use])
19421951
if test x"$USE_NAMED_POSIX_SEMAPHORES" = x"1" ; then
19431952
AC_DEFINE(USE_NAMED_POSIX_SEMAPHORES, 1, [Define to select named POSIX semaphores.])
19441953
SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c"
1954+
sematype="named POSIX"
19451955
else
19461956
if test x"$USE_UNNAMED_POSIX_SEMAPHORES" = x"1" ; then
19471957
AC_DEFINE(USE_UNNAMED_POSIX_SEMAPHORES, 1, [Define to select unnamed POSIX semaphores.])
19481958
SEMA_IMPLEMENTATION="src/backend/port/posix_sema.c"
1959+
sematype="unnamed POSIX"
19491960
else
19501961
AC_DEFINE(USE_SYSV_SEMAPHORES, 1, [Define to select SysV-style semaphores.])
19511962
SEMA_IMPLEMENTATION="src/backend/port/sysv_sema.c"
1963+
sematype="System V"
19521964
fi
1965+
AC_MSG_RESULT([$sematype])
19531966
fi
19541967
else
19551968
AC_DEFINE(USE_WIN32_SEMAPHORES, 1, [Define to select Win32-style semaphores.])

src/template/freebsd

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
# src/template/freebsd
2+
3+
# Prefer unnamed POSIX semaphores if available, unless user overrides choice
4+
if test x"$PREFERRED_SEMAPHORES" = x"" ; then
5+
PREFERRED_SEMAPHORES=UNNAMED_POSIX
6+
fi

src/template/linux

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# src/template/linux
22

3+
# Prefer unnamed POSIX semaphores if available, unless user overrides choice
4+
if test x"$PREFERRED_SEMAPHORES" = x"" ; then
5+
PREFERRED_SEMAPHORES=UNNAMED_POSIX
6+
fi
7+
38
# Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise
49
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
510

0 commit comments

Comments
 (0)