You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2012/04/28 14:48:23 UTC

svn commit: r1331760 - in /subversion/trunk/subversion: include/private/svn_named_atomic.h libsvn_subr/named_atomic.c tests/libsvn_subr/named_atomic-test.c

Author: stefan2
Date: Sat Apr 28 12:48:23 2012
New Revision: 1331760

URL: http://svn.apache.org/viewvc?rev=1331760&view=rev
Log:
To the named atomics API, add a method that checks whether the full
API functionality will be available to the current process.

* subversion/include/private/svn_named_atomic.h
  (svn_named_atomic__is_supported): declare new API function
* subversion/libsvn_subr/named_atomic.c
  (svn_named_atomic__is_supported): implement new API function
* subversion/tests/libsvn_subr/named_atomic-test.c
  (has_sufficient_privileges): drop
  (init_test_shm): use new API

Suggested by: gstein

Modified:
    subversion/trunk/subversion/include/private/svn_named_atomic.h
    subversion/trunk/subversion/libsvn_subr/named_atomic.c
    subversion/trunk/subversion/tests/libsvn_subr/named_atomic-test.c

Modified: subversion/trunk/subversion/include/private/svn_named_atomic.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_named_atomic.h?rev=1331760&r1=1331759&r2=1331760&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_named_atomic.h (original)
+++ subversion/trunk/subversion/include/private/svn_named_atomic.h Sat Apr 28 12:48:23 2012
@@ -51,6 +51,16 @@ typedef struct svn_named_atomic__t svn_n
  */
 #define SVN_NAMED_ATOMIC__MAX_NAME_LENGTH 30
 
+/** Returns #FALSE when named atomics are not available to our process
+ * and svn_atomic_namespace__create is likely to fail.
+ *
+ * Please note that the actual check will be performed only once and later
+ * changes in process privileges will not reflect in the outcome of future
+ * calls to this function.
+ */
+svn_boolean_t
+svn_named_atomic__is_supported(void);
+
 /** Returns #TRUE on platforms that don't need expensive synchronization
  * objects to serialize access to named atomics. If this returns #FALSE,
  * reading from or modifying a #svn_named_atomic__t may be as expensive

Modified: subversion/trunk/subversion/libsvn_subr/named_atomic.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/named_atomic.c?rev=1331760&r1=1331759&r2=1331760&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/named_atomic.c (original)
+++ subversion/trunk/subversion/libsvn_subr/named_atomic.c Sat Apr 28 12:48:23 2012
@@ -341,6 +341,36 @@ return_atomic(svn_named_atomic__t **atom
 /* Implement API */
 
 svn_boolean_t
+svn_named_atomic__is_supported(void)
+{
+#ifdef _WIN32
+  static svn_tristate_t result = svn_tristate_unknown;
+
+  if (result == svn_tristate_unknown)
+    {
+      /* APR SHM implementation requires the creation of global objects */
+      HANDLE handle = CreateFileMappingA(INVALID_HANDLE_VALUE,
+                                         NULL,
+                                         PAGE_READONLY,
+                                         0,
+                                         1,
+                                         "Global\\__RandomXZY_svn");
+      if (handle != NULL)
+        {
+          CloseHandle(handle);
+          result = svn_tristate_true;
+        }
+      else
+        result = svn_tristate_false;
+    }
+
+  return result == svn_tristate_true ? TRUE : FALSE;
+#else
+  return TRUE;
+#endif
+}
+
+svn_boolean_t
 svn_named_atomic__is_efficient(void)
 {
   return NA_SYNCHRONIZE_IS_FAST;

Modified: subversion/trunk/subversion/tests/libsvn_subr/named_atomic-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/named_atomic-test.c?rev=1331760&r1=1331759&r2=1331760&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/named_atomic-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/named_atomic-test.c Sat Apr 28 12:48:23 2012
@@ -45,37 +45,6 @@ static int hw_thread_count = 0;
  * (will be calibrated to about 1s runtime)*/
 static int suggested_iterations = 0;
 
-/* Return FALSE if we can't create SHMs due to missing privileges
- */
-static svn_boolean_t
-has_sufficient_privileges(void)
-{
-#ifdef _WIN32
-  static svn_tristate_t result = svn_tristate_unknown;
-
-  if (result == svn_tristate_unknown)
-    {
-      HANDLE handle = CreateFileMappingA(INVALID_HANDLE_VALUE,
-                                         NULL,
-                                         PAGE_READONLY,
-                                         0,
-                                         1,
-                                         "Global\\__RandomXZY_svn");
-      if (handle != NULL)
-        {
-          CloseHandle(handle);
-          result = svn_tristate_true;
-        }
-      else
-        result = svn_tristate_false;
-    }
-
-  return result == svn_tristate_true ? TRUE : FALSE;
-#else
-  return TRUE;
-#endif
-}
-
 /* If possible, translate PROC to a global path and set DIRECTORY to
  * the current directory.
  */
@@ -174,7 +143,7 @@ init_test_shm(apr_pool_t *pool)
     }
 
   /* skip tests if the current user does not have the required privileges */
-  if (!has_sufficient_privileges())
+  if (!svn_named_atomic__is_supported())
     return svn_error_wrap_apr(SVN_ERR_TEST_SKIPPED,
                               "user has insufficient privileges");
 



Re: svn commit: r1331760 - in /subversion/trunk/subversion: include/private/svn_named_atomic.h libsvn_subr/named_atomic.c tests/libsvn_subr/named_atomic-test.c

Posted by Greg Stein <gs...@gmail.com>.
On Apr 28, 2012 8:48 AM, <st...@apache.org> wrote:
>
> Author: stefan2
> Date: Sat Apr 28 12:48:23 2012
> New Revision: 1331760
>
> URL: http://svn.apache.org/viewvc?rev=1331760&view=rev
> Log:
> To the named atomics API, add a method that checks whether the full
> API functionality will be available to the current process.
>
> * subversion/include/private/svn_named_atomic.h
>  (svn_named_atomic__is_supported): declare new API function
> * subversion/libsvn_subr/named_atomic.c
>  (svn_named_atomic__is_supported): implement new API function
> * subversion/tests/libsvn_subr/named_atomic-test.c
>  (has_sufficient_privileges): drop
>  (init_test_shm): use new API

Nice. Thanks!