optimize for windows platform by conditional building.

This commit is contained in:
郑树新 2022-02-04 13:48:04 +08:00
parent 15c9eda94a
commit 2b9418a396
5 changed files with 42 additions and 4 deletions

View File

@ -71,12 +71,22 @@ typedef pthread_once_t acl_pthread_once_t;
#define ACL_TLS_OUT_OF_INDEXES 0xffffffff
#define ACL_PTHREAD_KEYS_MAX 1024
#define HAS_ONCE
/*
* see https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initonceexecuteonce
* for the supported windows OS's version, if not please comment out it.
*/
#ifdef _WIN32_WINNT
# if defined(_WIN32_WINNT_WS08)
# if _WIN32_WINNT >= _WIN32_WINNT_WS08
# define HAS_ONCE
# endif
# elif defined(_WIN32_WINNT_VISTA)
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
# define HAS_ONCE
# endif
# endif
#endif
#ifdef HAS_ONCE
#define ACL_PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
#else

View File

@ -5,7 +5,7 @@
#ifdef SYS_WIN
static int __default_limit = 10240;
static int __default_limit = FD_SETSIZE;
int open_limit(int limit)
{

View File

@ -22,7 +22,7 @@
# if(_MSC_VER >= 1300)
# undef FD_SETSIZE
# define FD_SETSIZE 10240
# define FD_SETSIZE 102400
# include <winsock2.h>
# include <mswsock.h>
# else

View File

@ -4,6 +4,21 @@
#ifdef SYS_WIN
// see <sdkddkver.h>
// see https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=msvc-170
#ifdef _WIN32_WINNT
# if defined(_WIN32_WINNT_WS08)
# if _WIN32_WINNT >= _WIN32_WINNT_WS08
# define HAS_FIBER_EX
# endif
# elif defined(_WIN32_WINNT_VISTA)
# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
# define HAS_FIBER_EX
# endif
# endif
#endif
typedef struct FIBER_WIN {
ACL_FIBER fiber;
LPVOID context;
@ -33,8 +48,14 @@ static void fiber_win_init(FIBER_WIN *fb, size_t size)
if (fb->context) {
DeleteFiber(fb->context);
}
#ifdef HAS_FIBER_EX
fb->context = CreateFiberEx(0, size, FIBER_FLAG_FLOAT_SWITCH,
fiber_win_start, fb);
#else
fb->context = CreateFiber(size, fiber_win_start, fb);
#endif
if (fb->context == NULL) {
int e = acl_fiber_last_error();
msg_fatal("%s: CreateFiberEx error=%s, %d", last_serror(), e);
@ -58,7 +79,12 @@ ACL_FIBER *fiber_win_origin(void)
{
FIBER_WIN *fb = (FIBER_WIN *) mem_calloc(1, sizeof(*fb));
#ifdef HAS_FIBER_EX
fb->context = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
#else
fb->context = ConvertThreadToFiber(NULL);
#endif
fb->fiber.free_fn = fiber_win_free;
fb->fiber.swap_fn = (void(*)(ACL_FIBER*, ACL_FIBER*)) fiber_win_swap;

View File

@ -118,6 +118,8 @@ void fiber_io_check(void)
var_maxfd = MAXFD;
}
msg_info("%s(%d): maxfd=%d", __FUNCTION__, __LINE__, var_maxfd);
__thread_fiber = (FIBER_TLS *) mem_malloc(sizeof(FIBER_TLS));
__thread_fiber->event = event_create(var_maxfd);
__thread_fiber->ev_fiber = acl_fiber_create(fiber_io_loop,