yading@11: /* yading@11: * Copyright (c) 2012 Ronald S. Bultje yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_ATOMIC_H yading@11: #define AVUTIL_ATOMIC_H yading@11: yading@11: #include "config.h" yading@11: yading@11: #if HAVE_ATOMICS_GCC yading@11: #include "atomic_gcc.h" yading@11: #elif HAVE_ATOMICS_WIN32 yading@11: #include "atomic_win32.h" yading@11: #elif HAVE_ATOMICS_SUNCC yading@11: #include "atomic_suncc.h" yading@11: #else yading@11: yading@11: /** yading@11: * Load the current value stored in an atomic integer. yading@11: * yading@11: * @param ptr atomic integer yading@11: * @return the current value of the atomic integer yading@11: * @note This acts as a memory barrier. yading@11: */ yading@11: int avpriv_atomic_int_get(volatile int *ptr); yading@11: yading@11: /** yading@11: * Store a new value in an atomic integer. yading@11: * yading@11: * @param ptr atomic integer yading@11: * @param val the value to store in the atomic integer yading@11: * @note This acts as a memory barrier. yading@11: */ yading@11: void avpriv_atomic_int_set(volatile int *ptr, int val); yading@11: yading@11: /** yading@11: * Add a value to an atomic integer. yading@11: * yading@11: * @param ptr atomic integer yading@11: * @param inc the value to add to the atomic integer (may be negative) yading@11: * @return the new value of the atomic integer. yading@11: * @note This does NOT act as a memory barrier. This is primarily yading@11: * intended for reference counting. yading@11: */ yading@11: int avpriv_atomic_int_add_and_fetch(volatile int *ptr, int inc); yading@11: yading@11: /** yading@11: * Atomic pointer compare and swap. yading@11: * yading@11: * @param ptr pointer to the pointer to operate on yading@11: * @param oldval do the swap if the current value of *ptr equals to oldval yading@11: * @param newval value to replace *ptr with yading@11: * @return the value of *ptr before comparison yading@11: */ yading@11: void *avpriv_atomic_ptr_cas(void * volatile *ptr, void *oldval, void *newval); yading@11: yading@11: #endif /* HAVE_MEMORYBARRIER */ yading@11: #endif /* AVUTIL_ATOMIC_H */