1
0
mirror of https://github.com/rofl0r/proxychains-ng synced 2025-01-24 02:02:53 +08:00

use macros for mutex stuff

This commit is contained in:
rofl0r 2012-01-27 21:30:42 +01:00
parent c36db11ebc
commit 070051bb73
3 changed files with 13 additions and 19 deletions

View File

@ -69,15 +69,11 @@ uint32_t index_from_internal_ip(ip_type internalip) {
char *string_from_internal_ip(ip_type internalip) { char *string_from_internal_ip(ip_type internalip) {
char *res = NULL; char *res = NULL;
#ifdef THREAD_SAFE
pthread_mutex_lock(&internal_ips_lock);
#endif
uint32_t index = index_from_internal_ip(internalip); uint32_t index = index_from_internal_ip(internalip);
MUTEX_LOCK(&internal_ips_lock);
if(index < internal_ips.counter) if(index < internal_ips.counter)
res = internal_ips.list[index]->string; res = internal_ips.list[index]->string;
#ifdef THREAD_SAFE MUTEX_UNLOCK(&internal_ips_lock);
pthread_mutex_unlock(&internal_ips_lock);
#endif
return res; return res;
} }
@ -790,9 +786,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
hash = dalias_hash((char *) name); hash = dalias_hash((char *) name);
#ifdef THREAD_SAFE MUTEX_LOCK(&internal_ips_lock);
pthread_mutex_lock(&internal_ips_lock);
#endif
// see if we already have this dns entry saved. // see if we already have this dns entry saved.
if(internal_ips.counter) { if(internal_ips.counter) {
@ -839,10 +833,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
have_ip: have_ip:
#ifdef THREAD_SAFE MUTEX_UNLOCK(&internal_ips_lock);
pthread_mutex_unlock(&internal_ips_lock);
#endif
strncpy(addr_name, name, sizeof(addr_name)); strncpy(addr_name, name, sizeof(addr_name));
@ -851,9 +842,7 @@ struct hostent *proxy_gethostbyname(const char *name) {
return &hostent_space; return &hostent_space;
err_plus_unlock: err_plus_unlock:
#ifdef THREAD_SAFE MUTEX_UNLOCK(&internal_ips_lock);
pthread_mutex_unlock(&internal_ips_lock);
#endif
return NULL; return NULL;
} }
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {

View File

@ -40,6 +40,13 @@ extern internal_ip_lookup_table internal_ips;
#ifdef THREAD_SAFE #ifdef THREAD_SAFE
#include <pthread.h> #include <pthread.h>
extern pthread_mutex_t internal_ips_lock; extern pthread_mutex_t internal_ips_lock;
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
#else
# define MUTEX_LOCK(x)
# define MUTEX_UNLOCK(x)
# define MUTEX_INIT(x,y)
#endif #endif
/*error codes*/ /*error codes*/

View File

@ -61,9 +61,7 @@ static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, ch
static void init_lib(void); static void init_lib(void);
static void init_lib(void) { static void init_lib(void) {
#ifdef THREAD_SAFE MUTEX_INIT(&internal_ips_lock, NULL);
pthread_mutex_init(&internal_ips_lock, NULL);
#endif
/* read the config file */ /* read the config file */
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct); get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);