Commits (1)
  • Deucе's avatar
    Remove RINGBUF_SEM for RINGBUG_EVENT · a2aa9631
    Deucе authored
    We've never really cared how many times the ring buffer has become
    empty, how many times data was added to it, or how many times we've
    been over the highwater mark.  These have effectively always been
    event signalling, with extra hackiness to clear "extra" semaphore
    posts.
    
    This commit removes RINGBUF_SEM entirely, and uses events for
    everything.  There's an empty event (set when the ring buffer is empty),
    a data event (set when the ring buffer is not empty), and a highwater
    event (set when the ring buffer has at least highwater mark bytes).
    
    A RingBufWrite() will set data and highwater events if applicable,
    and clear the empty event.
    
    A RingBufRead() will set empty event and clear data and highwater
    events if applicable.
    
    RingBufReInit() will now set the empty event, and clear the data
    and highwater events.
    
    These are the only actions the RingBuf API will perform on the
    events, it does *not* clear the highwater event on a RingBufWrite()
    if the buffer does not have enough bytes in it for example, this
    will *only* be done by RingBufRead() or RingBufReInit().  This
    allows consumers to force specific behaviours (such as forcing
    the highwater event on shutdown to prevent waiting for it).  Since
    the current code was able to deal with the semaphores having
    arbitrarily high counts, the existing code shouldn't have any
    issue with this.
    
    For things that want to shut something down, we're now setting both
    the data and highwater events to ensure it doesn't wait for a
    timeout (even for things that don't use highwater like the inbuf).
    The RingBuffer API should grow a thing to do this (RingBufferFlush
    perhaps?) rather than the consumers poking into the innards
    arbitrarily.
    
    Tested on the webserver and RLogin server and seems to be working
    great.  sexyz builds.  It seems there's some Windows thing that
    uses the ringbuffer sem for something, but I couldn't figure out
    what... updated the build file, but no clue if that's broken or not
    now... I'm sure DigitalMan will be happy to fix it if CI doesn't
    catch it. ;)
    
    This should allow the console object to grow a "flush" method that
    will set the highwater and data events.
    a2aa9631
......@@ -13,7 +13,7 @@ if(MSVC)
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS /wd4996)
endif()
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS RINGBUF_SEM RINGBUF_EVENT RINGBUF_MUTEX)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS RINGBUF_EVENT RINGBUF_MUTEX)
if(EXISTS /dev/random)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS HAS_DEV_RANDOM RANDOM_DEV="/dev/random")
......
......@@ -50,7 +50,7 @@
<DEBUGLIBPATH value="$(BCB)\lib\debug"/>
<RELEASELIBPATH value="$(BCB)\lib\release"/>
<LINKER value="ilink32"/>
<USERDEFINES value="SBBS;RINGBUF_SEM;RINGBUF_MUTEX;RINGBUF_EVENT;USE_CRYPTLIB;_DEBUG"/>
<USERDEFINES value="SBBS;RINGBUF_MUTEX;RINGBUF_EVENT;USE_CRYPTLIB;_DEBUG"/>
<SYSDEFINES value="NO_STRICT;_VIS_NOLIB"/>
<MAINSOURCE value="sbbsctrl.cpp"/>
<INCLUDEPATH value="..\;..;$(BCB)\Projects;..\..\xpdev;..\..\smblib;..\..\hash;$(BCB)\include;$(BCB)\include\vcl;..\..\..\3rdp\win32.release\cryptlib\include;..\..\comio"/>
......@@ -63,7 +63,7 @@
<IDLCFLAGS value="-I..\. -I.. -I$(BCB)\Projects -I..\..\xpdev
-I..\..\smblib -I..\..\hash -I$(BCB)\include -I$(BCB)\include\vcl
-I..\..\..\3rdp\win32.release\cryptlib\include -I..\..\comio -src_suffix
cpp -DSBBS -DRINGBUF_SEM -DRINGBUF_MUTEX -DUSE_CRYPTLIB -D_DEBUG -boa"/>
cpp -DSBBS -DRINGBUF_EVENT -DRINGBUF_MUTEX -DUSE_CRYPTLIB -D_DEBUG -boa"/>
<CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c
-tW -tWM"/>
<PFLAGS value="-$Y+ -$W -$O- -$A8 -v -JPHNE -M"/>
......@@ -221,11 +221,11 @@ Item0=$(BCB)\source\vcl
[HistoryLists\hlConditionals]
Count=9
Item0=SBBS;RINGBUF_SEM;RINGBUF_MUTEX;USE_CRYPTLIB;_DEBUG
Item1=SBBS;RINGBUF_SEM;RINGBUF_MUTEX;USE_CRYPTLIB
Item2=SBBS;_DEBUG;RINGBUF_SEM;RINGBUF_MUTEX;USE_CRYPTLIB
Item3=SBBS;_DEBUG;RINGBUF_SEM;RINGBUF_MUTEX
Item4=SBBS;_DEBUG;RINGBUF_SEM
Item0=SBBS;RINGBUF_EVENT;RINGBUF_MUTEX;USE_CRYPTLIB;_DEBUG
Item1=SBBS;RINGBUF_EVENT;RINGBUF_MUTEX;USE_CRYPTLIB
Item2=SBBS;_DEBUG;RINGBUF_EVENT;RINGBUF_MUTEX;USE_CRYPTLIB
Item3=SBBS;_DEBUG;RINGBUF_EVENT;RINGBUF_MUTEX
Item4=SBBS;_DEBUG;RINGBUF_EVENT
Item5=SBBS;_DEBUG
Item6=SBBS
Item7=SBBS;SMB_GETMSGTXT;_DEBUG
......@@ -256,4 +256,4 @@ AddServerUnit=1
AddClientUnit=1
PrecompiledHeaders=1
</IDEOPTIONS>
</PROJECT>
\ No newline at end of file
</PROJECT>
......@@ -29,6 +29,7 @@
#include "js_request.h"
#include "ssl.h"
#include "ver.h"
#include "eventwrap.h"
#include <multisock.h>
#include <limits.h> // HOST_NAME_MAX
......@@ -2117,7 +2118,8 @@ void input_thread(void *arg)
sbbs->sys_status|=SS_ABORT;
RingBufReInit(&sbbs->inbuf); /* Purge input buffer */
RingBufReInit(&sbbs->outbuf); /* Purge output buffer */
sem_post(&sbbs->inbuf.sem);
SetEvent(sbbs->inbuf.data_event);
SetEvent(sbbs->inbuf.highwater_event);
continue; // Ignore the entire buffer
}
......@@ -2343,23 +2345,20 @@ void output_thread(void* arg)
if(bufbot == buftop) {
/* Wait for something to output in the RingBuffer */
if((avail=RingBufFull(&sbbs->outbuf))==0) { /* empty */
if(sem_trywait_block(&sbbs->outbuf.sem,1000))
if (WaitForEvent(sbbs->outbuf.data_event, 1000) != WAIT_OBJECT_0)
continue;
/* Check for spurious sem post... */
if((avail=RingBufFull(&sbbs->outbuf))==0)
continue;
}
else
sem_trywait(&sbbs->outbuf.sem);
/* Wait for full buffer or drain timeout */
if(sbbs->outbuf.highwater_mark) {
if(avail<sbbs->outbuf.highwater_mark) {
sem_trywait_block(&sbbs->outbuf.highwater_sem,startup->outbuf_drain_timeout);
WaitForEvent(sbbs->outbuf.highwater_event, startup->outbuf_drain_timeout);
/* We (potentially) blocked, so get fill level again */
avail=RingBufFull(&sbbs->outbuf);
} else
sem_trywait(&sbbs->outbuf.highwater_sem);
}
}
/*
......@@ -3971,7 +3970,8 @@ void sbbs_t::hangup(void)
close_socket(client_socket);
client_socket=INVALID_SOCKET;
}
sem_post(&outbuf.sem);
SetEvent(outbuf.data_event);
SetEvent(outbuf.highwater_event);
}
int sbbs_t::incom(unsigned long timeout)
......@@ -3980,11 +3980,11 @@ int sbbs_t::incom(unsigned long timeout)
#if 0 /* looping version */
while(!RingBufRead(&inbuf, &ch, 1))
if(sem_trywait_block(&inbuf.sem,timeout)!=0 || sys_status&SS_ABORT)
if(WaitForEvent(inbuf.data_event, timeout) != WAIT_OBJECT_0 || sys_status&SS_ABORT)
return(NOINP);
#else
if(!RingBufRead(&inbuf, &ch, 1)) {
if(sem_trywait_block(&inbuf.sem,timeout)!=0)
if (WaitForEvent(inbuf.data_event, timeout) != WAIT_OBJECT_0)
return(NOINP);
if(!RingBufRead(&inbuf, &ch, 1))
return(NOINP);
......@@ -5805,7 +5805,8 @@ NO_SSH:
if(events!=NULL)
events->terminated=true;
// Wake-up BBS output thread so it can terminate
sem_post(&sbbs->outbuf.sem);
SetEvent(sbbs->outbuf.data_event);
SetEvent(sbbs->outbuf.highwater_event);
// Wait for all node threads to terminate
if(protected_uint32_value(node_threads_running)) {
......
REM Build SBBSEXEC.DLL (Synchronet Virtual UART/FOSSIL Device Driver)
cl /Di386 /Gz /O2 ntvdm.lib netapi32.lib /DRINGBUF_SEM /DRINGBUF_MUTEX /DNO_SOCKET_SUPPORT /I../xpdev /LD sbbsexec.c ringbuf.c ../xpdev/ini_file.c ../xpdev/dirwrap.c ../xpdev/str_list.c ../xpdev/xpdatetime.c ../xpdev/genwrap.c ../xpdev/semwrap.c ../xpdev/datewrap.c ../xpdev/xpprintf.c ../xpdev/threadwrap.c
cl /Di386 /Gz /O2 ntvdm.lib netapi32.lib /DRINGBUF_EVENT /DRINGBUF_MUTEX /DNO_SOCKET_SUPPORT /I../xpdev /LD sbbsexec.c ringbuf.c ../xpdev/ini_file.c ../xpdev/dirwrap.c ../xpdev/str_list.c ../xpdev/xpdatetime.c ../xpdev/genwrap.c ../xpdev/semwrap.c ../xpdev/datewrap.c ../xpdev/xpprintf.c ../xpdev/threadwrap.c
......@@ -95,11 +95,9 @@ int RingBufInit( RingBuf* rb, DWORD size
rb->pHead=rb->pTail=rb->pStart;
rb->pEnd=rb->pStart+size;
rb->size=size;
#ifdef RINGBUF_SEM
sem_init(&rb->sem,0,0);
sem_init(&rb->highwater_sem,0,0);
#endif
#ifdef RINGBUF_EVENT
rb->data_event=CreateEvent(NULL,TRUE,TRUE,NULL);
rb->highwater_event=CreateEvent(NULL,TRUE,TRUE,NULL);
rb->empty_event=CreateEvent(NULL,TRUE,TRUE,NULL);
#endif
#ifdef RINGBUF_MUTEX
......@@ -112,20 +110,19 @@ void RingBufDispose( RingBuf* rb)
{
if(rb->pStart!=NULL)
os_free(rb->pStart);
#ifdef RINGBUF_SEM
sem_post(&rb->sem); /* just incase someone's waiting */
while(sem_destroy(&rb->sem)==-1 && errno==EBUSY) {
SLEEP(1);
sem_post(&rb->sem);
}
while(sem_destroy(&rb->highwater_sem)==-1 && errno==EBUSY) {
SLEEP(1);
sem_post(&rb->highwater_sem);
}
#endif
#ifdef RINGBUF_EVENT
/*
* TODO: CloseEvent() will fail if there's any waiters...
* and the old semaphore posted an extra time
* "just incase"
*/
if(rb->empty_event!=NULL)
CloseEvent(rb->empty_event);
if(rb->data_event!=NULL)
CloseEvent(rb->data_event);
if(rb->highwater_event!=NULL)
CloseEvent(rb->highwater_event);
#endif
#ifdef RINGBUF_MUTEX
while(pthread_mutex_destroy(&rb->mutex)==EBUSY)
......@@ -206,14 +203,13 @@ DWORD RingBufWrite( RingBuf* rb, const BYTE* src, DWORD cnt )
if(rb->pHead > rb->pEnd)
rb->pHead = rb->pStart;
#ifdef RINGBUF_SEM
sem_post(&rb->sem);
if(rb->highwater_mark!=0 && RINGBUF_FILL_LEVEL(rb)>=rb->highwater_mark)
sem_post(&rb->highwater_sem);
#endif
#ifdef RINGBUF_EVENT
if(rb->empty_event!=NULL)
ResetEvent(rb->empty_event);
if (rb->data_event!=NULL)
SetEvent(rb->data_event);
if(rb->highwater_event!=NULL && rb->highwater_mark!=0 && RINGBUF_FILL_LEVEL(rb)>=rb->highwater_mark)
SetEvent(rb->highwater_event);
#endif
#ifdef RINGBUF_MUTEX
......@@ -265,16 +261,13 @@ DWORD RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt )
if(rb->pTail > rb->pEnd)
rb->pTail = rb->pStart;
#ifdef RINGBUF_SEM /* clear/signal semaphores, if appropriate */
if(RINGBUF_FILL_LEVEL(rb) == 0) /* empty */
sem_reset(&rb->sem);
if(RINGBUF_FILL_LEVEL(rb) < rb->highwater_mark)
sem_reset(&rb->highwater_sem);
#endif
#ifdef RINGBUF_EVENT
if(rb->empty_event!=NULL && RINGBUF_FILL_LEVEL(rb)==0)
if(rb->empty_event!=NULL && RINGBUF_FILL_LEVEL(rb)==0) {
SetEvent(rb->empty_event);
ResetEvent(rb->data_event);
}
if(rb->highwater_event!=NULL && rb->highwater_mark!=0 && RINGBUF_FILL_LEVEL(rb)<rb->highwater_mark)
ResetEvent(rb->highwater_event);
#endif
#ifdef RINGBUF_MUTEX
......@@ -331,9 +324,13 @@ void RingBufReInit(RingBuf* rb)
pthread_mutex_lock(&rb->mutex);
#endif
rb->pHead = rb->pTail = rb->pStart;
#ifdef RINGBUF_SEM
sem_reset(&rb->sem);
sem_reset(&rb->highwater_sem);
#ifdef RINGBUF_EVENT
if(rb->empty_event!=NULL)
SetEvent(rb->empty_event);
if (rb->data_event!=NULL)
ResetEvent(rb->data_event);
if(rb->highwater_event!=NULL && rb->highwater_mark!=0 && RINGBUF_FILL_LEVEL(rb)>=rb->highwater_mark)
ResetEvent(rb->highwater_event);
#endif
#ifdef RINGBUF_MUTEX
pthread_mutex_unlock(&rb->mutex);
......
......@@ -41,9 +41,6 @@
#include "gen_defs.h"
#ifdef RINGBUF_SEM
#include "semwrap.h" /* sem_t */
#endif
#ifdef RINGBUF_EVENT
#include "eventwrap.h" /* xpevent_t */
#endif
......@@ -68,13 +65,11 @@ typedef struct {
BYTE* pTail; /* next byte to be consumed */
BYTE* pEnd; /* end of the buffer, used for wrap around */
DWORD size;
#ifdef RINGBUF_SEM
sem_t sem; /* semaphore used to signal data waiting */
sem_t highwater_sem; /* semaphore used to signal highwater mark reached */
DWORD highwater_mark;
#endif
#ifdef RINGBUF_EVENT
xpevent_t empty_event;
xpevent_t data_event;
xpevent_t highwater_event;
DWORD highwater_mark;
#endif
#ifdef RINGBUF_MUTEX
pthread_mutex_t mutex; /* mutex used to protect ring buffer pointers */
......
......@@ -86,7 +86,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;BUILD_JSDOCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_EVENT;RINGBUF_MUTEX;BUILD_JSDOCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\msvc.win32.debug\sbbs/sbbs.pch</PrecompiledHeaderOutputFile>
......@@ -138,7 +138,7 @@
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
......@@ -818,4 +818,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -82,7 +82,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\msvc.win32.debug\sbbs/sbbs.pch</PrecompiledHeaderOutputFile>
......@@ -134,7 +134,7 @@
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;SBBS;SBBS_EXPORTS;SMB_EXPORTS;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
......@@ -807,4 +807,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -4,4 +4,4 @@
# $Id: sbbsdefs.mk,v 1.11 2010/03/12 01:32:02 deuce Exp $
SBBSDEFS= -DSBBS -DSBBS_EXPORTS -DSMB_EXPORTS -DMD5_EXPORTS -DRINGBUF_SEM -DRINGBUF_EVENT -DRINGBUF_MUTEX -DUSE_CRYPTLIB
SBBSDEFS= -DSBBS -DSBBS_EXPORTS -DSMB_EXPORTS -DMD5_EXPORTS -DRINGBUF_EVENT -DRINGBUF_MUTEX -DUSE_CRYPTLIB
......@@ -80,7 +80,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;i386;RINGBUF_SEM;RINGBUF_MUTEX;NO_SOCKET_SUPPORT;_DEBUG;SBBSEXEC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;i386;RINGBUF_MUTEX;NO_SOCKET_SUPPORT;_DEBUG;SBBSEXEC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CallingConvention>StdCall</CallingConvention>
......@@ -98,7 +98,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;i386;RINGBUF_SEM;RINGBUF_MUTEX;NO_SOCKET_SUPPORT;NDEBUG;SBBSEXEC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;i386;RINGBUF_MUTEX;NO_SOCKET_SUPPORT;NDEBUG;SBBSEXEC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<CallingConvention>StdCall</CallingConvention>
......@@ -115,4 +115,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -686,12 +686,9 @@ static void output_thread(void* arg)
avail=buftop-bufbot;
if(!avail) {
#if !defined(RINGBUF_EVENT)
SetEvent(outbuf_empty);
#endif
sem_wait(&outbuf.sem);
WaitForEvent(outbuf.data_event, INFINITE);
if(outbuf.highwater_mark)
sem_trywait_block(&outbuf.highwater_sem,outbuf_drain_timeout);
WaitForEvent(outbuf.highwater_event, outbuf_drain_timeout);
continue;
}
......@@ -1960,9 +1957,6 @@ int main(int argc, char **argv)
#endif
terminate=TRUE; /* stop output thread */
/* Code disabled. Why? ToDo */
/* sem_post(outbuf.sem);
sem_post(outbuf.highwater_sem); */
lprintf(LOG_INFO, "Exiting - Error level: %d, flows: %u, select_errors=%u"
,retval, flows, select_errors);
......
......@@ -66,7 +66,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\msvc.win32.debug\sexyz/sexyz.pch</PrecompiledHeaderOutputFile>
......@@ -110,7 +110,7 @@
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
......@@ -192,4 +192,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
</Project>
......@@ -1027,10 +1027,12 @@ static void drain_outbuf(http_session_t * session)
if(session->socket==INVALID_SOCKET)
return;
/* Force the output thread to go NOW */
sem_post(&(session->outbuf.highwater_sem));
SetEvent(session->outbuf.highwater_event);
/* ToDo: This should probobly timeout eventually... */
while(RingBufFull(&session->outbuf) && session->socket!=INVALID_SOCKET)
while(RingBufFull(&session->outbuf) && session->socket!=INVALID_SOCKET) {
SetEvent(session->outbuf.highwater_event);
SLEEP(1);
}
/* Lock the mutex to ensure data has been sent */
while(session->socket!=INVALID_SOCKET && !session->outbuf_write_initialized)
SLEEP(1);
......@@ -1065,7 +1067,7 @@ static void close_request(http_session_t * session)
}
/* Force the output thread to go NOW */
sem_post(&(session->outbuf.highwater_sem));
SetEvent(session->outbuf.highwater_event);
if(session->req.ld!=NULL) {
now=time(NULL);
......@@ -6397,23 +6399,20 @@ void http_output_thread(void *arg)
/* Wait for something to output in the RingBuffer */
if((avail=RingBufFull(obuf))==0) { /* empty */
if(sem_trywait_block(&obuf->sem,1000))
if(WaitForEvent(obuf->data_event, 1000) != WAIT_OBJECT_0)
continue;
/* Check for spurious sem post... */
if((avail=RingBufFull(obuf))==0)
continue;
}
else
sem_trywait(&obuf->sem);
/* Wait for full buffer or drain timeout */
if(obuf->highwater_mark) {
if(avail<obuf->highwater_mark) {
sem_trywait_block(&obuf->highwater_sem,startup->outbuf_drain_timeout);
WaitForEvent(obuf->highwater_event, startup->outbuf_drain_timeout);
/* We (potentially) blocked, so get fill level again */
avail=RingBufFull(obuf);
} else
sem_trywait(&obuf->highwater_sem);
}
}
/*
......
......@@ -81,7 +81,7 @@
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;WEBSRVR_EXPORTS;RINGBUF_SEM;RINGBUF_MUTEX;RINGBUF_EVENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;_USRDLL;WEBSRVR_EXPORTS;RINGBUF_MUTEX;RINGBUF_EVENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
......@@ -128,7 +128,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;WEBSRVR_EXPORTS;RINGBUF_SEM;RINGBUF_MUTEX;RINGBUF_EVENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;WEBSRVR_EXPORTS;RINGBUF_MUTEX;RINGBUF_EVENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeaderOutputFile>.\msvc.win32.debug\websrvr/websrvr.pch</PrecompiledHeaderOutputFile>
......@@ -197,4 +197,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
</Project>