1 /***************************************************************************/ 2 /* This code is part of WWW grabber called pavuk */ 3 /* Copyright (c) 1997 - 2001 Stefan Ondrejicka */ 4 /* Distributed under GPL 2 or later */ 5 /***************************************************************************/ 6 7 #ifndef _have_mt_h_ 8 #define _have_mt_h_ 9 10 #ifdef HAVE_MT 11 #include <pthread.h> 12 13 #define MT_STACK_SIZE 131072 14 15 extern pthread_key_t _mt_key_main_thread; 16 #define MT_IS_MAIN_THREAD() (pthread_getspecific(_mt_key_main_thread)) 17 18 extern pthread_mutex_t _mt_urlstack_lock; 19 extern pthread_mutex_t _mt_urlhash_lock; 20 extern pthread_mutex_t _mt_filehash_lock; 21 extern pthread_mutex_t _mt_cookies_lock; 22 extern pthread_mutex_t _mt_authinfo_lock; 23 extern pthread_mutex_t _mt_dns_lock; 24 extern pthread_mutex_t _mt_log_lock; 25 extern pthread_mutex_t _mt_slog_lock; 26 extern pthread_mutex_t _mt_tlog_lock; 27 extern pthread_mutex_t _mt_dcnt_lock; 28 extern pthread_mutex_t _mt_time_lock; 29 extern pthread_mutex_t _mt_ghbn_lock; 30 extern pthread_mutex_t _mt_getlfname_lock; 31 extern pthread_mutex_t _mt_proxy_lock; 32 extern pthread_mutex_t _mt_output_lock; 33 extern pthread_mutex_t _mt_dirr_lock; 34 extern pthread_mutex_t _mt_tcnt_lock; 35 extern pthread_mutex_t _mt_gtktree_lock; 36 extern pthread_mutex_t _mt_gtkstatus_lock; 37 extern pthread_mutex_t _mt_gtklog_lock; 38 extern pthread_mutex_t _mt_rejcnt_lock; 39 extern pthread_mutex_t _mt_failcnt_lock; 40 extern pthread_mutex_t _mt_gcfg_lock; 41 extern pthread_mutex_t _mt_nscache_lock; 42 extern pthread_mutex_t _mt_robots_lock; 43 extern pthread_mutex_t _mt_dumpurls_lock; 44 extern pthread_mutex_t _mt_dumpfd_lock; 45 extern pthread_mutex_t _mt_taghash_lock; 46 extern pthread_mutex_t _mt_jsres_lock; 47 extern pthread_mutex_t _mt_inet_ntoa_lock; 48 extern pthread_mutex_t _mt_mozjs_lock; 49 extern pthread_mutex_t _mt_ssl_map_lock; 50 51 #define LOCK_CFG_URLSTACK mt_pthread_mutex_lock(&_mt_urlstack_lock, "urlstack") 52 #define UNLOCK_CFG_URLSTACK mt_pthread_mutex_unlock(&_mt_urlstack_lock, "urlstack") 53 #define LOCK_CFG_URLHASH mt_pthread_mutex_lock(&_mt_urlhash_lock, "urlhash") 54 #define UNLOCK_CFG_URLHASH mt_pthread_mutex_unlock(&_mt_urlhash_lock, "urlhash") 55 #define LOCK_CFG_FILEHASH mt_pthread_mutex_lock(&_mt_filehash_lock, "filehash") 56 #define UNLOCK_CFG_FILEHASH mt_pthread_mutex_unlock(&_mt_filehash_lock, "filehash") 57 #define LOCK_COOKIES mt_pthread_mutex_lock(&_mt_cookies_lock, "cookies") 58 #define UNLOCK_COOKIES mt_pthread_mutex_unlock(&_mt_cookies_lock, "cookies") 59 #define LOCK_AUTHINFO mt_pthread_mutex_lock(&_mt_authinfo_lock, "authinfo") 60 #define UNLOCK_AUTHINFO mt_pthread_mutex_unlock(&_mt_authinfo_lock, "authinfo") 61 #define LOCK_GETLFNAME mt_pthread_mutex_lock(&_mt_getlfname_lock, "getlfname") 62 #define UNLOCK_GETLFNAME mt_pthread_mutex_unlock(&_mt_getlfname_lock, "getlfname") 63 #define LOCK_DNS mt_pthread_mutex_lock(&_mt_dns_lock, "dns") 64 #define UNLOCK_DNS mt_pthread_mutex_unlock(&_mt_dns_lock, "dns") 65 #define LOCK_SSL_MAP mt_pthread_mutex_lock(&_mt_ssl_map_lock, "ssl_map") 66 #define UNLOCK_SSL_MAP mt_pthread_mutex_unlock(&_mt_ssl_map_lock, "ssl_map") 67 #define LOCK_LOG mt_pthread_mutex_lock(&_mt_log_lock, "log") 68 #define UNLOCK_LOG mt_pthread_mutex_unlock(&_mt_log_lock, "log") 69 #define LOCK_SLOG mt_pthread_mutex_lock(&_mt_slog_lock, "slog") 70 #define UNLOCK_SLOG mt_pthread_mutex_unlock(&_mt_slog_lock, "slog") 71 #define LOCK_TLOG mt_pthread_mutex_lock(&_mt_tlog_lock, "tlog") 72 #define UNLOCK_TLOG mt_pthread_mutex_unlock(&_mt_tlog_lock, "tlog") 73 #define LOCK_DCNT mt_pthread_mutex_lock(&_mt_dcnt_lock, "dcnt") 74 #define UNLOCK_DCNT mt_pthread_mutex_unlock(&_mt_dcnt_lock, "dcnt") 75 #define LOCK_TIME mt_pthread_mutex_lock(&_mt_time_lock, "time") 76 #define UNLOCK_TIME mt_pthread_mutex_unlock(&_mt_time_lock, "time") 77 #define LOCK_GHBN mt_pthread_mutex_lock(&_mt_ghbn_lock, "ghbn") 78 #define UNLOCK_GHBN mt_pthread_mutex_unlock(&_mt_ghbn_lock, "ghbn") 79 #define LOCK_OUTPUT mt_pthread_mutex_lock(&_mt_output_lock, "output") 80 #define UNLOCK_OUTPUT mt_pthread_mutex_unlock(&_mt_output_lock, "output") 81 #define LOCK_PROXY mt_pthread_mutex_lock(&_mt_proxy_lock, "proxy") 82 #define UNLOCK_PROXY mt_pthread_mutex_unlock(&_mt_proxy_lock, "proxy") 83 #define LOCK_DIRR mt_pthread_mutex_lock(&_mt_dirr_lock, "dirr") 84 #define UNLOCK_DIRR mt_pthread_mutex_unlock(&_mt_dirr_lock, "dirr") 85 #define LOCK_TCNT mt_pthread_mutex_lock(&_mt_tcnt_lock, "tcnt") 86 #define UNLOCK_TCNT mt_pthread_mutex_unlock(&_mt_tcnt_lock, "tcnt") 87 #define LOCK_GTKTREE mt_pthread_mutex_lock(&_mt_gtktree_lock, "gtktree") 88 #define UNLOCK_GTKTREE mt_pthread_mutex_unlock(&_mt_gtktree_lock, "gtktree") 89 #define LOCK_GTKSTATUS mt_pthread_mutex_lock(&_mt_gtkstatus_lock, "gtkstatus") 90 #define UNLOCK_GTKSTATUS mt_pthread_mutex_unlock(&_mt_gtkstatus_lock, "gtkstatus") 91 #define LOCK_GTKLOG mt_pthread_mutex_lock(&_mt_gtklog_lock, "gtklog") 92 #define UNLOCK_GTKLOG mt_pthread_mutex_unlock(&_mt_gtklog_lock, "gtklog") 93 #define LOCK_REJCNT mt_pthread_mutex_lock(&_mt_rejcnt_lock, "rejcnt") 94 #define UNLOCK_REJCNT mt_pthread_mutex_unlock(&_mt_rejcnt_lock, "rejcnt") 95 #define LOCK_FAILCNT mt_pthread_mutex_lock(&_mt_failcnt_lock, "failcnt") 96 #define UNLOCK_FAILCNT mt_pthread_mutex_unlock(&_mt_failcnt_lock, "failcnt") 97 #define LOCK_URL(lurl) mt_pthread_mutex_lock(&(lurl)->lock, "url") 98 #define UNLOCK_URL(lurl) mt_pthread_mutex_unlock(&(lurl)->lock, "url") 99 #define LOCK_GCFG mt_pthread_mutex_lock(&_mt_gcfg_lock, "gcfg") 100 #define UNLOCK_GCFG mt_pthread_mutex_unlock(&_mt_gcfg_lock, "gcfg") 101 #define LOCK_NSCACHE mt_pthread_mutex_lock(&_mt_nscache_lock, "nscache") 102 #define UNLOCK_NSCACHE mt_pthread_mutex_unlock(&_mt_nscache_lock, "nscache") 103 #define LOCK_ROBOTS mt_pthread_mutex_lock(&_mt_robots_lock, "robots") 104 #define UNLOCK_ROBOTS mt_pthread_mutex_unlock(&_mt_robots_lock, "robots") 105 #define LOCK_DUMPURLS mt_pthread_mutex_lock(&_mt_dumpurls_lock, "dumpurls") 106 #define UNLOCK_DUMPURLS mt_pthread_mutex_unlock(&_mt_dumpurls_lock, "dumpurls") 107 #define LOCK_DUMPFD mt_pthread_mutex_lock(&_mt_dumpurls_lock, "dumpfd") 108 #define UNLOCK_DUMPFD mt_pthread_mutex_unlock(&_mt_dumpfd_lock, "dumpfd") 109 #define LOCK_TAG_HASH mt_pthread_mutex_lock(&_mt_taghash_lock, "tag_hash") 110 #define UNLOCK_TAG_HASH mt_pthread_mutex_unlock(&_mt_taghash_lock, "tag_hash") 111 #define LOCK_INETNTOA mt_pthread_mutex_lock(&_mt_inet_ntoa_lock, "inet_ntoa") 112 #define UNLOCK_INETNTOA mt_pthread_mutex_unlock(&_mt_inet_ntoa_lock, "inet_ntoa") 113 #define LOCK_MOZJS mt_pthread_mutex_lock(&_mt_mozjs_lock, "mozjs") 114 #define UNLOCK_MOZJS mt_pthread_mutex_unlock(&_mt_mozjs_lock, "mozjs") 115 116 #define _h_errno_ (*((int *)pthread_getspecific(cfg.herrno_key))) 117 118 extern int mt_pthread_mutex_lock(pthread_mutex_t *, char *); 119 extern int mt_pthread_mutex_unlock(pthread_mutex_t *, char *); 120 121 typedef struct _mt_semaphore 122 { 123 long v; 124 pthread_mutex_t mutex; 125 pthread_cond_t cond; 126 } mt_semaphore; 127 128 extern int mt_semaphore_init(mt_semaphore *); 129 extern int mt_semaphore_destroy(mt_semaphore *); 130 extern long mt_semaphore_up(mt_semaphore *); 131 extern long mt_semaphore_down(mt_semaphore *); 132 extern long mt_semaphore_timed_down(mt_semaphore *, int); 133 extern long mt_semaphore_timed_wait(mt_semaphore *, int); 134 extern long mt_semaphore_decrement(mt_semaphore *); 135 136 #else 137 138 #define MT_IS_MAIN_THREAD() TRUE 139 140 #define LOCK_CFG_URLSTACK 141 #define UNLOCK_CFG_URLSTACK 142 #define LOCK_CFG_URLHASH 143 #define UNLOCK_CFG_URLHASH 144 #define LOCK_CFG_FILEHASH 145 #define UNLOCK_CFG_FILEHASH 146 #define LOCK_COOKIES 147 #define UNLOCK_COOKIES 148 #define LOCK_AUTHINFO 149 #define UNLOCK_AUTHINFO 150 #define LOCK_DNS 151 #define UNLOCK_DNS 152 #define LOCK_SSL_MAP 153 #define UNLOCK_SSL_MAP 154 #define LOCK_LOG 155 #define UNLOCK_LOG 156 #define UNLOCK_SLOG 157 #define LOCK_SLOG 158 #define LOCK_TLOG 159 #define UNLOCK_TLOG 160 #define LOCK_GETLFNAME 161 #define UNLOCK_GETLFNAME 162 #define LOCK_DCNT 163 #define UNLOCK_DCNT 164 #define LOCK_TIME 165 #define UNLOCK_TIME 166 #define LOCK_OUTPUT 167 #define UNLOCK_OUTPUT 168 #define LOCK_GHBN 169 #define UNLOCK_GHBN 170 #define LOCK_PROXY 171 #define UNLOCK_PROXY 172 #define LOCK_DIRR 173 #define UNLOCK_DIRR 174 #define LOCK_TCNT 175 #define UNLOCK_TCNT 176 #define LOCK_GTKTREE 177 #define UNLOCK_GTKTREE 178 #define LOCK_GTKSTATUS 179 #define UNLOCK_GTKSTATUS 180 #define LOCK_GTKLOG 181 #define UNLOCK_GTKLOG 182 #define LOCK_REJCNT 183 #define UNLOCK_REJCNT 184 #define LOCK_FAILCNT 185 #define UNLOCK_FAILCNT 186 #define LOCK_URL(lurl) 187 #define UNLOCK_URL(lurl) 188 #define LOCK_GCFG 189 #define UNLOCK_GCFG 190 #define LOCK_NSCACHE 191 #define UNLOCK_NSCACHE 192 #define LOCK_ROBOTS 193 #define UNLOCK_ROBOTS 194 #define LOCK_DUMPURLS 195 #define UNLOCK_DUMPURLS 196 #define LOCK_DUMPFD 197 #define UNLOCK_DUMPFD 198 #define LOCK_TAG_HASH 199 #define UNLOCK_TAG_HASH 200 #define LOCK_INETNTOA 201 #define UNLOCK_INETNTOA 202 #define LOCK_MOZJS 203 #define UNLOCK_MOZJS 204 205 #define _h_errno_ h_errno 206 207 #endif 208 209 extern void mt_init(void); 210 211 #endif 212