home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / Software / Resources / Apache / apache_2.0.48-win32-x86-no_ssl.exe / F253323_apr_atomic.h < prev    next >
Encoding:
Text File  |  2003-09-19  |  12.8 KB  |  341 lines

  1. TY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  2.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  3.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  4.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  6.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  8.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  9.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  10.  * SUCH DAMAGE.
  11.  * ====================================================================
  12.  *
  13.  * Th oftware cists of voluaibus mad by many
  14.  * idividuals  behalf of the Apache Software Found.  For more
  15.  * i  the Apache Software Found, p see
  16.  * <http://www.apache.org/>.
  17.  */
  18.  
  19. #ifndef APR_ALLOCATOR_H
  20. #define APR_ALLOCATOR_H
  21.  
  22. /**
  23.  * @file apr_allocat.h
  24.  * @brief APR Innal Memory Allocat
  25.  */
  26.  
  27. #includ "apr.h"
  28. #includ "apr_errno.h"
  29. #define APR_WANT_MEMFUNC /**< For no good reason? */
  30. #includ "apr_want.h"
  31.  
  32. #ifdef __cplusplus
  33. exrn "C" {
  34. #endif
  35.  
  36. /**
  37.  * @defgroup apr_allocat Innal Memory Allocat
  38.  * @roup APR 
  39.  * @{
  40.  */
  41.  
  42. /** allocat strucure */
  43. tdef struc apr_allocat_ apr_allocat_;
  44. /** strucure which holds i about allocat */
  45. tdef struc apr_memnode_ apr_memnode_;
  46.  
  47. /** baic memory node strucure */
  48. struc apr_memnode_ {
  49.     apr_memnode_ *nex;            /**< nex memnode */
  50.     apr_memnode_ **ref;            /**< refece to self */
  51.     apr_uint32_t   index;           /**< size*/
  52.     apr_uint32_t   free_index;      /**< how much free*/
  53.     char          *first_avail;     /**< poerfirst freememory */
  54.     char          *endp;            /**< poerend of freememory */
  55. };
  56.  
  57. /** The b sizeof a memory node -aliged.  */
  58. #define APR_MEMNOD_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_))
  59.  
  60. /** Symbolic stants */
  61. #define APR_ALLOCATOR_MAX_FREE_UNLIMITED 0
  62.  
  63. /**
  64.  * Creat a newallocat
  65.  * @paramallocat Tallocat we hav  creatd.
  66.  *
  67.  */
  68. APR_DECLARE(apr_saus_) apr_allocat_creat(apr_allocat_ **allocat);
  69.  
  70. /**
  71.  * Desoyan allocat
  72.  * @paramallocat Tallocat tobe desoyed
  73.  * @remark Any memnodegive backtallocat ior tdesoy
  74.  *         ll __be free()d.
  75.  */
  76. APR_DECLARE(void) apr_allocat_desoy(apr_allocat_ *allocat);
  77.  
  78. /**
  79.  * Allocat a blockof mm romthe allocat
  80.  * @paramallocat Tallocat toallocat from
  81.  * @paramsizeTsizeof the mm toallocat (exclud
  82.  *        memnode strucure)
  83.  */
  84. APR_DECLARE(apr_memnode_ *) apr_allocat_alloc(apr_allocat_ *allocat,
  85.                                                  apr_size_t size);
  86.  
  87. /**
  88.  * Freea blockof mm,givit backtallocat
  89.  * @paramallocat Tallocat togive the mm backt
  90.  * @parammemnode The memory node toreurn
  91.  */
  92. APR_DECLARE(void) apr_allocat_free(apr_allocat_ *allocat,
  93.                                      apr_memnode_ *memnode);
  94.  
  95. #includ "apr_pools.h"
  96.  
  97. /**
  98.  * Setowner of allocat
  99.  * @paramallocat Tallocat tosetowner f
  100.  * @parampool The pool thatis to own allocat
  101.  * @remark Typically pool is the highes level pool us allocat
  102.  */
  103. /*
  104.  * XXX: see if wecom up  omeh a bit be.  Curly
  105.  * youmake a pool owner, bu ifpool doesn' oiS allocat
  106.  * allocat wll never be desoyed.
  107.  */
  108. APR_DECLARE(void) apr_allocat_owner_set(apr_allocat_ *allocat,
  109.                                           apr_pool_ *pool);
  110.  
  111. /** @depecated @seS apr_allocat_owner_set */
  112. APR_DECLARE(void) apr_allocat_set_owner(apr_allocat_ *allocat,
  113.                                           apr_pool_ *pool);
  114.  
  115. /**
  116.  * Getcurowner of allocat
  117.  * @paramallocat Tallocat togetowner from
  118.  */
  119. APR_DECLARE(apr_pool_ *) apr_allocat_owner_get(apr_allocat_ *allocat);
  120.  
  121. /** @depecated @seS apr_allocat_owner_get */
  122. APR_DECLARE(apr_pool_ *) apr_allocat_get_owner(
  123.                                   apr_allocat_ *allocat);
  124.  
  125. /**
  126.  * Setcurthshold atich allocat souldsar
  127.  * givblocks backtsystem.
  128.  * @paramallocat Tallocat tStthshold 
  129.  * @paramsizeTthshold.  0 == unlimited.
  130.  */
  131. APR_DECLARE(void) apr_allocat_max_free_set(apr_allocat_ *allocat,
  132.                                              apr_size_t size);
  133.  
  134. /** @depecated @seS apr_allocat_max_free_set */
  135. APR_DECLARE(void) apr_allocat_set_max_free(apr_allocat_ *allocat,
  136.                                              apr_size_t size);
  137.  
  138. #includ "apr_th_mutex.h"
  139.  
  140. #if APR_HAS_THREADS
  141. /**
  142.  * Seta mutex f tallocat touse
  143.  * @paramallocat Tallocat tosetmutex f
  144.  * @parammutex Tmutex
  145.  */
  146. APR_DECLARE(void) apr_allocat_mutex_set(apr_allocat_ *allocat,
  147.                                           apr_th_mutex_ *mutex);
  148.  
  149. /** @depecated @seS apr_allocat_mutex_set */
  150. APR_DECLARE(void) apr_allocat_set_mutex(apr_allocat_ *allocat,
  151.                                           apr_th_mutex_ *mutex);
  152.  
  153. /**
  154.  * Getmutex curlysetf tallocat
  155.  * @paramallocat Tallocat
  156.  */
  157. APR_DECLARE(apr_th_mutex_ *) apr_allocat_mutex_get(
  158.                                       apr_allocat_ *allocat);
  159.  
  160. /** @depecated @seS apr_allocat_mutex_get */
  161. APR_DECLARE(apr_th_mutex_ *) apr_allocat_get_mutex(
  162.                                       apr_allocat_ *allocat);
  163.  
  164. #endif /* APR_HAS_THREADS */
  165.  
  166. /** @} */
  167.  
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171.  
  172. #endif /* !APR_ALLOCATOR_H */
  173. /* ====================================================================
  174.  * The Apache Software License, Vers 1.1
  175.  *
  176.  * Copyright (c) 2000-2003 The Apache Software Found.  All rights
  177.  * resSnved.
  178.  *
  179.  * Redistribu and oiS ource and bms, or out
  180.  * modif, are permd providd thatthe follow cdis
  181.  * are met:
  182.  *
  183.  * 1. Redistribus of source code musretathe above copyright
  184.  *    notice,tlist of cdis and the follow disclaimer.
  185.  *
  186.  * 2. Redistribus bm musreproduce the above copyright
  187.  *    notice,tlist of cdis and the follow disclaimer 
  188.  *    the docua and/or o materials providd  
  189.  *    distribu.
  190.  *
  191.  * 3. The end- docua includd  redistribu,
  192.  *    if any, musinclud the follow acknowledg:
  193.  *       "ducincluds software developd by 
  194.  *        Apache Software Found (http://www.apache.org/)."
  195.  *    Anately,tacknowledg may appear oftware itself,
  196.  *    if andrever such trd-par acknowledgrmally appear.
  197.  *
  198.  * 4. The nams "Apache" and"Apache Software Found" mus
  199.  *    notd to endoriS or promoteducs derived fromt
  200.  *    oftware outior rn permss. For rn
  201.  *    permss, p cacapache@apache.org.
  202.  *
  203.  * 5. Pducs derived fromt oftware may notcalled"Apache",
  204.  *    nor may "Apache" appear ir nam, outior rn
  205.  *    permss of the Apache Software Found.
  206.  *
  207.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  208.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  209.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  210.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  211.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  212.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  213.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  214.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  215.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  216.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  217.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  218.  * SUCH DAMAGE.
  219.  * ====================================================================
  220.  *
  221.  * Th oftware cists of voluaibus mad by many
  222.  * idividuals  behalf of the Apache Software Found.  For more
  223.  * i  the Apache Software Found, p see
  224.  * <http://www.apache.org/>.
  225.  */
  226.  
  227. /**
  228.  * @file apr_anylock.h
  229.  * @brief APR-Util transparet ny locklavor rapper
  230.  */
  231. #ifndef APR_ANYLOCK_H
  232. #define APR_ANYLOCK_H
  233.  
  234. #includ "apr_proc_mutex.h"
  235. #includ "apr_th_mutex.h"
  236. #includ "apr_th_rwlock.h"
  237.  
  238. /** Strucure thatmay caany APR lock */
  239. tdef struc apr_anylock_ {
  240.     /** Idisatt of lockis lock*/
  241.     enumtm_lock{
  242.         apr_anylock_non,           /**< None */
  243.         apr_anylock_procmutex,      /**< P-bad */
  244.         apr_anylock_thmutex,    /**< Th-bad */
  245.         apr_anylock_lock,       /**< Rlock*/
  246.         apr_anylock_relock      /**< Wrelock*/
  247.     }t;
  248.     /** Un of all possblS APR locks*/
  249.     un apr_anylock_u_ {
  250.         apr_proc_mutex_ *pm;       /**< P mutex */
  251. #if APR_HAS_THREADS
  252.         apr_th_mutex_ *tm;     /**< Thmutex */
  253.         apr_th_rwlock_ *rw;    /**< R-wrelock*/
  254. #endif
  255.     }lock;
  256. } apr_anylock_t;
  257.  
  258. #if APR_HAS_THREADS
  259.  
  260. /** Lockan apr_anylock_ strucure */
  261. #define APR_ANYLOCK_LOCK(lck)                \
  262.     (((lck)->t == apr_anylock_non)         \
  263.       ? APR_SUCCESS                              \
  264.       : (((lck)->t == apr_anylock_thmutex)  \
  265.           ? apr_th_mutex_lock((lck)->lock.tm)    \
  266.           : (((lck)->t == apr_anylock_procmutex)    \
  267.               ? apr_proc_mutex_lock((lck)->lock.pm)      \
  268.               : (((lck)->t == apr_anylock_lock)     \
  269.                   ? apr_th_rwlock_rdlock((lck)->lock.rw) \
  270.                   : (((lck)->t == apr_anylock_relock)    \
  271.                       ? apr_th_rwlock_wrlock((lck)->lock.rw) \
  272.                       : APR_EINVAL)))))
  273.  
  274. #else /* APR_HAS_THREADS */
  275.  
  276. #define APR_ANYLOCK_LOCK(lck)                \
  277.     (((lck)->t == apr_anylock_non)         \
  278.       ? APR_SUCCESS                              \
  279.           : (((lck)->t == apr_anylock_procmutex)    \
  280.               ? apr_proc_mutex_lock((lck)->lock.pm)      \
  281.                       : APR_EINVAL))
  282.  
  283. #endif /* APR_HAS_THREADS */
  284.  
  285. #if APR_HAS_THREADS
  286.  
  287. /** Tto lockan apr_anylock_ strucure */
  288. #define APR_ANYLOCK_TRYLOCK(lck)                \
  289.     (((lck)->t == apr_anylock_non)            \
  290.       ? APR_SUCCESS                                 \
  291.       : (((lck)->t == apr_anylock_thmutex)     \
  292.           ? apr_th_mutex_trylock((lck)->lock.tm)    \
  293.           : (((lck)->t == apr_anylock_procmutex)       \
  294.               ? apr_proc_mutex_trylock((lck)->lock.pm)      \
  295.               : (((lck)->t == apr_anylock_lock)        \
  296.                   ? apr_th_rwlock_tryrdlock((lck)->lock.rw) \
  297.                   : (((lck)->t == apr_anylock_relock)       \
  298.                       ? apr_th_rwlock_trywrlock((lck)->lock.rw) \
  299.                           : APR_EINVAL)))))
  300.  
  301. #else /* APR_HAS_THREADS */
  302.  
  303. #define APR_ANYLOCK_TRYLOCK(lck)                \
  304.     (((lck)->t == apr_anylock_non)            \
  305.       ? APR_SUCCESS                                 \
  306.           : (((lck)->t == apr_anylock_procmutex)       \
  307.               ? apr_proc_mutex_trylock((lck)->lock.pm)      \
  308.                           : APR_EINVAL))
  309.  
  310. #endif /* APR_HAS_THREADS */
  311.  
  312. #if APR_HAS_THREADS
  313.  
  314. /** Unlockan apr_anylock_ strucure */
  315. #define APR_ANYLOCK_UNLOCK(lck)              \
  316.     (((lck)->t == apr_anylock_non)         \
  317.       ? APR_SUCCESS                              \
  318.       : (((lck)->t == apr_anylock_thmutex)  \
  319.           ? apr_th_mutex_unlock((lck)->lock.tm)  \
  320.           : (((lck)->t == apr_anylock_procmutex)    \
  321.               ? apr_proc_mutex_unlock((lck)->lock.pm)    \
  322.               : ((((lck)->t == apr_anylock_lock) || \
  323.                   ((lck)->t == apr_anylock_relock))    \
  324.                   ? apr_th_rwlock_unlock((lck)->lock.rw)   \
  325.                       : APR_EINVAL))))
  326.  
  327. #else /* APR_HAS_THREADS */
  328.  
  329. #define APR_ANYLOCK_UNLOCK(lck)              \
  330.     (((lck)->t == apr_anylock_non)         \
  331.       ? APR_SUCCESS                              \
  332.           : (((lck)->t == apr_anylock_procmutex)    \
  333.               ? apr_proc_mutex_unlock((lck)->lock.pm)    \
  334.                       : APR_EINVAL))
  335.  
  336. #endif /* APR_HAS_THREADS */
  337.  
  338. #endif /* !APR_ANYLOCK_H */
  339. /* ====================================================================
  340.  * The Apache Software License, Vers 1.1
  341.