Browse Source

Work on task #14780: Add debug helper asserts to ensure threading/locking requirements are met

Implement checks in unix port
master
Dirk Ziegelmeier 8 years ago
parent
commit
68385d37de
  1. 23
      ports/unix/lib/lwipopts.h
  2. 22
      ports/unix/minimal/lwipopts.h
  3. 40
      ports/unix/port/sys_arch.c
  4. 24
      ports/unix/unixsim/lwipopts.h

23
ports/unix/lib/lwipopts.h

@ -414,6 +414,27 @@
#define PPP_SUPPORT 0
/* Misc */
/*
---------------------------------------
---------- Threading options ----------
---------------------------------------
*/
#define LWIP_TCPIP_CORE_LOCKING 1
#if !NO_SYS
void sys_check_core_locking(void);
#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking()
void sys_mark_tcpip_thread(void);
#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread()
#if LWIP_TCPIP_CORE_LOCKING
void sys_lock_tcpip_core(void);
#define LOCK_TCPIP_CORE() sys_lock_tcpip_core()
void sys_unlock_tcpip_core(void);
#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core()
#endif
#endif
#endif /* LWIP_LWIPOPTS_H */

22
ports/unix/minimal/lwipopts.h

@ -437,4 +437,26 @@
extern unsigned char debug_flags;
#define LWIP_DBG_TYPES_ON debug_flags
/*
---------------------------------------
---------- Threading options ----------
---------------------------------------
*/
#define LWIP_TCPIP_CORE_LOCKING 1
#if !NO_SYS
void sys_check_core_locking(void);
#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking()
void sys_mark_tcpip_thread(void);
#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread()
#if LWIP_TCPIP_CORE_LOCKING
void sys_lock_tcpip_core(void);
#define LOCK_TCPIP_CORE() sys_lock_tcpip_core()
void sys_unlock_tcpip_core(void);
#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core()
#endif
#endif
#endif /* LWIP_LWIPOPTS_H */

40
ports/unix/port/sys_arch.c

@ -64,6 +64,7 @@
#include "lwip/sys.h"
#include "lwip/opt.h"
#include "lwip/stats.h"
#include "lwip/tcpip.h"
static void
get_monotonic_time(struct timespec *ts)
@ -180,6 +181,42 @@ sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksi
return st;
}
#if !NO_SYS
#if LWIP_TCPIP_CORE_LOCKING
static u8_t lwip_core_locked;
void sys_lock_tcpip_core(void)
{
sys_mutex_lock(&lock_tcpip_core);
lwip_core_locked = 1;
}
void sys_unlock_tcpip_core(void)
{
lwip_core_locked = 0;
sys_mutex_unlock(&lock_tcpip_core);
}
#endif /* LWIP_TCPIP_CORE_LOCKING */
static pthread_t lwip_tcpip_thread_id;
void sys_mark_tcpip_thread(void)
{
lwip_tcpip_thread_id = pthread_self();
}
void sys_check_core_locking(void)
{
if (lwip_tcpip_thread_id != 0) {
pthread_t current_thread_id = pthread_self();
#if LWIP_TCPIP_CORE_LOCKING
LWIP_ASSERT("Function called without core lock", (current_thread_id == lwip_tcpip_thread_id) || lwip_core_locked);
#else /* LWIP_TCPIP_CORE_LOCKING */
LWIP_ASSERT("Function called from wrong thread", current_thread_id == lwip_tcpip_thread_id);
#endif /* LWIP_TCPIP_CORE_LOCKING */
}
}
#endif /* !NO_SYS */
/*-----------------------------------------------------------------------------------*/
/* Mailbox */
err_t
@ -639,7 +676,8 @@ sys_arch_unprotect(sys_prot_t pval)
LWIP_UNUSED_ARG(pval);
if (lwprot_thread == pthread_self())
{
if (--lwprot_count == 0)
lwprot_count--;
if (lwprot_count == 0)
{
lwprot_thread = (pthread_t) 0xDEAD;
pthread_mutex_unlock(&lwprot_mutex);

24
ports/unix/unixsim/lwipopts.h

@ -369,6 +369,28 @@ extern void sntp_set_system_time(u32_t sec);
#endif /* PPP_SUPPORT > 0 */
#define LWIP_HTTPD_SSI 1
#define LWIP_HTTPD_SSI 1
/*
---------------------------------------
---------- Threading options ----------
---------------------------------------
*/
#define LWIP_TCPIP_CORE_LOCKING 1
#if !NO_SYS
void sys_check_core_locking(void);
#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking()
void sys_mark_tcpip_thread(void);
#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread()
#if LWIP_TCPIP_CORE_LOCKING
void sys_lock_tcpip_core(void);
#define LOCK_TCPIP_CORE() sys_lock_tcpip_core()
void sys_unlock_tcpip_core(void);
#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core()
#endif
#endif
#endif /* LWIP_LWIPOPTS_H */

Loading…
Cancel
Save