From e2af95686c3fd471a2b2db32ae8395ef7543ad6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Lled=C3=B3?= <jlledom@member.fsf.org>
Date: Sat, 13 Jul 2019 10:12:15 +0200
Subject: [PATCH] Move core lock macros to include/lwip/sys.h
* LWIP_ASSERT_CORE_LOCKED and LWIP_MARK_TCPIP_THREAD moved
  to include/lwip/sys.h
* Unix port definitions of these macros moved to sys_arch.h

---
 contrib/ports/unix/lib/lwipopts.h               | 14 --------------
 contrib/ports/unix/port/include/arch/sys_arch.h | 20 ++++++++++++++++++++
 src/core/ipv4/acd.c                             |  2 +-
 src/core/ipv4/dhcp.c                            |  2 +-
 src/core/ipv4/etharp.c                          |  2 +-
 src/core/ipv4/igmp.c                            |  2 +-
 src/core/ipv4/ip4.c                             |  2 +-
 src/core/ipv6/ethip6.c                          |  2 +-
 src/core/ipv6/ip6.c                             |  2 +-
 src/core/ipv6/mld6.c                            |  2 +-
 src/core/raw.c                                  |  2 +-
 src/core/tcp.c                                  |  2 +-
 src/core/tcp_in.c                               |  2 +-
 src/core/tcp_out.c                              |  5 +----
 src/core/udp.c                                  |  2 +-
 src/include/lwip/apps/netbiosns_opts.h          |  2 +-
 src/include/lwip/opt.h                          | 22 ----------------------
 src/include/lwip/sys.h                          | 22 ++++++++++++++++++++++
 src/netif/ethernet.c                            |  2 +-
 19 files changed, 57 insertions(+), 54 deletions(-)

diff --git a/contrib/ports/unix/lib/lwipopts.h b/contrib/ports/unix/lib/lwipopts.h
index 660f7f70..1be73684 100644
--- a/contrib/ports/unix/lib/lwipopts.h
+++ b/contrib/ports/unix/lib/lwipopts.h
@@ -428,18 +428,4 @@
 
 #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 */
diff --git a/contrib/ports/unix/port/include/arch/sys_arch.h b/contrib/ports/unix/port/include/arch/sys_arch.h
index 416b716c..08328c73 100644
--- a/contrib/ports/unix/port/include/arch/sys_arch.h
+++ b/contrib/ports/unix/port/include/arch/sys_arch.h
@@ -62,4 +62,24 @@ typedef struct sys_thread * sys_thread_t;
 #define LWIP_EXAMPLE_APP_ABORT() lwip_unix_keypressed()
 int lwip_unix_keypressed(void);
 
+/*
+   ---------------------------------------
+   ---------- Threading options ----------
+   ---------------------------------------
+*/
+
+#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_ARCH_SYS_ARCH_H */
diff --git a/src/core/ipv4/acd.c b/src/core/ipv4/acd.c
index 138859a7..463441ff 100644
--- a/src/core/ipv4/acd.c
+++ b/src/core/ipv4/acd.c
@@ -61,7 +61,7 @@
  * Author: Dominik Spies <kontakt@dspies.de>
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 /* don't build if not configured for use in lwipopts.h */
 #if LWIP_IPV4 && LWIP_ACD
diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c
index d2195255..86fcb267 100644
--- a/src/core/ipv4/dhcp.c
+++ b/src/core/ipv4/dhcp.c
@@ -63,7 +63,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV4 && LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c
index 9d7bf299..fd15ef42 100644
--- a/src/core/ipv4/etharp.c
+++ b/src/core/ipv4/etharp.c
@@ -43,7 +43,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c
index b655aa3a..24f9d273 100644
--- a/src/core/ipv4/igmp.c
+++ b/src/core/ipv4/igmp.c
@@ -80,7 +80,7 @@ Steve Reynolds
  * Includes
  *----------------------------------------------------------------------------*/
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV4 && LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c
index 60d4042d..8aceeef5 100644
--- a/src/core/ipv4/ip4.c
+++ b/src/core/ipv4/ip4.c
@@ -38,7 +38,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV4
 
diff --git a/src/core/ipv6/ethip6.c b/src/core/ipv6/ethip6.c
index fec8b28a..c5df2cc9 100644
--- a/src/core/ipv6/ethip6.c
+++ b/src/core/ipv6/ethip6.c
@@ -39,7 +39,7 @@
  * <delamer@inicotech.com>
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV6 && LWIP_ETHERNET
 
diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c
index afa69f1b..85b0b75f 100644
--- a/src/core/ipv6/ip6.c
+++ b/src/core/ipv6/ip6.c
@@ -39,7 +39,7 @@
  * <delamer@inicotech.com>
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV6  /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c
index 86cc0818..eff9c036 100644
--- a/src/core/ipv6/mld6.c
+++ b/src/core/ipv6/mld6.c
@@ -51,7 +51,7 @@
 
 /* Based on igmp.c implementation of igmp v2 protocol */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_IPV6 && LWIP_IPV6_MLD  /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/raw.c b/src/core/raw.c
index cf7609c2..68947880 100644
--- a/src/core/raw.c
+++ b/src/core/raw.c
@@ -45,7 +45,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/tcp.c b/src/core/tcp.c
index d34f0e8c..23e27b2d 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -97,7 +97,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
index b6a4e4af..42cfe3e3 100644
--- a/src/core/tcp_in.c
+++ b/src/core/tcp_in.c
@@ -41,7 +41,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
index a00ce23f..13956b45 100644
--- a/src/core/tcp_out.c
+++ b/src/core/tcp_out.c
@@ -60,7 +60,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
 
@@ -74,9 +74,6 @@
 #include "lwip/stats.h"
 #include "lwip/ip6.h"
 #include "lwip/ip6_addr.h"
-#if LWIP_TCP_TIMESTAMPS
-#include "lwip/sys.h"
-#endif
 
 #include <string.h>
 
diff --git a/src/core/udp.c b/src/core/udp.c
index 96796884..b5b57e6d 100644
--- a/src/core/udp.c
+++ b/src/core/udp.c
@@ -45,7 +45,7 @@
 /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'!
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_UDP /* don't build if not configured for use in lwipopts.h */
 
diff --git a/src/include/lwip/apps/netbiosns_opts.h b/src/include/lwip/apps/netbiosns_opts.h
index 1f51ab02..9f3e1a95 100644
--- a/src/include/lwip/apps/netbiosns_opts.h
+++ b/src/include/lwip/apps/netbiosns_opts.h
@@ -32,7 +32,7 @@
 #ifndef LWIP_HDR_APPS_NETBIOS_OPTS_H
 #define LWIP_HDR_APPS_NETBIOS_OPTS_H
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 /**
  * @defgroup netbiosns_opts Options
diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
index 84f2b645..4e5296bc 100644
--- a/src/include/lwip/opt.h
+++ b/src/include/lwip/opt.h
@@ -214,28 +214,6 @@
 #endif
 
 /**
- * Macro/function to check whether lwIP's threading/locking
- * requirements are satisfied during current function call.
- * This macro usually calls a function that is implemented in the OS-dependent
- * sys layer and performs the following checks:
- * - Not in ISR (this should be checked for NO_SYS==1, too!)
- * - If @ref LWIP_TCPIP_CORE_LOCKING = 1: TCPIP core lock is held
- * - If @ref LWIP_TCPIP_CORE_LOCKING = 0: function is called from TCPIP thread
- * @see @ref multithreading
- */
-#if !defined LWIP_ASSERT_CORE_LOCKED || defined __DOXYGEN__
-#define LWIP_ASSERT_CORE_LOCKED()
-#endif
-
-/**
- * Called as first thing in the lwIP TCPIP thread. Can be used in conjunction
- * with @ref LWIP_ASSERT_CORE_LOCKED to check core locking.
- * @see @ref multithreading
- */
-#if !defined LWIP_MARK_TCPIP_THREAD || defined __DOXYGEN__
-#define LWIP_MARK_TCPIP_THREAD()
-#endif
-/**
  * @}
  */
 
diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h
index cf13e1dc..25bb84dd 100644
--- a/src/include/lwip/sys.h
+++ b/src/include/lwip/sys.h
@@ -552,6 +552,28 @@ void sys_arch_unprotect(sys_prot_t pval);
                               } while(0)
 #endif /* SYS_ARCH_LOCKED */
 
+/**
+ * Macro/function to check whether lwIP's threading/locking
+ * requirements are satisfied during current function call.
+ * This macro usually calls a function that is implemented in the OS-dependent
+ * sys layer and performs the following checks:
+ * - Not in ISR (this should be checked for NO_SYS==1, too!)
+ * - If @ref LWIP_TCPIP_CORE_LOCKING = 1: TCPIP core lock is held
+ * - If @ref LWIP_TCPIP_CORE_LOCKING = 0: function is called from TCPIP thread
+ * @see @ref multithreading
+ */
+#if !defined LWIP_ASSERT_CORE_LOCKED || defined __DOXYGEN__
+#define LWIP_ASSERT_CORE_LOCKED()
+#endif
+
+/**
+ * Called as first thing in the lwIP TCPIP thread. Can be used in conjunction
+ * with @ref LWIP_ASSERT_CORE_LOCKED to check core locking.
+ * @see @ref multithreading
+ */
+#if !defined LWIP_MARK_TCPIP_THREAD || defined __DOXYGEN__
+#define LWIP_MARK_TCPIP_THREAD()
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c
index 545ce460..5535a0a1 100644
--- a/src/netif/ethernet.c
+++ b/src/netif/ethernet.c
@@ -38,7 +38,7 @@
  *
  */
 
-#include "lwip/opt.h"
+#include "lwip/sys.h"
 
 #if LWIP_ARP || LWIP_ETHERNET
 
-- 
2.11.0

