LTP GCOV extension - code coverage report
Current view: directory - Zend - zend_ts_hash.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 147
Code covered: 0.0 % Executed lines: 0
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | Zend Engine                                                          |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1998-2007 Zend Technologies Ltd. (http://www.zend.com) |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 2.00 of the Zend license,     |
       8                 :    | that is bundled with this package in the file LICENSE, and is        | 
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.zend.com/license/2_00.txt.                                |
      11                 :    | If you did not receive a copy of the Zend license and are unable to  |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@zend.com so we can mail you a copy immediately.              |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Authors: Harald Radi <harald.radi@nme.at>                            |
      16                 :    +----------------------------------------------------------------------+
      17                 : */
      18                 : 
      19                 : /* $Id: zend_ts_hash.c,v 1.14.2.1.2.1 2007/01/01 09:35:47 sebastian Exp $ */
      20                 : 
      21                 : #include "zend.h"
      22                 : #include "zend_ts_hash.h"
      23                 : 
      24                 : /* ts management functions */
      25                 : static void begin_read(TsHashTable *ht)
      26               0 : {
      27                 : #ifdef ZTS
      28                 :         tsrm_mutex_lock(ht->mx_reader);
      29                 :         if ((++(ht->reader)) == 1) {
      30                 :                 tsrm_mutex_lock(ht->mx_writer);
      31                 :         }
      32                 :         tsrm_mutex_unlock(ht->mx_reader);
      33                 : #endif
      34               0 : }
      35                 : 
      36                 : static void end_read(TsHashTable *ht)
      37               0 : {
      38                 : #ifdef ZTS
      39                 :         tsrm_mutex_lock(ht->mx_reader);
      40                 :         if ((--(ht->reader)) == 0) {
      41                 :                 tsrm_mutex_unlock(ht->mx_writer);
      42                 :         }
      43                 :         tsrm_mutex_unlock(ht->mx_reader);
      44                 : #endif
      45               0 : }
      46                 : 
      47                 : static void begin_write(TsHashTable *ht)
      48               0 : {
      49                 : #ifdef ZTS
      50                 :         tsrm_mutex_lock(ht->mx_writer);
      51                 : #endif
      52               0 : }
      53                 : 
      54                 : static void end_write(TsHashTable *ht)
      55               0 : {
      56                 : #ifdef ZTS
      57                 :         tsrm_mutex_unlock(ht->mx_writer);
      58                 : #endif
      59               0 : }
      60                 : 
      61                 : /* delegates */
      62                 : ZEND_API int _zend_ts_hash_init(TsHashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC)
      63               0 : {
      64                 : #ifdef ZTS
      65                 :         ht->mx_reader = tsrm_mutex_alloc();
      66                 :         ht->mx_writer = tsrm_mutex_alloc();
      67                 :         ht->reader = 0;
      68                 : #endif
      69               0 :         return _zend_hash_init(TS_HASH(ht), nSize, pHashFunction, pDestructor, persistent ZEND_FILE_LINE_RELAY_CC);
      70                 : }
      71                 : 
      72                 : ZEND_API int _zend_ts_hash_init_ex(TsHashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC)
      73               0 : {
      74                 : #ifdef ZTS
      75                 :         ht->mx_reader = tsrm_mutex_alloc();
      76                 :         ht->mx_writer = tsrm_mutex_alloc();
      77                 :         ht->reader = 0;
      78                 : #endif
      79               0 :         return _zend_hash_init_ex(TS_HASH(ht), nSize, pHashFunction, pDestructor, persistent, bApplyProtection ZEND_FILE_LINE_RELAY_CC);
      80                 : }
      81                 : 
      82                 : ZEND_API void zend_ts_hash_destroy(TsHashTable *ht)
      83               0 : {
      84                 : #ifdef ZTS
      85                 :         tsrm_mutex_free(ht->mx_reader);
      86                 :         tsrm_mutex_free(ht->mx_writer);
      87                 : #endif
      88               0 :         zend_hash_destroy(TS_HASH(ht));
      89               0 : }
      90                 : 
      91                 : ZEND_API void zend_ts_hash_clean(TsHashTable *ht)
      92               0 : {
      93               0 :         ht->reader = 0;
      94               0 :         zend_hash_clean(TS_HASH(ht));
      95               0 : }
      96                 : 
      97                 : ZEND_API int _zend_ts_hash_add_or_update(TsHashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC)
      98               0 : {
      99                 :         int retval;
     100                 : 
     101               0 :         begin_write(ht);
     102               0 :         retval = _zend_hash_add_or_update(TS_HASH(ht), arKey, nKeyLength, pData, nDataSize, pDest, flag ZEND_FILE_LINE_RELAY_CC);
     103               0 :         end_write(ht);
     104                 : 
     105               0 :         return retval;
     106                 : }
     107                 : 
     108                 : ZEND_API int _zend_ts_hash_quick_add_or_update(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC)
     109               0 : {
     110                 :         int retval;
     111                 : 
     112               0 :         begin_write(ht);
     113               0 :         retval = _zend_hash_quick_add_or_update(TS_HASH(ht), arKey, nKeyLength, h, pData, nDataSize, pDest, flag ZEND_FILE_LINE_RELAY_CC);
     114               0 :         end_write(ht);
     115                 : 
     116               0 :         return retval;
     117                 : }
     118                 : 
     119                 : ZEND_API int _zend_ts_hash_index_update_or_next_insert(TsHashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC)
     120               0 : {
     121                 :         int retval;
     122                 : 
     123               0 :         begin_write(ht);
     124               0 :         retval = _zend_hash_index_update_or_next_insert(TS_HASH(ht), h, pData, nDataSize, pDest, flag ZEND_FILE_LINE_RELAY_CC);
     125               0 :         end_write(ht);
     126                 : 
     127               0 :         return retval;
     128                 : }
     129                 : 
     130                 : ZEND_API int zend_ts_hash_add_empty_element(TsHashTable *ht, char *arKey, uint nKeyLength)
     131               0 : {
     132                 :         int retval;
     133                 : 
     134               0 :         begin_write(ht);
     135               0 :         retval = zend_hash_add_empty_element(TS_HASH(ht), arKey, nKeyLength);
     136               0 :         end_write(ht);
     137                 : 
     138               0 :         return retval;
     139                 : }
     140                 : 
     141                 : ZEND_API void zend_ts_hash_graceful_destroy(TsHashTable *ht)
     142               0 : {
     143                 : #ifdef ZTS
     144                 :         tsrm_mutex_free(ht->mx_reader);
     145                 :         tsrm_mutex_free(ht->mx_reader);
     146                 : #endif
     147               0 :         zend_hash_graceful_destroy(TS_HASH(ht));
     148               0 : }
     149                 : 
     150                 : ZEND_API void zend_ts_hash_apply(TsHashTable *ht, apply_func_t apply_func TSRMLS_DC)
     151               0 : {
     152               0 :         begin_write(ht);
     153               0 :         zend_hash_apply(TS_HASH(ht), apply_func TSRMLS_CC);
     154               0 :         end_write(ht);
     155               0 : }
     156                 : 
     157                 : ZEND_API void zend_ts_hash_apply_with_argument(TsHashTable *ht, apply_func_arg_t apply_func, void *argument TSRMLS_DC)
     158               0 : {
     159               0 :         begin_write(ht);
     160               0 :         zend_hash_apply_with_argument(TS_HASH(ht), apply_func, argument TSRMLS_CC);
     161               0 :         end_write(ht);
     162               0 : }
     163                 : 
     164                 : ZEND_API void zend_ts_hash_apply_with_arguments(TsHashTable *ht, apply_func_args_t apply_func, int num_args, ...)
     165               0 : {
     166                 :         va_list args;
     167                 : 
     168               0 :         va_start(args, num_args);
     169               0 :         begin_write(ht);
     170               0 :         zend_hash_apply_with_arguments(TS_HASH(ht), apply_func, num_args, args);
     171               0 :         end_write(ht);
     172               0 :         va_end(args);
     173               0 : }
     174                 : 
     175                 : ZEND_API void zend_ts_hash_reverse_apply(TsHashTable *ht, apply_func_t apply_func TSRMLS_DC)
     176               0 : {
     177               0 :         begin_write(ht);
     178               0 :         zend_hash_reverse_apply(TS_HASH(ht), apply_func TSRMLS_CC);
     179               0 :         end_write(ht);
     180               0 : }
     181                 : 
     182                 : ZEND_API int zend_ts_hash_del_key_or_index(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag)
     183               0 : {
     184                 :         int retval;
     185                 : 
     186               0 :         begin_write(ht);
     187               0 :         retval = zend_hash_del_key_or_index(TS_HASH(ht), arKey, nKeyLength, h, flag);
     188               0 :         end_write(ht);
     189                 : 
     190               0 :         return retval;
     191                 : }
     192                 : 
     193                 : ZEND_API ulong zend_ts_get_hash_value(TsHashTable *ht, char *arKey, uint nKeyLength)
     194               0 : {
     195                 :         ulong retval;
     196                 : 
     197               0 :         begin_read(ht);
     198               0 :         retval = zend_get_hash_value(arKey, nKeyLength);
     199               0 :         end_read(ht);
     200                 : 
     201               0 :         return retval;
     202                 : }
     203                 : 
     204                 : ZEND_API int zend_ts_hash_find(TsHashTable *ht, char *arKey, uint nKeyLength, void **pData)
     205               0 : {
     206                 :         int retval;
     207                 : 
     208               0 :         begin_read(ht);
     209               0 :         retval = zend_hash_find(TS_HASH(ht), arKey, nKeyLength, pData);
     210               0 :         end_read(ht);
     211                 : 
     212               0 :         return retval;
     213                 : }
     214                 : 
     215                 : ZEND_API int zend_ts_hash_quick_find(TsHashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData)
     216               0 : {
     217                 :         int retval;
     218                 : 
     219               0 :         begin_read(ht);
     220               0 :         retval = zend_hash_quick_find(TS_HASH(ht), arKey, nKeyLength, h, pData);
     221               0 :         end_read(ht);
     222                 : 
     223               0 :         return retval;
     224                 : }
     225                 : 
     226                 : ZEND_API int zend_ts_hash_index_find(TsHashTable *ht, ulong h, void **pData)
     227               0 : {
     228                 :         int retval;
     229                 : 
     230               0 :         begin_read(ht);
     231               0 :         retval = zend_hash_index_find(TS_HASH(ht), h, pData);
     232               0 :         end_read(ht);
     233                 : 
     234               0 :         return retval;
     235                 : }
     236                 : 
     237                 : ZEND_API int zend_ts_hash_exists(TsHashTable *ht, char *arKey, uint nKeyLength)
     238               0 : {
     239                 :         int retval;
     240                 : 
     241               0 :         begin_read(ht);
     242               0 :         retval = zend_hash_exists(TS_HASH(ht), arKey, nKeyLength);
     243               0 :         end_read(ht);
     244                 : 
     245               0 :         return retval;
     246                 : }
     247                 : 
     248                 : ZEND_API int zend_ts_hash_index_exists(TsHashTable *ht, ulong h)
     249               0 : {
     250                 :         int retval;
     251                 : 
     252               0 :         begin_read(ht);
     253               0 :         retval = zend_hash_index_exists(TS_HASH(ht), h);
     254               0 :         end_read(ht);
     255                 : 
     256               0 :         return retval;
     257                 : }
     258                 : 
     259                 : ZEND_API void zend_ts_hash_copy(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size)
     260               0 : {
     261               0 :         begin_read(source);
     262               0 :         begin_write(target);
     263               0 :         zend_hash_copy(TS_HASH(target), TS_HASH(source), pCopyConstructor, tmp, size);
     264               0 :         end_write(target);
     265               0 :         end_read(source);
     266               0 : }
     267                 : 
     268                 : ZEND_API void zend_ts_hash_merge(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite)
     269               0 : {
     270               0 :         begin_read(source);
     271               0 :         begin_write(target);
     272               0 :         zend_hash_merge(TS_HASH(target), TS_HASH(source), pCopyConstructor, tmp, size, overwrite);
     273               0 :         end_write(target);
     274               0 :         end_read(source);
     275               0 : }
     276                 : 
     277                 : ZEND_API void zend_ts_hash_merge_ex(TsHashTable *target, TsHashTable *source, copy_ctor_func_t pCopyConstructor, uint size, merge_checker_func_t pMergeSource, void *pParam)
     278               0 : {
     279               0 :         begin_read(source);
     280               0 :         begin_write(target);
     281               0 :         zend_hash_merge_ex(TS_HASH(target), TS_HASH(source), pCopyConstructor, size, pMergeSource, pParam);
     282               0 :         end_write(target);
     283               0 :         end_read(source);
     284               0 : }
     285                 : 
     286                 : ZEND_API int zend_ts_hash_sort(TsHashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber TSRMLS_DC)
     287               0 : {
     288                 :         int retval;
     289                 : 
     290               0 :         begin_write(ht);
     291               0 :         retval = zend_hash_sort(TS_HASH(ht), sort_func, compare_func, renumber TSRMLS_CC);
     292               0 :         end_write(ht);
     293                 : 
     294               0 :         return retval;
     295                 : }
     296                 : 
     297                 : ZEND_API int zend_ts_hash_compare(TsHashTable *ht1, TsHashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC)
     298               0 : {
     299                 :         int retval;
     300                 : 
     301               0 :         begin_read(ht1);
     302               0 :         begin_read(ht2);
     303               0 :         retval = zend_hash_compare(TS_HASH(ht1), TS_HASH(ht2), compar, ordered TSRMLS_CC);
     304               0 :         end_read(ht2);
     305               0 :         end_read(ht1);
     306                 : 
     307               0 :         return retval;
     308                 : }
     309                 : 
     310                 : ZEND_API int zend_ts_hash_minmax(TsHashTable *ht, compare_func_t compar, int flag, void **pData TSRMLS_DC)
     311               0 : {
     312                 :         int retval;
     313                 : 
     314               0 :         begin_read(ht);
     315               0 :         retval = zend_hash_minmax(TS_HASH(ht), compar, flag, pData TSRMLS_CC);
     316               0 :         end_read(ht);
     317                 : 
     318               0 :         return retval;
     319                 : }
     320                 : 
     321                 : ZEND_API int zend_ts_hash_num_elements(TsHashTable *ht)
     322               0 : {
     323                 :         int retval;
     324                 : 
     325               0 :         begin_read(ht);
     326               0 :         retval = zend_hash_num_elements(TS_HASH(ht));
     327               0 :         end_read(ht);
     328                 : 
     329               0 :         return retval;
     330                 : }
     331                 : 
     332                 : ZEND_API int zend_ts_hash_rehash(TsHashTable *ht)
     333               0 : {
     334                 :         int retval;
     335                 : 
     336               0 :         begin_write(ht);
     337               0 :         retval = zend_hash_rehash(TS_HASH(ht));
     338               0 :         end_write(ht);
     339                 : 
     340               0 :         return retval;
     341                 : }
     342                 : 
     343                 : #if ZEND_DEBUG
     344                 : void zend_ts_hash_display_pListTail(TsHashTable *ht)
     345                 : {
     346                 :         begin_read(ht);
     347                 :         zend_hash_display_pListTail(TS_HASH(ht));
     348                 :         end_read(ht);
     349                 : }
     350                 : 
     351                 : void zend_ts_hash_display(TsHashTable *ht)
     352                 : {
     353                 :         begin_read(ht);
     354                 :         zend_hash_display(TS_HASH(ht));
     355                 :         end_read(ht);
     356                 : }
     357                 : #endif
     358                 : 
     359                 : /*
     360                 :  * Local variables:
     361                 :  * tab-width: 4
     362                 :  * c-basic-offset: 4
     363                 :  * indent-tabs-mode: t
     364                 :  * End:
     365                 :  */

Generated by: LTP GCOV extension version 1.5