fiber for windows: client2 and server2 run very well:)

This commit is contained in:
zsxxsz 2018-01-22 22:01:12 +08:00
parent 49a92e9348
commit 66c05c16cb
7 changed files with 92 additions and 8 deletions

View File

@ -727,6 +727,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fiber", "lib_fiber\samples\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinEchod", "lib_fiber\samples\WinEchod\WinEchod.vcxproj", "{F74A61AD-A309-47A5-A7C6-BAC888660BBC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server2", "lib_fiber\samples\server2\server2_vc2012.vcxproj", "{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client2", "lib_fiber\samples\client2\client2_vc2012.vcxproj", "{A08F48F5-D359-4332-8743-F9D85887AEF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@ -3601,6 +3605,56 @@ Global
{F74A61AD-A309-47A5-A7C6-BAC888660BBC}.Template|Win32.ActiveCfg = DebugDll|Win32
{F74A61AD-A309-47A5-A7C6-BAC888660BBC}.Template|Win32.Build.0 = DebugDll|Win32
{F74A61AD-A309-47A5-A7C6-BAC888660BBC}.Template|x64.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Debug|Win32.ActiveCfg = Debug|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Debug|Win32.Build.0 = Debug|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Debug|x64.ActiveCfg = Debug|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.DebugDll|Win32.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.DebugDll|Win32.Build.0 = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.DebugDll|x64.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Release|Mixed Platforms.Build.0 = Release|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Release|Win32.ActiveCfg = Release|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Release|Win32.Build.0 = Release|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Release|x64.ActiveCfg = Release|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Releasedll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Releasedll|Mixed Platforms.Build.0 = ReleaseDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Releasedll|Win32.ActiveCfg = ReleaseDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Releasedll|Win32.Build.0 = ReleaseDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Releasedll|x64.ActiveCfg = ReleaseDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|Mixed Platforms.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|Mixed Platforms.Build.0 = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|Win32.ActiveCfg = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|Win32.Build.0 = DebugDll|Win32
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}.Template|x64.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Win32.ActiveCfg = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|Win32.Build.0 = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Debug|x64.ActiveCfg = Debug|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Win32.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|Win32.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.DebugDll|x64.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Mixed Platforms.Build.0 = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Win32.ActiveCfg = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|Win32.Build.0 = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Release|x64.ActiveCfg = Release|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Mixed Platforms.Build.0 = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Win32.ActiveCfg = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|Win32.Build.0 = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Releasedll|x64.ActiveCfg = ReleaseDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Mixed Platforms.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Mixed Platforms.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Win32.ActiveCfg = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|Win32.Build.0 = DebugDll|Win32
{A08F48F5-D359-4332-8743-F9D85887AEF6}.Template|x64.ActiveCfg = DebugDll|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -3730,5 +3784,7 @@ Global
{20299269-7A1C-45CB-8807-861745A55F82} = {3C576B18-D253-4CA2-986E-7173C2978AC3}
{BFCE4280-B6E5-414A-A8CD-F827A4A19B6F} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
{F74A61AD-A309-47A5-A7C6-BAC888660BBC} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
{A08F48F5-D359-4332-8743-F9D85887AEF6} = {D75ACD1D-AD2A-4A16-B761-6EA5202D5EA5}
EndGlobalSection
EndGlobal

View File

@ -195,8 +195,8 @@ long long acl_atomic_int64_cas(ACL_ATOMIC *self, long long cmp, long long n)
acl_pthread_mutex_unlock(&self->lock);
return old;
#elif defined(ACL_WINDOWS)
return InterlockedCompareExchange64((volatile LONGLONG*)&self->value,
n, cmp);
return InterlockedCompareExchange64(
(volatile LONGLONG*)&self->value, n, cmp);
#else
return (long long) __sync_val_compare_and_swap(
(long long*) self->value, cmp, n);

View File

@ -27,6 +27,8 @@ void atomic_set(ATOMIC *self, void *value)
{
#if defined(__GNUC__) && (__GNUC__ >= 4)
(void) __sync_lock_test_and_set(&self->value, value);
#elif defined(SYS_WIN)
InterlockedExchangePointer((volatile PVOID*) &self->value, value);
#else
(void) self;
(void) value;
@ -38,6 +40,9 @@ void *atomic_cas(ATOMIC *self, void *cmp, void *value)
{
#if defined(__GNUC__) && (__GNUC__ >= 4)
return __sync_val_compare_and_swap(&self->value, cmp, value);
#elif defined(SYS_WIN)
return InterlockedCompareExchangePointer(
(volatile PVOID*)&self->value, value, cmp);
#else
(void) self;
(void) cmp;
@ -52,6 +57,8 @@ void *atomic_xchg(ATOMIC *self, void *value)
{
#if defined(__GNUC__) && (__GNUC__ >= 4)
return __sync_lock_test_and_set(&self->value, value);
#elif defined(SYS_WIN)
return InterlockedExchangePointer((volatile PVOID*)&self->value, value);
#else
(void) self;
(void) value;
@ -65,6 +72,8 @@ void atomic_int64_set(ATOMIC *self, long long n)
{
#if defined(__GNUC__) && (__GNUC__ >= 4)
(void) __sync_lock_test_and_set((long long *) self->value, n);
#elif defined(SYS_WIN)
InterlockedExchangePointer((volatile PVOID*) self->value, (PVOID) n);
#else
(void) self;
(void) n;
@ -77,6 +86,10 @@ long long atomic_int64_fetch_add(ATOMIC *self, long long n)
{
#if defined(__GNUC__) && (__GNUC__ >= 4)
return (long long) __sync_fetch_and_add((long long *) self->value, n);
#elif defined(SYS_WIN)
long long k = InterlockedExchangeAdd64(
(volatile LONGLONG*) self->value, n);
return k - n;
#else
(void) self;
(void) n;
@ -90,6 +103,8 @@ long long atomic_int64_add_fetch(ATOMIC *self, long long n)
{
#if defined(__GNUC__) && (__GNUC__ >= 4)
return (long long) __sync_add_and_fetch((long long *) self->value, n);
#elif defined(SYS_WIN)
return InterlockedExchangeAdd64((volatile LONGLONG*) self->value, n);
#else
(void) self;
(void) n;
@ -104,6 +119,9 @@ long long atomic_int64_cas(ATOMIC *self, long long cmp, long long n)
#if defined(__GNUC__) && (__GNUC__ >= 4)
return (long long) __sync_val_compare_and_swap(
(long long*) self->value, cmp, n);
#elif defined(SYS_WIN)
return InterlockedCompareExchange64(
(volatile LONGLONG*)&self->value, n, cmp);
#else
(void) self;
(void) cmp;

View File

@ -164,6 +164,10 @@ static int poll_wait(EVENT *ev, int timeout)
EVENT_POLL *ep = (EVENT_POLL *) ev;
int n, i;
if (ev->fdcount == 0) {
return 0;
}
n = __sys_poll(ep->pfds, ep->count, timeout);
if (n < 0) {
if (errno == EINTR) {

View File

@ -157,6 +157,11 @@ static int select_event_wait(EVENT *ev, int timeout)
}
#ifdef SYS_WIN
acl_fiber_set_error(0);
if (ev->fdcount == 0) {
return 0;
}
n = __sys_select(0, &rset, &wset, &xset, tp);
#else
if (es->dirty) {
@ -171,6 +176,7 @@ static int select_event_wait(EVENT *ev, int timeout)
n = __sys_select(es->maxfd + 1, &rset, 0, &xset, tp);
#endif
if (n < 0) {
printf("select error %s\r\n", last_serror());
if (acl_fiber_last_error() == FIBER_EINTR) {
return 0;
}

View File

@ -96,7 +96,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012d.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
@ -147,7 +147,7 @@ copy ..\..\c\lib_fiber.dll .\ /Y</Command>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_acl.lib;lib_fiber.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib_acl.lib;lib_fiber.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
@ -176,7 +176,7 @@ copy ..\..\c\lib_fiber.dll .\ /Y</Command>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>

View File

@ -96,7 +96,7 @@
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012d.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
@ -147,7 +147,7 @@ copy ..\..\c\lib_fiber.dll .\ /Y</Command>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_acl.lib;lib_fiber.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib_acl.lib;lib_fiber.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>
@ -176,7 +176,7 @@ copy ..\..\c\lib_fiber.dll .\ /Y</Command>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\c;..\..\..\lib_acl;</AdditionalLibraryDirectories>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib_fiber.lib;lib_acl_vc2012.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>