csutil/threading/atomicops_gcc_generic.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

csutil/threading/atomicops_gcc_generic.h

    00001 /*
    00002   Copyright (C) 2010 by Stefano Angeleri
    00003
    00004   This library is free software; you can redistribute it and/or
    00005   modify it under the terms of the GNU Lesser General Public
    00006   License as published by the Free Software Foundation; either
    00007   version 2 of the License, or (at your option) any later version.
    00008
    00009   This library is distributed in the hope that it will be useful,
    00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012   Library General Public License for more details.
    00013
    00014   You should have received a copy of the GNU Library General Public
    00015   License along with this library; if not, write to the Free
    00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CSUTIL_ATOMICOPS_GCC_GENERIC_H__
    00020 #define __CS_CSUTIL_ATOMICOPS_GCC_GENERIC_H__
    00021
    00022 #ifndef DOXYGEN_RUN
    00023
    00024 namespace CS
    00025 {
    00026 namespace Threading
    00027 {
    00028   class CS_CRYSTALSPACE_EXPORT AtomicOperationsGenericGCC
    00029   {
    00030     public:
    00031     inline static int32 Set (int32* target, int32 value)
    00032     {
    00033       return __sync_lock_test_and_set (target, value);
    00034     }
    00035
    00036     inline static void* Set (void** target, void* value)
    00037     {
    00038       return __sync_lock_test_and_set (target, value);
    00039     }
    00040
    00041     inline static int32 CompareAndSet (int32* target, int32 value,
    00042       int32 comparand)
    00043     {
    00044       return __sync_val_compare_and_swap (target, comparand, value);
    00045     }
    00046
    00047     inline static void* CompareAndSet (void** target, void* value,
    00048       void* comparand)
    00049     {
    00050       return __sync_val_compare_and_swap (target, comparand, value);
    00051     }
    00052
    00053     inline static int32 Increment (int32* target, register int32 incr = 1)
    00054     {
    00055       return __sync_fetch_and_add (target, incr);
    00056     }
    00057
    00058     inline static int32 Decrement (int32* target)
    00059     {
    00060       return __sync_fetch_and_sub (target, 1);
    00061     }
    00062   };
    00063 }
    00064 }
    00065
    00066 #endif // DOXYGEN_RUN
    00067
    00068 #endif // __CS_CSUTIL_ATOMICOPS_GCC_GENERIC_H__