Synesis Software

include/asm/atomic.h

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:    atomic.h
00003  *
00004  * Purpose: Declaration of Linux like atomic functions for the
00005  *          Win32 platform.
00006  *
00007  * Created: 21st November 2003
00008  * Updated: 12th September 2006
00009  *
00010  * Home:    http://synesis.com.au/software/
00011  *
00012  * Copyright (c) 2003-2006, Matthew Wilson and Synesis Software
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice, this
00019  *   list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright notice,
00021  *   this list of conditions and the following disclaimer in the documentation
00022  *   and/or other materials provided with the distribution.
00023  * - Neither the names of Matthew Wilson and Synesis Software nor the names of
00024  *   any contributors may be used to endorse or promote products derived from
00025  *   this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////////// */
00040 
00041 
00042 #ifndef SYNSOFT_UNIXEM_INCL_SYS_H_ATOMIC
00043 #define SYNSOFT_UNIXEM_INCL_SYS_H_ATOMIC
00044 
00045 #ifndef UNIXEM_DOCUMENTATION_SKIP_SECTION
00046 # define SYNSOFT_UNIXEM_VER_SYS_H_ATOMIC_MAJOR          2
00047 # define SYNSOFT_UNIXEM_VER_SYS_H_ATOMIC_MINOR          1
00048 # define SYNSOFT_UNIXEM_VER_SYS_H_ATOMIC_REVISION       1
00049 # define SYNSOFT_UNIXEM_VER_SYS_H_ATOMIC_EDIT           15
00050 #endif /* !UNIXEM_DOCUMENTATION_SKIP_SECTION */
00051 
00052 /* ////////////////////////////////////////////////////////////////////////// */
00053 
00054 #ifndef _WIN32
00055 # error This file is only currently defined for compilation on Win32 systems
00056 #endif /* _WIN32 */
00057 
00058 /* /////////////////////////////////////////////////////////////////////////////
00059  * Constants and definitions
00060  */
00061 
00062 
00063 /* /////////////////////////////////////////////////////////////////////////////
00064  * Typedefs
00065  */
00066 
00067 typedef signed long             atomic_t;
00068 
00069 /* /////////////////////////////////////////////////////////////////////////////
00070  * API functions
00071  */
00072 
00073 #ifdef __cplusplus
00074 extern "C" {
00075 #endif /* __cplusplus */
00076 
00077 #define ATOMIC_INIT(i)          (i)
00078 
00079 void    atomic_set(atomic_t volatile *v, int i);
00080 int     atomic_write(atomic_t volatile *v, int i);
00081 int     atomic_read(atomic_t volatile *v);
00082 
00083 void    atomic_add(int i, atomic_t volatile *v);
00084 void    atomic_sub(int i, atomic_t volatile *v);
00085 
00086 void    atomic_inc(atomic_t volatile *v);
00087 void    atomic_dec(atomic_t volatile *v);
00088 
00090 int     atomic_inc_and_test(atomic_t volatile *v);
00092 int     atomic_dec_and_test(atomic_t volatile *v);
00093 
00095 int     atomic_add_and_test(int i, atomic_t volatile *v);
00097 int     atomic_sub_and_test(int i, atomic_t volatile *v);
00098 
00099 #ifdef __cplusplus
00100 }
00101 #endif /* __cplusplus */
00102 
00103 /* ////////////////////////////////////////////////////////////////////////// */
00104 
00105 #endif /* SYNSOFT_UNIXEM_INCL_SYS_H_ATOMIC */
00106 
00107 /* ////////////////////////////////////////////////////////////////////////// */

UNIX Emulation for Win32 Libraries documentation © Synesis Software Pty Ltd, 2002-2005