1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more 2251875Speter * contributor license agreements. See the NOTICE file distributed with 3251875Speter * this work for additional information regarding copyright ownership. 4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0 5251875Speter * (the "License"); you may not use this file except in compliance with 6251875Speter * the License. You may obtain a copy of the License at 7251875Speter * 8251875Speter * http://www.apache.org/licenses/LICENSE-2.0 9251875Speter * 10251875Speter * Unless required by applicable law or agreed to in writing, software 11251875Speter * distributed under the License is distributed on an "AS IS" BASIS, 12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13251875Speter * See the License for the specific language governing permissions and 14251875Speter * limitations under the License. 15251875Speter */ 16251875Speter 17251875Speter#ifndef APR_ATOMIC_H 18251875Speter#define APR_ATOMIC_H 19251875Speter 20251875Speter/** 21251875Speter * @file apr_atomic.h 22251875Speter * @brief APR Atomic Operations 23251875Speter */ 24251875Speter 25251875Speter#include "apr.h" 26251875Speter#include "apr_pools.h" 27251875Speter 28251875Speter#ifdef __cplusplus 29251875Speterextern "C" { 30251875Speter#endif 31251875Speter 32251875Speter/** 33251875Speter * @defgroup apr_atomic Atomic Operations 34251875Speter * @ingroup APR 35251875Speter * @{ 36251875Speter */ 37251875Speter 38251875Speter/** 39251875Speter * this function is required on some platforms to initialize the 40251875Speter * atomic operation's internal structures 41251875Speter * @param p pool 42251875Speter * @return APR_SUCCESS on successful completion 43251875Speter * @remark Programs do NOT need to call this directly. APR will call this 44251875Speter * automatically from apr_initialize. 45251875Speter * @internal 46251875Speter */ 47251875SpeterAPR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p); 48251875Speter 49251875Speter/* 50251875Speter * Atomic operations on 32-bit values 51251875Speter * Note: Each of these functions internally implements a memory barrier 52251875Speter * on platforms that require it 53251875Speter */ 54251875Speter 55251875Speter/** 56251875Speter * atomically read an apr_uint32_t from memory 57251875Speter * @param mem the pointer 58251875Speter */ 59251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem); 60251875Speter 61251875Speter/** 62251875Speter * atomically set an apr_uint32_t in memory 63251875Speter * @param mem pointer to the object 64251875Speter * @param val value that the object will assume 65251875Speter */ 66251875SpeterAPR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val); 67251875Speter 68251875Speter/** 69251875Speter * atomically add 'val' to an apr_uint32_t 70251875Speter * @param mem pointer to the object 71251875Speter * @param val amount to add 72251875Speter * @return old value pointed to by mem 73251875Speter */ 74251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val); 75251875Speter 76251875Speter/** 77251875Speter * atomically subtract 'val' from an apr_uint32_t 78251875Speter * @param mem pointer to the object 79251875Speter * @param val amount to subtract 80251875Speter */ 81251875SpeterAPR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val); 82251875Speter 83251875Speter/** 84251875Speter * atomically increment an apr_uint32_t by 1 85251875Speter * @param mem pointer to the object 86251875Speter * @return old value pointed to by mem 87251875Speter */ 88251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem); 89251875Speter 90251875Speter/** 91251875Speter * atomically decrement an apr_uint32_t by 1 92251875Speter * @param mem pointer to the atomic value 93251875Speter * @return zero if the value becomes zero on decrement, otherwise non-zero 94251875Speter */ 95251875SpeterAPR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem); 96251875Speter 97251875Speter/** 98251875Speter * compare an apr_uint32_t's value with 'cmp'. 99251875Speter * If they are the same swap the value with 'with' 100251875Speter * @param mem pointer to the value 101251875Speter * @param with what to swap it with 102251875Speter * @param cmp the value to compare it to 103251875Speter * @return the old value of *mem 104251875Speter */ 105251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with, 106251875Speter apr_uint32_t cmp); 107251875Speter 108251875Speter/** 109251875Speter * exchange an apr_uint32_t's value with 'val'. 110251875Speter * @param mem pointer to the value 111251875Speter * @param val what to swap it with 112251875Speter * @return the old value of *mem 113251875Speter */ 114251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val); 115251875Speter 116251875Speter/** 117251875Speter * compare the pointer's value with cmp. 118251875Speter * If they are the same swap the value with 'with' 119251875Speter * @param mem pointer to the pointer 120251875Speter * @param with what to swap it with 121251875Speter * @param cmp the value to compare it to 122251875Speter * @return the old value of the pointer 123251875Speter */ 124251875SpeterAPR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp); 125251875Speter 126251875Speter/** 127251875Speter * exchange a pair of pointer values 128251875Speter * @param mem pointer to the pointer 129251875Speter * @param with what to swap it with 130251875Speter * @return the old value of the pointer 131251875Speter */ 132251875SpeterAPR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with); 133251875Speter 134251875Speter/** @} */ 135251875Speter 136251875Speter#ifdef __cplusplus 137251875Speter} 138251875Speter#endif 139251875Speter 140251875Speter#endif /* !APR_ATOMIC_H */ 141