mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
optimize for windows platform by conditional building.
This commit is contained in:
parent
15c9eda94a
commit
2b9418a396
@ -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
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#ifdef SYS_WIN
|
||||
|
||||
static int __default_limit = 10240;
|
||||
static int __default_limit = FD_SETSIZE;
|
||||
|
||||
int open_limit(int limit)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user