So something like attached?
I removed my raise/reset macro's.
It appears to work for me, I added a new private pool, not sure if this
was what you intended or not.
Let me know what you think.
BR
David
On 07/09/17 19:40, goldsi...@gmx.de wrote:
David Lockyer wrote:
Okay, thank you for the suggestion. Just to be clear are you
suggesting modifying lwip_select() to allocate select_cb from a pool
& free prior to return?
Via a define, like Joel wrote, yes. This might need a new memp pool
though...
We don't have an abstraction for your priviledge raising macro yet,
and I'm not sure it's the best solution for everyone using this mode,
either.
I will have to investigate the speed impact of this, as I have
MEM_LIBC_MALLOC and MAEP_MEM_MALLOC both defined as 1.
Well, you have this pool allocation at some other places already when
socket threads communicate with the tcpip thread for asynchronous things.
Having those 2 defines combined with a possibly slow libc malloc()
(heap) is probabably not the fastest solution, anyway.
The best thing to get this fixed would be
Simon
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
--- lwip-2.0.2/src/api/sockets.c (original)
+++ lwip-2.0.2/src/api/sockets.c (patched)
@@ -50,7 +50,6 @@
#include "lwip/sockets.h"
#include "lwip/api.h"
-#include "lwip/sys.h"
#include "lwip/igmp.h"
#include "lwip/inet.h"
#include "lwip/tcp.h"
@@ -76,6 +75,13 @@
#undef LWIP_NETCONN
#define LWIP_NETCONN 0
#endif
+
+#define API_SELECT_CB_VAR_REF(name) API_VAR_REF(name)
+#define API_SELECT_CB_VAR_DECLARE(name) API_VAR_DECLARE(struct lwip_select_cb, name)
+#define API_SELECT_CB_VAR_ALLOC(name) API_VAR_ALLOC(struct lwip_select_cb, MEMP_SELECT_CB, name, ERR_MEM)
+#define API_SELECT_CB_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC(struct lwip_select_cb, MEMP_SELECT_CB, name, NULL)
+#define API_SELECT_CB_VAR_FREE(name) API_VAR_FREE(MEMP_SELECT_CB, name)
+
#if LWIP_IPV4
#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \
@@ -218,32 +224,6 @@
SELWAIT_T select_waiting;
};
-#if LWIP_NETCONN_SEM_PER_THREAD
-#define SELECT_SEM_T sys_sem_t*
-#define SELECT_SEM_PTR(sem) (sem)
-#else /* LWIP_NETCONN_SEM_PER_THREAD */
-#define SELECT_SEM_T sys_sem_t
-#define SELECT_SEM_PTR(sem) (&(sem))
-#endif /* LWIP_NETCONN_SEM_PER_THREAD */
-
-/** Description for a task waiting in select */
-struct lwip_select_cb {
- /** Pointer to the next waiting task */
- struct lwip_select_cb *next;
- /** Pointer to the previous waiting task */
- struct lwip_select_cb *prev;
- /** readset passed to select */
- fd_set *readset;
- /** writeset passed to select */
- fd_set *writeset;
- /** unimplemented: exceptset passed to select */
- fd_set *exceptset;
- /** don't signal the same semaphore twice: set to 1 when signalled */
- int sem_signalled;
- /** semaphore to wake up a task waiting for select */
- SELECT_SEM_T sem;
-};
-
/** A struct sockaddr replacement that has the same alignment as sockaddr_in/
* sockaddr_in6 if instantiated.
*/
@@ -1375,13 +1355,15 @@
int nready;
fd_set lreadset, lwriteset, lexceptset;
u32_t msectimeout;
- struct lwip_select_cb select_cb;
+ API_SELECT_CB_VAR_DECLARE(select_cb);
int i;
int maxfdp2;
#if LWIP_NETCONN_SEM_PER_THREAD
int waited = 0;
#endif
SYS_ARCH_DECL_PROTECT(lev);
+
+ API_SELECT_CB_VAR_ALLOC(select_cb);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select(%d, %p, %p, %p, tvsec=%"S32_F" tvusec=%"S32_F")\n",
maxfdp1, (void *)readset, (void *) writeset, (void *) exceptset,
@@ -1406,18 +1388,19 @@
list is only valid while we are in this function, so it's ok
to use local variables. */
- select_cb.next = NULL;
- select_cb.prev = NULL;
- select_cb.readset = readset;
- select_cb.writeset = writeset;
- select_cb.exceptset = exceptset;
- select_cb.sem_signalled = 0;
+ API_SELECT_CB_VAR_REF(select_cb).next = NULL;
+ API_SELECT_CB_VAR_REF(select_cb).prev = NULL;
+ API_SELECT_CB_VAR_REF(select_cb).readset = readset;
+ API_SELECT_CB_VAR_REF(select_cb).writeset = writeset;
+ API_SELECT_CB_VAR_REF(select_cb).exceptset = exceptset;
+ API_SELECT_CB_VAR_REF(select_cb).sem_signalled = 0;
#if LWIP_NETCONN_SEM_PER_THREAD
- select_cb.sem = LWIP_NETCONN_THREAD_SEM_GET();
+ API_SELECT_CB_VAR_REF(select_cb).sem = LWIP_NETCONN_THREAD_SEM_GET();
#else /* LWIP_NETCONN_SEM_PER_THREAD */
- if (sys_sem_new(&select_cb.sem, 0) != ERR_OK) {
+ if (sys_sem_new(&API_SELECT_CB_VAR_REF(select_cb).sem, 0) != ERR_OK) {
/* failed to create semaphore */
set_errno(ENOMEM);
+ API_SELECT_CB_VAR_FREE(select_cb);
return -1;
}
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
@@ -1426,11 +1409,11 @@
SYS_ARCH_PROTECT(lev);
/* Put this select_cb on top of list */
- select_cb.next = select_cb_list;
+ API_SELECT_CB_VAR_REF(select_cb).next = select_cb_list;
if (select_cb_list != NULL) {
- select_cb_list->prev = &select_cb;
- }
- select_cb_list = &select_cb;
+ select_cb_list->prev = &API_SELECT_CB_VAR_REF(select_cb);
+ }
+ select_cb_list = &API_SELECT_CB_VAR_REF(select_cb);
/* Increasing this counter tells event_callback that the list has changed. */
select_cb_ctr++;
@@ -1477,7 +1460,7 @@
}
}
- waitres = sys_arch_sem_wait(SELECT_SEM_PTR(select_cb.sem), msectimeout);
+ waitres = sys_arch_sem_wait(SELECT_SEM_PTR(API_SELECT_CB_VAR_REF(select_cb).sem), msectimeout);
#if LWIP_NETCONN_SEM_PER_THREAD
waited = 1;
#endif
@@ -1507,32 +1490,33 @@
}
/* Take us off the list */
SYS_ARCH_PROTECT(lev);
- if (select_cb.next != NULL) {
- select_cb.next->prev = select_cb.prev;
- }
- if (select_cb_list == &select_cb) {
- LWIP_ASSERT("select_cb.prev == NULL", select_cb.prev == NULL);
- select_cb_list = select_cb.next;
+ if (API_SELECT_CB_VAR_REF(select_cb).next != NULL) {
+ API_SELECT_CB_VAR_REF(select_cb).next->prev = API_SELECT_CB_VAR_REF(select_cb).prev;
+ }
+ if (select_cb_list == &API_SELECT_CB_VAR_REF(select_cb)) {
+ LWIP_ASSERT("select_cb.prev == NULL", API_SELECT_CB_VAR_REF(select_cb).prev == NULL);
+ select_cb_list = API_SELECT_CB_VAR_REF(select_cb).next;
} else {
- LWIP_ASSERT("select_cb.prev != NULL", select_cb.prev != NULL);
- select_cb.prev->next = select_cb.next;
+ LWIP_ASSERT("select_cb.prev != NULL", API_SELECT_CB_VAR_REF(select_cb).prev != NULL);
+ API_SELECT_CB_VAR_REF(select_cb).prev->next = API_SELECT_CB_VAR_REF(select_cb).next;
}
/* Increasing this counter tells event_callback that the list has changed. */
select_cb_ctr++;
SYS_ARCH_UNPROTECT(lev);
#if LWIP_NETCONN_SEM_PER_THREAD
- if (select_cb.sem_signalled && (!waited || (waitres == SYS_ARCH_TIMEOUT))) {
+ if (API_SELECT_CB_VAR_REF(select_cb).sem_signalled && (!waited || (waitres == SYS_ARCH_TIMEOUT))) {
/* don't leave the thread-local semaphore signalled */
- sys_arch_sem_wait(select_cb.sem, 1);
+ sys_arch_sem_wait(API_SELECT_CB_VAR_REF(select_cb).sem, 1);
}
#else /* LWIP_NETCONN_SEM_PER_THREAD */
- sys_sem_free(&select_cb.sem);
+ sys_sem_free(&API_SELECT_CB_VAR_REF(select_cb).sem);
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
if (nready < 0) {
/* This happens when a socket got closed while waiting */
set_errno(EBADF);
+ API_SELECT_CB_VAR_FREE(select_cb);
return -1;
}
@@ -1560,6 +1544,7 @@
if (exceptset) {
*exceptset = lexceptset;
}
+ API_SELECT_CB_VAR_FREE(select_cb);
return nready;
}
--- lwip-2.0.2/src/include/lwip/opt.h (original)
+++ lwip-2.0.2/src/include/lwip/opt.h (patched)
@@ -455,6 +455,14 @@
#endif
/**
+ * MEMP_NUM_SELECT_CB: the number of struct lwip_select_cb.
+ * (only needed if you use the sequential API, like api_lib.c)
+ */
+#if !defined MEMP_NUM_SELECT_CB || defined __DOXYGEN__
+#define MEMP_NUM_SELECT_CB 4
+#endif
+
+/**
* MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used
* for callback/timeout API communication.
* (only needed if you use tcpip.c)
--- lwip-2.0.2/src/include/lwip/priv/memp_std.h (original)
+++ lwip-2.0.2/src/include/lwip/priv/memp_std.h (patched)
@@ -63,6 +63,10 @@
LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF")
LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn), "NETCONN")
#endif /* LWIP_NETCONN || LWIP_SOCKET */
+
+#if LWIP_SOCKET
+LWIP_MEMPOOL(SELECT_CB, MEMP_NUM_SELECT_CB, sizeof(struct lwip_select_cb), "SELECT_CB")
+#endif /* LWIP_SOCKET */
#if NO_SYS==0
LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API")
--- lwip-2.0.2/src/include/lwip/sockets.h (original)
+++ lwip-2.0.2/src/include/lwip/sockets.h (patched)
@@ -47,6 +47,7 @@
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/errno.h"
+#include "lwip/sys.h"
#ifdef __cplusplus
extern "C" {
@@ -157,6 +158,32 @@
void *msg_control;
socklen_t msg_controllen;
int msg_flags;
+};
+
+#if LWIP_NETCONN_SEM_PER_THREAD
+#define SELECT_SEM_T sys_sem_t*
+#define SELECT_SEM_PTR(sem) (sem)
+#else /* LWIP_NETCONN_SEM_PER_THREAD */
+#define SELECT_SEM_T sys_sem_t
+#define SELECT_SEM_PTR(sem) (&(sem))
+#endif /* LWIP_NETCONN_SEM_PER_THREAD */
+
+/** Description for a task waiting in select */
+struct lwip_select_cb {
+ /** Pointer to the next waiting task */
+ struct lwip_select_cb *next;
+ /** Pointer to the previous waiting task */
+ struct lwip_select_cb *prev;
+ /** readset passed to select */
+ fd_set *readset;
+ /** writeset passed to select */
+ fd_set *writeset;
+ /** unimplemented: exceptset passed to select */
+ fd_set *exceptset;
+ /** don't signal the same semaphore twice: set to 1 when signalled */
+ int sem_signalled;
+ /** semaphore to wake up a task waiting for select */
+ SELECT_SEM_T sem;
};
/* Socket protocol types (TCP/UDP/RAW) */
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users