diff --git a/libs/libc/netdb/lib_dns.h b/libs/libc/netdb/lib_dns.h index 25ed4fedf1..996bc8683f 100644 --- a/libs/libc/netdb/lib_dns.h +++ b/libs/libc/netdb/lib_dns.h @@ -151,6 +151,26 @@ void dns_lock(void); void dns_unlock(void); +/**************************************************************************** + * Name: dns_breaklock + * + * Description: + * Break the DNS lock + * + ****************************************************************************/ + +void dns_breaklock(FAR unsigned int *count); + +/**************************************************************************** + * Name: dns_restorelock + * + * Description: + * Restore the DNS lock + * + ****************************************************************************/ + +void dns_restorelock(unsigned int count); + /**************************************************************************** * Name: dns_bind * diff --git a/libs/libc/netdb/lib_dnsforeach.c b/libs/libc/netdb/lib_dnsforeach.c index 5ce67f4aee..75d4e58cf2 100644 --- a/libs/libc/netdb/lib_dnsforeach.c +++ b/libs/libc/netdb/lib_dnsforeach.c @@ -80,6 +80,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) char line[DNS_MAX_LINE]; FAR char *addrstr; FAR char *ptr; + unsigned int count; uint16_t port; int keylen; int ret; @@ -186,8 +187,10 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) { u.ipv4.sin_family = AF_INET; u.ipv4.sin_port = port; + dns_breaklock(&count); ret = callback(arg, (FAR struct sockaddr *)&u.ipv4, sizeof(struct sockaddr_in)); + dns_restorelock(count); } else #endif @@ -205,8 +208,10 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) { u.ipv6.sin6_family = AF_INET6; u.ipv6.sin6_port = port; + dns_breaklock(&count); ret = callback(arg, (FAR struct sockaddr *)&u.ipv6, sizeof(struct sockaddr_in6)); + dns_restorelock(count); } else #endif @@ -235,6 +240,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) { FAR struct sockaddr *addr; + unsigned int count; int ret = OK; int i; @@ -255,7 +261,9 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) /* Perform the callback */ + dns_breaklock(&count); ret = callback(arg, addr, sizeof(struct sockaddr_in)); + dns_restorelock(count); } else #endif @@ -274,7 +282,9 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) /* Perform the callback */ + dns_breaklock(&count); ret = callback(arg, addr, sizeof(struct sockaddr_in6)); + dns_restorelock(count); } else #endif diff --git a/libs/libc/netdb/lib_dnsinit.c b/libs/libc/netdb/lib_dnsinit.c index 4d78b03b6d..4ce1dc7c26 100644 --- a/libs/libc/netdb/lib_dnsinit.c +++ b/libs/libc/netdb/lib_dnsinit.c @@ -43,7 +43,7 @@ static rmutex_t g_dns_lock = NXRMUTEX_INITIALIZER; /**************************************************************************** - * Private Functions + * Public Functions ****************************************************************************/ /**************************************************************************** @@ -71,3 +71,28 @@ void dns_unlock(void) { nxrmutex_unlock(&g_dns_lock); } + +/**************************************************************************** + * Name: dns_breaklock + * + * Description: + * Break the DNS lock + ****************************************************************************/ + +void dns_breaklock(FAR unsigned int *count) +{ + nxrmutex_breaklock(&g_dns_lock, count); +} + +/**************************************************************************** + * Name: dns_restorelock + * + * Description: + * Restore the DNS lock + * + ****************************************************************************/ + +void dns_restorelock(unsigned int count) +{ + nxrmutex_restorelock(&g_dns_lock, count); +}