Author: sebor
Date: Mon Jan 18 01:21:27 2010
New Revision: 900262
URL: http://svn.apache.org/viewvc?rev=900262&view=rev
Log:
2010-01-17 John Taylor <[email protected]>
STDCXX-1045
* etc/config/src/POSIX_MADVISE.cpp: New config test.
* src/memattr.cpp [_RWSTD_OS_SUNOS && !_RWSTD_NO_POSIX_MADVISE]
(__rw_memattr): Used posix_madvise() instead of madvise().
Added:
stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp (with props)
Modified:
stdcxx/branches/4.2.x/src/memattr.cpp
Added: stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp?rev=900262&view=auto
==============================================================================
--- stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp (added)
+++ stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp Mon Jan 18 01:21:27
2010
@@ -0,0 +1,40 @@
+// checking for posix_madvise() in <sys/mman.h>
+
+/***************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the License); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ **************************************************************************/
+
+#include <sys/mman.h> // for posix_madvise(), POSIX_MADV_WILLNEED
+#include <sys/types.h> // for size_t
+
+
+int main (int argc, char *argv[])
+{
+ size_t len = (size_t)argc;
+
+ const int result = posix_madvise (argv, len, POSIX_MADV_WILLNEED);
+
+ if (1 < argc) {
+ // invoke with any command line arguments to test
+ return result;
+ }
+
+ // always succeed when invoked without arguments
+ return 0;
+}
Propchange: stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: stdcxx/branches/4.2.x/etc/config/src/POSIX_MADVISE.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Modified: stdcxx/branches/4.2.x/src/memattr.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/src/memattr.cpp?rev=900262&r1=900261&r2=900262&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/src/memattr.cpp (original)
+++ stdcxx/branches/4.2.x/src/memattr.cpp Mon Jan 18 01:21:27 2010
@@ -29,6 +29,8 @@
#define _RWSTD_LIB_SRC
+#include <config.h>
+
#include <errno.h> // for ENOMEM, errno
#include <string.h> // for memchr(), size_t
@@ -55,6 +57,11 @@
# include <sys/mman.h> // for mincore()
# include <sys/types.h>
+# if defined (_RWSTD_OS_SUNOS) && defined (_RWSTD_NO_POSIX_MADVISE)
+ // can't get a proper prototype for madvise with C++ defines in Solaris 10
+ extern "C" int madvise(caddr_t, size_t, int);
+# endif
+
# ifndef _SC_PAGE_SIZE
// fall back on the alternative macro if it exists,
@@ -93,7 +100,6 @@
( _RWSTD_REINTERPRET_CAST (const char*, addr1) \
- _RWSTD_REINTERPRET_CAST (const char*, addr2))
-
_RWSTD_NAMESPACE (__rw) {
_RWSTD_EXPORT _RWSTD_SSIZE_T
@@ -129,11 +135,21 @@
# ifdef _RWSTD_OS_SUNOS
- char dummy = '\0';
+# ifndef _RWSTD_NO_POSIX_MADVISE
+
+ const int advice = POSIX_MADV_WILLNEED;
+
+ // on Solaris use posix_madvise if available
+ if (-1 == posix_madvise (next, 1, advice)) {
+
+# else
+
+ const int advice = MADV_WILLNEED;
+
+ // on Solaris use madvise if available
+ if (-1 == madvise (next, 1, advice)) {
- // on Solaris use mincore() instead of madvise() since
- // the latter is unreliable
- if (-1 == mincore (next, 1, &dummy)) {
+# endif // _RWSTD_NO_POSIX_MADVISE
const int err = errno;
errno = errno_save;