Skip to content

Commit 735022d

Browse files
authored
Merge pull request #367 from elliott-bfs/366-nx_bsd_select_wakeup-spurious-events
Fixed issue #366 Refactor `select()` socket suspend structures
2 parents 00ea00b + e43986f commit 735022d

2 files changed

Lines changed: 23 additions & 49 deletions

File tree

addons/BSD/nxd_bsd.c

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8226,19 +8226,24 @@ INT ret;
82268226
suspend_request.nx_bsd_socket_suspend_actual_flags = 0;
82278227

82288228
if(readfds)
8229-
suspend_request.nx_bsd_socket_suspend_read_fd_set = *readfds;
8229+
suspend_request.nx_bsd_socket_suspend_read_request_fd_set = *readfds;
82308230
else
8231-
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_fd_set);
8231+
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_request_fd_set);
82328232

82338233
if(writefds)
8234-
suspend_request.nx_bsd_socket_suspend_write_fd_set = *writefds;
8234+
suspend_request.nx_bsd_socket_suspend_write_request_fd_set = *writefds;
82358235
else
8236-
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_fd_set);
8236+
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_request_fd_set);
82378237

82388238
if(exceptfds)
8239-
suspend_request.nx_bsd_socket_suspend_exception_fd_set = *exceptfds;
8239+
suspend_request.nx_bsd_socket_suspend_exception_request_fd_set = *exceptfds;
82408240
else
8241-
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_fd_set);
8241+
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_request_fd_set);
8242+
8243+
/* Clear the actual fd sets, which will be set in nx_bsd_select_wakeup(). */
8244+
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_fd_set);
8245+
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_fd_set);
8246+
NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_fd_set);
82428247

82438248
/* Temporarily disable preemption. */
82448249
tx_thread_preemption_change(current_thread_ptr, 0, &original_threshold);
@@ -10242,20 +10247,17 @@ TX_THREAD *current_thread_ptr;
1024210247
static VOID nx_bsd_select_wakeup(UINT sock_id, UINT fd_sets)
1024310248
{
1024410249
TX_INTERRUPT_SAVE_AREA
10245-
nx_bsd_fd_set local_fd;
1024610250
TX_THREAD *suspended_thread;
1024710251
ULONG suspended_count;
1024810252
ULONG original_suspended_count;
1024910253
NX_BSD_SOCKET_SUSPEND *suspend_info;
10254+
INT bsd_sock_id;
1025010255

1025110256

1025210257
/* At this point the thread should NOT own the IP mutex, and it must own the
1025310258
BSD mutex. */
1025410259

10255-
10256-
NX_BSD_FD_ZERO(&local_fd);
10257-
NX_BSD_FD_SET((INT)sock_id + NX_BSD_SOCKFD_START, &local_fd);
10258-
10260+
bsd_sock_id = (INT)sock_id + NX_BSD_SOCKFD_START;
1025910261
/* Disable interrupts temporarily. */
1026010262
TX_DISABLE
1026110263

@@ -10280,65 +10282,34 @@ NX_BSD_SOCKET_SUSPEND *suspend_info;
1028010282
suspend_info = (NX_BSD_SOCKET_SUSPEND *) suspended_thread -> tx_thread_additional_suspend_info;
1028110283

1028210284
/* Now determine if this thread was waiting for this socket. */
10283-
if ((fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set)))
10285+
if ((fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET(bsd_sock_id, &suspend_info -> nx_bsd_socket_suspend_read_request_fd_set)))
1028410286
{
10287+
NX_BSD_FD_SET(bsd_sock_id, &suspend_info -> nx_bsd_socket_suspend_read_fd_set);
1028510288

10286-
/* Copy the local fd over so that the return shows the receive socket. */
10287-
suspend_info -> nx_bsd_socket_suspend_read_fd_set = local_fd;
10288-
10289-
/* Adjust the suspension type so that the event flag set below will wakeup the thread
10289+
/* Adjust the suspension type so that the event flag set below will wakeup the thread
1029010290
selecting. */
1029110291
suspended_thread -> tx_thread_suspend_info = NX_BSD_RECEIVE_EVENT;
1029210292
}
1029310293

1029410294
/* Now determine if this thread was waiting for this socket. */
10295-
if ((fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set)))
10295+
if ((fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET(bsd_sock_id, &suspend_info -> nx_bsd_socket_suspend_write_request_fd_set)))
1029610296
{
10297-
10298-
/* Copy the local fd over so that the return shows the receive socket. */
10299-
suspend_info -> nx_bsd_socket_suspend_write_fd_set = local_fd;
10297+
NX_BSD_FD_SET(bsd_sock_id, &suspend_info -> nx_bsd_socket_suspend_write_fd_set);
1030010298

1030110299
/* Adjust the suspension type so that the event flag set below will wakeup the thread
1030210300
selecting. */
1030310301
suspended_thread -> tx_thread_suspend_info = NX_BSD_RECEIVE_EVENT;
1030410302
}
1030510303

1030610304
/* Now determine if this thread was waiting for this socket. */
10307-
if ((fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set)))
10305+
if ((fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET(bsd_sock_id, &suspend_info -> nx_bsd_socket_suspend_exception_request_fd_set)))
1030810306
{
10309-
10310-
/* Copy the local fd over so that the return shows the receive socket. */
10311-
suspend_info -> nx_bsd_socket_suspend_exception_fd_set = local_fd;
10307+
NX_BSD_FD_SET(bsd_sock_id, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set);
1031210308

1031310309
/* Adjust the suspension type so that the event flag set below will wakeup the thread
1031410310
selecting. */
1031510311
suspended_thread -> tx_thread_suspend_info = NX_BSD_RECEIVE_EVENT;
1031610312
}
10317-
10318-
/* Clear FD that is not set. */
10319-
if (suspended_thread -> tx_thread_suspend_info == NX_BSD_RECEIVE_EVENT)
10320-
{
10321-
if (!(fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set)))
10322-
{
10323-
10324-
/* Clear read FD. */
10325-
NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set);
10326-
}
10327-
10328-
if (!(fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set)))
10329-
{
10330-
10331-
/* Clear write FD. */
10332-
NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set);
10333-
}
10334-
10335-
if (!(fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set)))
10336-
{
10337-
10338-
/* Clear exception FD. */
10339-
NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set);
10340-
}
10341-
}
1034210313
}
1034310314

1034410315
/* Now move to the next event. */

addons/BSD/nxd_bsd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ typedef struct FD_SET_STRUCT /* The select socket array manager.
708708
typedef struct NX_BSD_SOCKET_SUSPEND_STRUCT
709709
{
710710
ULONG nx_bsd_socket_suspend_actual_flags;
711+
nx_bsd_fd_set nx_bsd_socket_suspend_read_request_fd_set;
712+
nx_bsd_fd_set nx_bsd_socket_suspend_write_request_fd_set;
713+
nx_bsd_fd_set nx_bsd_socket_suspend_exception_request_fd_set;
711714
nx_bsd_fd_set nx_bsd_socket_suspend_read_fd_set;
712715
nx_bsd_fd_set nx_bsd_socket_suspend_write_fd_set;
713716
nx_bsd_fd_set nx_bsd_socket_suspend_exception_fd_set;

0 commit comments

Comments
 (0)