[Freeswitch-svn] [commit] r5186 - freeswitch/trunk/libs/js/nsprpub/pr/src/misc

Freeswitch SVN mikej at freeswitch.org
Tue May 15 13:22:49 EDT 2007


Author: mikej
Date: Tue May 15 13:22:49 2007
New Revision: 5186

Modified:
   freeswitch/trunk/libs/js/nsprpub/pr/src/misc/pratom.c

Log:
fix the fallback atomic operation implementation for use on arm devices.

Modified: freeswitch/trunk/libs/js/nsprpub/pr/src/misc/pratom.c
==============================================================================
--- freeswitch/trunk/libs/js/nsprpub/pr/src/misc/pratom.c	(original)
+++ freeswitch/trunk/libs/js/nsprpub/pr/src/misc/pratom.c	Tue May 15 13:22:49 2007
@@ -54,6 +54,50 @@
  */
 
 #if !defined(_PR_HAVE_ATOMIC_OPS)
+#include "prbit.h"
+
+/*
+** Compute the log of the least power of 2 greater than or equal to n
+*/
+PR_IMPLEMENT(PRIntn) PR_CeilingLog2(PRUint32 n)
+{
+    PRIntn log2 = 0;
+
+    if (n & (n-1))
+	log2++;
+    if (n >> 16)
+	log2 += 16, n >>= 16;
+    if (n >> 8)
+	log2 += 8, n >>= 8;
+    if (n >> 4)
+	log2 += 4, n >>= 4;
+    if (n >> 2)
+	log2 += 2, n >>= 2;
+    if (n >> 1)
+	log2++;
+    return log2;
+}
+
+/*
+** Compute the log of the greatest power of 2 less than or equal to n.
+** This really just finds the highest set bit in the word.
+*/
+PR_IMPLEMENT(PRIntn) PR_FloorLog2(PRUint32 n)
+{
+    PRIntn log2 = 0;
+
+    if (n >> 16)
+	log2 += 16, n >>= 16;
+    if (n >> 8)
+	log2 += 8, n >>= 8;
+    if (n >> 4)
+	log2 += 4, n >>= 4;
+    if (n >> 2)
+	log2 += 2, n >>= 2;
+    if (n >> 1)
+	log2++;
+    return log2;
+}
 
 #if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
 /*



More information about the Freeswitch-svn mailing list