Blame SOURCES/jemalloc-3.0.0.atomic_h_ppc_32bit_operations.patch

fc2ce9
diff -Naur ../jemalloc-3.0.0.orig/COPYING.epel5-ppc ./COPYING.epel5-ppc
fc2ce9
--- ../jemalloc-3.0.0.orig/COPYING.epel5-ppc	1970-01-01 01:00:00.000000000 +0100
fc2ce9
+++ ./COPYING.epel5-ppc	2012-05-18 16:21:31.869392165 +0200
fc2ce9
@@ -0,0 +1,215 @@
fc2ce9
+When using this jemalloc package with EPEL5 on ppc, please note that a
fc2ce9
+non-upstream patch has been added. This patch is covered by the Apache
fc2ce9
+2.0 License, which states that this work is
fc2ce9
+
fc2ce9
+   Licensed under the Apache License, Version 2.0 (the "License");
fc2ce9
+   you may not use this file except in compliance with the License.
fc2ce9
+
fc2ce9
+For other platforms and operating systems, please ignore this file.
fc2ce9
+
fc2ce9
+The patch adds missing 32bit atomic operations that is missing from
fc2ce9
+RHEL5 and its derivates on ppc/ppc64. The code was fetched from the
fc2ce9
+Apache Portable Runtime project, http://apr.apache.org/
fc2ce9
+
fc2ce9
+
fc2ce9
+
fc2ce9
+Apache License
fc2ce9
+
fc2ce9
+Version 2.0, January 2004
fc2ce9
+
fc2ce9
+http://www.apache.org/licenses/
fc2ce9
+
fc2ce9
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
fc2ce9
+
fc2ce9
+1. Definitions.
fc2ce9
+
fc2ce9
+"License" shall mean the terms and conditions for use, reproduction,
fc2ce9
+and distribution as defined by Sections 1 through 9 of this document.
fc2ce9
+
fc2ce9
+"Licensor" shall mean the copyright owner or entity authorized by the
fc2ce9
+copyright owner that is granting the License.
fc2ce9
+
fc2ce9
+"Legal Entity" shall mean the union of the acting entity and all other
fc2ce9
+entities that control, are controlled by, or are under common control
fc2ce9
+with that entity. For the purposes of this definition, "control" means
fc2ce9
+(i) the power, direct or indirect, to cause the direction or
fc2ce9
+management of such entity, whether by contract or otherwise, or (ii)
fc2ce9
+ownership of fifty percent (50%) or more of the outstanding shares, or
fc2ce9
+(iii) beneficial ownership of such entity.
fc2ce9
+
fc2ce9
+"You" (or "Your") shall mean an individual or Legal Entity exercising
fc2ce9
+permissions granted by this License.
fc2ce9
+
fc2ce9
+"Source" form shall mean the preferred form for making modifications,
fc2ce9
+including but not limited to software source code, documentation
fc2ce9
+source, and configuration files.
fc2ce9
+
fc2ce9
+"Object" form shall mean any form resulting from mechanical
fc2ce9
+transformation or translation of a Source form, including but not
fc2ce9
+limited to compiled object code, generated documentation, and
fc2ce9
+conversions to other media types.
fc2ce9
+
fc2ce9
+"Work" shall mean the work of authorship, whether in Source or Object
fc2ce9
+form, made available under the License, as indicated by a copyright
fc2ce9
+notice that is included in or attached to the work (an example is
fc2ce9
+provided in the Appendix below).
fc2ce9
+
fc2ce9
+"Derivative Works" shall mean any work, whether in Source or Object
fc2ce9
+form, that is based on (or derived from) the Work and for which the
fc2ce9
+editorial revisions, annotations, elaborations, or other modifications
fc2ce9
+represent, as a whole, an original work of authorship. For the
fc2ce9
+purposes of this License, Derivative Works shall not include works
fc2ce9
+that remain separable from, or merely link (or bind by name) to the
fc2ce9
+interfaces of, the Work and Derivative Works thereof.
fc2ce9
+
fc2ce9
+"Contribution" shall mean any work of authorship, including the
fc2ce9
+original version of the Work and any modifications or additions to
fc2ce9
+that Work or Derivative Works thereof, that is intentionally submitted
fc2ce9
+to Licensor for inclusion in the Work by the copyright owner or by an
fc2ce9
+individual or Legal Entity authorized to submit on behalf of the
fc2ce9
+copyright owner. For the purposes of this definition, "submitted"
fc2ce9
+means any form of electronic, verbal, or written communication sent to
fc2ce9
+the Licensor or its representatives, including but not limited to
fc2ce9
+communication on electronic mailing lists, source code control
fc2ce9
+systems, and issue tracking systems that are managed by, or on behalf
fc2ce9
+of, the Licensor for the purpose of discussing and improving the Work,
fc2ce9
+but excluding communication that is conspicuously marked or otherwise
fc2ce9
+designated in writing by the copyright owner as "Not a Contribution."
fc2ce9
+
fc2ce9
+"Contributor" shall mean Licensor and any individual or Legal Entity
fc2ce9
+on behalf of whom a Contribution has been received by Licensor and
fc2ce9
+subsequently incorporated within the Work.
fc2ce9
+
fc2ce9
+2. Grant of Copyright License. Subject to the terms and conditions of
fc2ce9
+this License, each Contributor hereby grants to You a perpetual,
fc2ce9
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
fc2ce9
+copyright license to reproduce, prepare Derivative Works of, publicly
fc2ce9
+display, publicly perform, sublicense, and distribute the Work and
fc2ce9
+such Derivative Works in Source or Object form.
fc2ce9
+
fc2ce9
+3. Grant of Patent License. Subject to the terms and conditions of
fc2ce9
+this License, each Contributor hereby grants to You a perpetual,
fc2ce9
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except
fc2ce9
+as stated in this section) patent license to make, have made, use,
fc2ce9
+offer to sell, sell, import, and otherwise transfer the Work, where
fc2ce9
+such license applies only to those patent claims licensable by such
fc2ce9
+Contributor that are necessarily infringed by their Contribution(s)
fc2ce9
+alone or by combination of their Contribution(s) with the Work to
fc2ce9
+which such Contribution(s) was submitted. If You institute patent
fc2ce9
+litigation against any entity (including a cross-claim or counterclaim
fc2ce9
+in a lawsuit) alleging that the Work or a Contribution incorporated
fc2ce9
+within the Work constitutes direct or contributory patent
fc2ce9
+infringement, then any patent licenses granted to You under this
fc2ce9
+License for that Work shall terminate as of the date such litigation
fc2ce9
+is filed.
fc2ce9
+
fc2ce9
+4. Redistribution. You may reproduce and distribute copies of the Work
fc2ce9
+or Derivative Works thereof in any medium, with or without
fc2ce9
+modifications, and in Source or Object form, provided that You meet
fc2ce9
+the following conditions:
fc2ce9
+
fc2ce9
+    You must give any other recipients of the Work or Derivative Works
fc2ce9
+    a copy of this License; and
fc2ce9
+
fc2ce9
+    You must cause any modified files to carry prominent notices
fc2ce9
+    stating that You changed the files; and
fc2ce9
+
fc2ce9
+    You must retain, in the Source form of any Derivative Works that
fc2ce9
+    You distribute, all copyright, patent, trademark, and attribution
fc2ce9
+    notices from the Source form of the Work, excluding those notices
fc2ce9
+    that do not pertain to any part of the Derivative Works; and
fc2ce9
+
fc2ce9
+    If the Work includes a "NOTICE" text file as part of its
fc2ce9
+    distribution, then any Derivative Works that You distribute must
fc2ce9
+    include a readable copy of the attribution notices contained
fc2ce9
+    within such NOTICE file, excluding those notices that do not
fc2ce9
+    pertain to any part of the Derivative Works, in at least one of
fc2ce9
+    the following places: within a NOTICE text file distributed as
fc2ce9
+    part of the Derivative Works; within the Source form or
fc2ce9
+    documentation, if provided along with the Derivative Works; or,
fc2ce9
+    within a display generated by the Derivative Works, if and
fc2ce9
+    wherever such third-party notices normally appear. The contents of
fc2ce9
+    the NOTICE file are for informational purposes only and do not
fc2ce9
+    modify the License. You may add Your own attribution notices
fc2ce9
+    within Derivative Works that You distribute, alongside or as an
fc2ce9
+    addendum to the NOTICE text from the Work, provided that such
fc2ce9
+    additional attribution notices cannot be construed as modifying
fc2ce9
+    the License. You may add Your own copyright statement to Your
fc2ce9
+    modifications and may provide additional or different license
fc2ce9
+    terms and conditions for use, reproduction, or distribution of
fc2ce9
+    Your modifications, or for any such Derivative Works as a whole,
fc2ce9
+    provided Your use, reproduction, and distribution of the Work
fc2ce9
+    otherwise complies with the conditions stated in this License.
fc2ce9
+
fc2ce9
+5. Submission of Contributions. Unless You explicitly state otherwise,
fc2ce9
+any Contribution intentionally submitted for inclusion in the Work by
fc2ce9
+You to the Licensor shall be under the terms and conditions of this
fc2ce9
+License, without any additional terms or conditions. Notwithstanding
fc2ce9
+the above, nothing herein shall supersede or modify the terms of any
fc2ce9
+separate license agreement you may have executed with Licensor
fc2ce9
+regarding such Contributions.
fc2ce9
+
fc2ce9
+6. Trademarks. This License does not grant permission to use the trade
fc2ce9
+names, trademarks, service marks, or product names of the Licensor,
fc2ce9
+except as required for reasonable and customary use in describing the
fc2ce9
+origin of the Work and reproducing the content of the NOTICE file.
fc2ce9
+
fc2ce9
+7. Disclaimer of Warranty. Unless required by applicable law or agreed
fc2ce9
+to in writing, Licensor provides the Work (and each Contributor
fc2ce9
+provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR
fc2ce9
+CONDITIONS OF ANY KIND, either express or implied, including, without
fc2ce9
+limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
fc2ce9
+MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
fc2ce9
+responsible for determining the appropriateness of using or
fc2ce9
+redistributing the Work and assume any risks associated with Your
fc2ce9
+exercise of permissions under this License.
fc2ce9
+
fc2ce9
+8. Limitation of Liability. In no event and under no legal theory,
fc2ce9
+whether in tort (including negligence), contract, or otherwise, unless
fc2ce9
+required by applicable law (such as deliberate and grossly negligent
fc2ce9
+acts) or agreed to in writing, shall any Contributor be liable to You
fc2ce9
+for damages, including any direct, indirect, special, incidental, or
fc2ce9
+consequential damages of any character arising as a result of this
fc2ce9
+License or out of the use or inability to use the Work (including but
fc2ce9
+not limited to damages for loss of goodwill, work stoppage, computer
fc2ce9
+failure or malfunction, or any and all other commercial damages or
fc2ce9
+losses), even if such Contributor has been advised of the possibility
fc2ce9
+of such damages.
fc2ce9
+
fc2ce9
+9. Accepting Warranty or Additional Liability. While redistributing
fc2ce9
+the Work or Derivative Works thereof, You may choose to offer, and
fc2ce9
+charge a fee for, acceptance of support, warranty, indemnity, or other
fc2ce9
+liability obligations and/or rights consistent with this
fc2ce9
+License. However, in accepting such obligations, You may act only on
fc2ce9
+Your own behalf and on Your sole responsibility, not on behalf of any
fc2ce9
+other Contributor, and only if You agree to indemnify, defend, and
fc2ce9
+hold each Contributor harmless for any liability incurred by, or
fc2ce9
+claims asserted against, such Contributor by reason of your accepting
fc2ce9
+any such warranty or additional liability.
fc2ce9
+
fc2ce9
+END OF TERMS AND CONDITIONS
fc2ce9
+APPENDIX: How to apply the Apache License to your work
fc2ce9
+
fc2ce9
+To apply the Apache License to your work, attach the following
fc2ce9
+boilerplate notice, with the fields enclosed by brackets "[]" replaced
fc2ce9
+with your own identifying information. (Don't include the brackets!)
fc2ce9
+The text should be enclosed in the appropriate comment syntax for the
fc2ce9
+file format. We also recommend that a file or class name and
fc2ce9
+description of purpose be included on the same "printed page" as the
fc2ce9
+copyright notice for easier identification within third-party
fc2ce9
+archives.
fc2ce9
+
fc2ce9
+   Copyright [yyyy] [name of copyright owner]
fc2ce9
+
fc2ce9
+   Licensed under the Apache License, Version 2.0 (the "License");
fc2ce9
+   you may not use this file except in compliance with the License.
fc2ce9
+   You may obtain a copy of the License at
fc2ce9
+
fc2ce9
+       http://www.apache.org/licenses/LICENSE-2.0
fc2ce9
+
fc2ce9
+   Unless required by applicable law or agreed to in writing, software
fc2ce9
+   distributed under the License is distributed on an "AS IS" BASIS,
fc2ce9
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
fc2ce9
+   See the License for the specific language governing permissions and
fc2ce9
+   limitations under the License.
fc2ce9
+
fc2ce9
diff -Naur ../jemalloc-3.0.0.orig/include/jemalloc/internal/atomic.h ./include/jemalloc/internal/atomic.h
fc2ce9
--- ../jemalloc-3.0.0.orig/include/jemalloc/internal/atomic.h	2012-05-12 02:50:38.000000000 +0200
fc2ce9
+++ ./include/jemalloc/internal/atomic.h	2012-05-18 15:55:34.457212405 +0200
fc2ce9
@@ -242,6 +242,33 @@
fc2ce9
 
fc2ce9
 	return (__sync_sub_and_fetch(p, x));
fc2ce9
 }
fc2ce9
+#elif (defined(__ppc__) || defined(__PPC__))
fc2ce9
+// Code fetched from the boost library
fc2ce9
+// 
fc2ce9
+JEMALLOC_INLINE uint32_t
fc2ce9
+atomic_add_uint32(uint32_t *p, uint32_t x)
fc2ce9
+{
fc2ce9
+	uint32_t prev, temp;
fc2ce9
+
fc2ce9
+	asm volatile ("0:\n\t"                 // retry local label     
fc2ce9
+               "lwarx  %0,0,%2\n\t"       // load prev and reserve 
fc2ce9
+               "add    %1,%0,%3\n\t"      // temp = prev + x 
fc2ce9
+               "stwcx. %1,0,%2\n\t"       // conditionally store   
fc2ce9
+               "bne-   0b"                // start over if we lost
fc2ce9
+                                          // the reservation
fc2ce9
+               //XXX find a cleaner way to define the temp         
fc2ce9
+               //it's not an output
fc2ce9
+               : "=&r" (prev), "=&r" (temp)        // output, temp 
fc2ce9
+               : "b" (p), "r" (x)                  // inputs       
fc2ce9
+               : "memory", "cc");                  // clobbered    
fc2ce9
+	return temp;
fc2ce9
+}
fc2ce9
+
fc2ce9
+JEMALLOC_INLINE uint32_t
fc2ce9
+atomic_sub_uint32(uint32_t *p, uint32_t x)
fc2ce9
+{
fc2ce9
+	return atomic_add_uint32(p, -x);
fc2ce9
+}
fc2ce9
 #else
fc2ce9
 #  error "Missing implementation for 32-bit atomic operations"
fc2ce9
 #endif