From 210e6901653cf9dc7c04c8cd32371f575fd91a7e Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Tue, 14 Apr 2020 08:22:54 +0000 Subject: [PATCH] On Windows, smb_addmsg() was slow because smb_updatethread() was slow: So on Windows, calling unlock() on a file region that you don't have locked, incurs a delay. Likewise, calling lock() on a file region that already have locked incurs a delay. These delays were seriously throttling message imports on Windows (e.g. importing echomail or QWK packets). What should take a few seconds, was taking minutes with noticeable delays. This code has been performing redundant locks/unlocks for over 15 years, so I can only conclude that the performance penalty is a new behavior introduced in recent version(s) of Windows. --- src/smblib/smblib.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/smblib/smblib.c b/src/smblib/smblib.c index cb3ceb047b..a61efa230c 100644 --- a/src/smblib/smblib.c +++ b/src/smblib/smblib.c @@ -2000,6 +2000,7 @@ int SMBCALL smb_tzutc(int16_t zone) } /****************************************************************************/ +/* The caller needs to call smb_unlockmsghdr(smb,remsg) */ /****************************************************************************/ int SMBCALL smb_updatethread(smb_t* smb, smbmsg_t* remsg, ulong newmsgnum) { @@ -2011,16 +2012,15 @@ int SMBCALL smb_updatethread(smb_t* smb, smbmsg_t* remsg, ulong newmsgnum) if((remsg->offset==0 || remsg->idx.offset==0) /* index not read? */ && (retval=smb_getmsgidx(smb,remsg))!=SMB_SUCCESS) return(retval); - if((retval=smb_lockmsghdr(smb,remsg))!=SMB_SUCCESS) - return(retval); - if(!remsg->hdr.length /* header not read? */ - && (retval=smb_getmsghdr(smb,remsg))!=SMB_SUCCESS) - return(retval); - + if(!remsg->hdr.length) { /* header not read? */ + if((retval=smb_lockmsghdr(smb,remsg))!=SMB_SUCCESS) + return(retval); + if((retval=smb_getmsghdr(smb,remsg))!=SMB_SUCCESS) + return(retval); + } remsg->hdr.thread_first=newmsgnum; remsg->idx.attr = (remsg->hdr.attr |= MSG_REPLIED); retval=smb_putmsg(smb,remsg); - smb_unlockmsghdr(smb,remsg); return(retval); } -- GitLab