mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 02:47:56 +08:00
test some fiber module on windows
This commit is contained in:
parent
ff71cebfae
commit
e0601e582f
@ -45,8 +45,22 @@ EndProject
|
|||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "lib_fiber\samples-c++1x\server\server.vcxproj", "{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "lib_fiber\samples-c++1x\server\server.vcxproj", "{EE518BE5-94B2-4F8E-82CC-C08503BBD6B2}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "master_fiber", "lib_fiber\samples\master_fiber\master_fiber_vc2019.vcxproj", "{3E725148-0807-4CBA-8FC1-7FCA46F605F3}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "master_fiber", "lib_fiber\samples\master_fiber\master_fiber_vc2019.vcxproj", "{3E725148-0807-4CBA-8FC1-7FCA46F605F3}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{F2479E2C-7267-436C-A1F1-A63B39E7CB30} = {F2479E2C-7267-436C-A1F1-A63B39E7CB30}
|
||||||
|
{6EC1F44E-6A6A-48E9-B699-D7E89B63C8DC} = {6EC1F44E-6A6A-48E9-B699-D7E89B63C8DC}
|
||||||
|
{AD99B75A-40BF-46DC-844B-23417FDC8690} = {AD99B75A-40BF-46DC-844B-23417FDC8690}
|
||||||
|
{B40213C2-507C-4C7F-A6E1-B850C9BDC27B} = {B40213C2-507C-4C7F-A6E1-B850C9BDC27B}
|
||||||
|
{FE724EF7-3763-4E78-BDF5-BCBC075719FD} = {FE724EF7-3763-4E78-BDF5-BCBC075719FD}
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinFiber", "lib_fiber\samples\WinFiber\WinFiber_vc2019.vcxproj", "{141DDEA4-DDEF-4D7E-9FE1-5FEFE0D95222}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinFiber", "lib_fiber\samples\WinFiber\WinFiber_vc2019.vcxproj", "{141DDEA4-DDEF-4D7E-9FE1-5FEFE0D95222}"
|
||||||
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
|
{F2479E2C-7267-436C-A1F1-A63B39E7CB30} = {F2479E2C-7267-436C-A1F1-A63B39E7CB30}
|
||||||
|
{6EC1F44E-6A6A-48E9-B699-D7E89B63C8DC} = {6EC1F44E-6A6A-48E9-B699-D7E89B63C8DC}
|
||||||
|
{AD99B75A-40BF-46DC-844B-23417FDC8690} = {AD99B75A-40BF-46DC-844B-23417FDC8690}
|
||||||
|
{B40213C2-507C-4C7F-A6E1-B850C9BDC27B} = {B40213C2-507C-4C7F-A6E1-B850C9BDC27B}
|
||||||
|
{FE724EF7-3763-4E78-BDF5-BCBC075719FD} = {FE724EF7-3763-4E78-BDF5-BCBC075719FD}
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
#include "fiber_define.h"
|
#include "fiber_define.h"
|
||||||
#include "fiber_event.h"
|
#include "fiber_event.h"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -61,4 +59,3 @@ FIBER_API int acl_fiber_cond_signal(ACL_FIBER_COND *cond);
|
|||||||
|
|
||||||
#endif // !defined(_WIN32) && !defined(_WIN64)
|
#endif // !defined(_WIN32) && !defined(_WIN64)
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "fiber_define.h"
|
#include "fiber_define.h"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -70,6 +68,4 @@ FIBER_API int acl_fiber_event_notify(ACL_FIBER_EVENT *event);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,14 +11,9 @@
|
|||||||
# undef HAS_ATOMIC
|
# undef HAS_ATOMIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(SYS_WIN)
|
||||||
# ifndef WINDOWS
|
//# define HAS_ATOMIC
|
||||||
# define WINDOWS
|
#include "common/pthread_patch.h"
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(WINDOWS)
|
|
||||||
# define HAS_ATOMIC
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -60,7 +55,7 @@ void atomic_set(ATOMIC *self, void *value)
|
|||||||
pthread_mutex_lock(&self->lock);
|
pthread_mutex_lock(&self->lock);
|
||||||
self->value = value;
|
self->value = value;
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
InterlockedExchangePointer((volatile PVOID*) &self->value, value);
|
InterlockedExchangePointer((volatile PVOID*) &self->value, value);
|
||||||
#else
|
#else
|
||||||
(void) __sync_lock_test_and_set(&self->value, value);
|
(void) __sync_lock_test_and_set(&self->value, value);
|
||||||
@ -79,7 +74,7 @@ void *atomic_cas(ATOMIC *self, void *cmp, void *value)
|
|||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
|
|
||||||
return old;
|
return old;
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
return InterlockedCompareExchangePointer(
|
return InterlockedCompareExchangePointer(
|
||||||
(volatile PVOID*)&self->value, value, cmp);
|
(volatile PVOID*)&self->value, value, cmp);
|
||||||
#else
|
#else
|
||||||
@ -98,7 +93,7 @@ void *atomic_xchg(ATOMIC *self, void *value)
|
|||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
|
|
||||||
return old;
|
return old;
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
return InterlockedExchangePointer((volatile PVOID*)&self->value, value);
|
return InterlockedExchangePointer((volatile PVOID*)&self->value, value);
|
||||||
#else
|
#else
|
||||||
return __sync_lock_test_and_set(&self->value, value);
|
return __sync_lock_test_and_set(&self->value, value);
|
||||||
@ -111,7 +106,7 @@ void atomic_int64_set(ATOMIC *self, long long n)
|
|||||||
pthread_mutex_lock(&self->lock);
|
pthread_mutex_lock(&self->lock);
|
||||||
*((long long *) self->value) = n;
|
*((long long *) self->value) = n;
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
InterlockedExchangePointer((volatile PVOID*) self->value, (PVOID) n);
|
InterlockedExchangePointer((volatile PVOID*) self->value, (PVOID) n);
|
||||||
#else
|
#else
|
||||||
(void) __sync_lock_test_and_set((long long *) self->value, n);
|
(void) __sync_lock_test_and_set((long long *) self->value, n);
|
||||||
@ -126,7 +121,7 @@ long long atomic_int64_fetch_add(ATOMIC *self, long long n)
|
|||||||
*((long long *) self->value) = v + n;
|
*((long long *) self->value) = v + n;
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
return v;
|
return v;
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
return InterlockedExchangeAdd64((volatile LONGLONG*) self->value, n);
|
return InterlockedExchangeAdd64((volatile LONGLONG*) self->value, n);
|
||||||
#else
|
#else
|
||||||
return (long long) __sync_fetch_and_add((long long *) self->value, n);
|
return (long long) __sync_fetch_and_add((long long *) self->value, n);
|
||||||
@ -141,7 +136,7 @@ long long atomic_int64_add_fetch(ATOMIC *self, long long n)
|
|||||||
*((long long *) self->value) = v;
|
*((long long *) self->value) = v;
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
return v;
|
return v;
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
return n + InterlockedExchangeAdd64((volatile LONGLONG*) self->value, n);
|
return n + InterlockedExchangeAdd64((volatile LONGLONG*) self->value, n);
|
||||||
#else
|
#else
|
||||||
return (long long) __sync_add_and_fetch((long long *) self->value, n);
|
return (long long) __sync_add_and_fetch((long long *) self->value, n);
|
||||||
@ -157,7 +152,7 @@ long long atomic_int64_cas(ATOMIC *self, long long cmp, long long n)
|
|||||||
*((long long *) self->value) = n;
|
*((long long *) self->value) = n;
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
return old;
|
return old;
|
||||||
#elif defined(WINDOWS)
|
#elif defined(SYS_WIN)
|
||||||
return InterlockedCompareExchange64(
|
return InterlockedCompareExchange64(
|
||||||
(volatile LONGLONG*)&self->value, n, cmp);
|
(volatile LONGLONG*)&self->value, n, cmp);
|
||||||
#else
|
#else
|
||||||
|
@ -54,8 +54,20 @@ void tcp_nodelay(socket_t fd, int onoff);
|
|||||||
// in read_wait.c
|
// in read_wait.c
|
||||||
int read_wait(socket_t fd, int delay);
|
int read_wait(socket_t fd, int delay);
|
||||||
|
|
||||||
#ifdef SYS_UNIX
|
/**
|
||||||
int sane_socketpair(int domain, int type, int protocol, int result[2]);
|
* ´´½¨ socket ¶Ô
|
||||||
|
* @param domain {int}
|
||||||
|
* @param type {int}
|
||||||
|
* @param protocol {int}
|
||||||
|
* @param result {int[2]}
|
||||||
|
* @return {int}
|
||||||
|
*/
|
||||||
|
int sane_socketpair(int domain, int type, int protocol, socket_t result[2]);
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
# define CLOSE_SOCKET closesocket
|
||||||
|
#else
|
||||||
|
# define CLOSE_SOCKET close
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -3,7 +3,101 @@
|
|||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
#include "iostuff.h"
|
#include "iostuff.h"
|
||||||
|
|
||||||
#ifdef SYS_UNIX
|
#ifdef SYS_WIN
|
||||||
|
|
||||||
|
static socket_t inet_listen(const char *addr, int port, int backlog)
|
||||||
|
{
|
||||||
|
socket_t s;
|
||||||
|
struct sockaddr_in in;
|
||||||
|
|
||||||
|
in.sin_addr.s_addr = inet_addr(addr);
|
||||||
|
in.sin_port = htons(port);
|
||||||
|
in.sin_family = AF_INET;
|
||||||
|
|
||||||
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (s == INVALID_SOCKET) {
|
||||||
|
msg_error("%s(%d), %s: create listen socket error=%s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||||
|
return INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bind(s, (const struct sockaddr*)&in, sizeof(in)) < 0) {
|
||||||
|
msg_error("%s(%d), %s: bind %s error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, addr, last_serror());
|
||||||
|
closesocket(s);
|
||||||
|
return INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listen(s, backlog) < 0) {
|
||||||
|
msg_error("%s(%d), %s: listen %s error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, addr, last_serror());
|
||||||
|
closesocket(s);
|
||||||
|
return INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sane_socketpair(int domain, int type, int protocol, socket_t result[2])
|
||||||
|
{
|
||||||
|
socket_t listener = inet_listen("127.0.0.1", 0, 10);
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
struct sockaddr *sa = (struct sockaddr*) &addr;
|
||||||
|
socklen_t len = sizeof(addr);
|
||||||
|
|
||||||
|
if (listener == INVALID_SOCKET) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[0] = INVALID_SOCKET;
|
||||||
|
result[1] = INVALID_SOCKET;
|
||||||
|
|
||||||
|
if (listener == INVALID_SOCKET) {
|
||||||
|
msg_error("%s(%d), %s: listen error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcp_nodelay(listener, 1);
|
||||||
|
if (getsockname(listener, sa, &len) < 0) {
|
||||||
|
msg_error("%s(%d), %s: getoskname error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||||
|
CLOSE_SOCKET(listener);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[0] = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (result[0] == INVALID_SOCKET) {
|
||||||
|
msg_error("%s(%d), %s: create socket %s error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, addr, last_serror());
|
||||||
|
CLOSE_SOCKET(listener);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (connect(result[0], sa, len) == -1) {
|
||||||
|
msg_error("%s(%d), %s: connect error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||||
|
CLOSE_SOCKET(listener);
|
||||||
|
CLOSE_SOCKET(result[0]);
|
||||||
|
result[0] = INVALID_SOCKET;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[1] = accept(listener, NULL, 0);
|
||||||
|
CLOSE_SOCKET(listener);
|
||||||
|
|
||||||
|
if (result[1] == INVALID_SOCKET) {
|
||||||
|
msg_error("%s(%d), %s: accept error %s",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, last_serror());
|
||||||
|
CLOSE_SOCKET(result[0]);
|
||||||
|
result[0] = INVALID_SOCKET;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcp_nodelay(result[0], 1);
|
||||||
|
tcp_nodelay(result[1], 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(SYS_UNIX)
|
||||||
|
|
||||||
/* sane_socketpair - sanitize socketpair() error returns */
|
/* sane_socketpair - sanitize socketpair() error returns */
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef SYS_UNIX
|
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
# include <linux/version.h>
|
# include <linux/version.h>
|
||||||
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||||
@ -14,6 +12,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "fiber/libfiber.h"
|
#include "fiber/libfiber.h"
|
||||||
|
#include "fiber/fiber_hook.h"
|
||||||
|
#include "common/iostuff.h"
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
|
|
||||||
void fbase_event_open(FIBER_BASE *fbase)
|
void fbase_event_open(FIBER_BASE *fbase)
|
||||||
@ -53,10 +53,10 @@ void fbase_event_open(FIBER_BASE *fbase)
|
|||||||
void fbase_event_close(FIBER_BASE *fbase)
|
void fbase_event_close(FIBER_BASE *fbase)
|
||||||
{
|
{
|
||||||
if (fbase->event_in >= 0) {
|
if (fbase->event_in >= 0) {
|
||||||
close(fbase->event_in);
|
CLOSE_SOCKET(fbase->event_in);
|
||||||
}
|
}
|
||||||
if (fbase->event_out != fbase->event_in && fbase->event_out >= 0) {
|
if (fbase->event_out != fbase->event_in && fbase->event_out >= 0) {
|
||||||
close(fbase->event_out);
|
CLOSE_SOCKET(fbase->event_out);
|
||||||
}
|
}
|
||||||
fbase->event_in = -1;
|
fbase->event_in = -1;
|
||||||
fbase->event_out = -2;
|
fbase->event_out = -2;
|
||||||
@ -73,7 +73,11 @@ int fbase_event_wait(FIBER_BASE *fbase)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
#ifdef SYS_WIN
|
||||||
|
ret = (int) recv(fbase->event_in, (char*) &n, sizeof(n), 0);
|
||||||
|
#else
|
||||||
ret = (int) acl_fiber_read(fbase->event_in, &n, sizeof(n));
|
ret = (int) acl_fiber_read(fbase->event_in, &n, sizeof(n));
|
||||||
|
#endif
|
||||||
if (ret == sizeof(n)) {
|
if (ret == sizeof(n)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -126,7 +130,12 @@ int fbase_event_wakeup(FIBER_BASE *fbase)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
#ifdef SYS_WIN
|
||||||
|
ret = (int) acl_fiber_send(fbase->event_out, (char*) &n, sizeof(n), 0);
|
||||||
|
#else
|
||||||
ret = (int) acl_fiber_write(fbase->event_out, &n, sizeof(n));
|
ret = (int) acl_fiber_write(fbase->event_out, &n, sizeof(n));
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret == sizeof(n)) {
|
if (ret == sizeof(n)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -155,4 +164,3 @@ int fbase_event_wakeup(FIBER_BASE *fbase)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SYS_UNIX
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef SYS_UNIX
|
//#ifdef SYS_UNIX
|
||||||
|
#if 1
|
||||||
|
|
||||||
#include "fiber/libfiber.h"
|
#include "fiber/libfiber.h"
|
||||||
#include "fiber/fiber_cond.h"
|
#include "fiber/fiber_cond.h"
|
||||||
|
#include "common/pthread_patch.h"
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
|
|
||||||
struct ACL_FIBER_COND {
|
struct ACL_FIBER_COND {
|
||||||
@ -16,7 +18,9 @@ struct ACL_FIBER_COND {
|
|||||||
|
|
||||||
ACL_FIBER_COND *acl_fiber_cond_create(unsigned flag fiber_unused)
|
ACL_FIBER_COND *acl_fiber_cond_create(unsigned flag fiber_unused)
|
||||||
{
|
{
|
||||||
|
#ifdef SYS_UNIX
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
|
#endif
|
||||||
ACL_FIBER_COND *cond = (ACL_FIBER_COND *)
|
ACL_FIBER_COND *cond = (ACL_FIBER_COND *)
|
||||||
mem_calloc(1, sizeof(ACL_FIBER_COND));
|
mem_calloc(1, sizeof(ACL_FIBER_COND));
|
||||||
|
|
||||||
@ -25,10 +29,14 @@ ACL_FIBER_COND *acl_fiber_cond_create(unsigned flag fiber_unused)
|
|||||||
atomic_set(cond->atomic, &cond->value);
|
atomic_set(cond->atomic, &cond->value);
|
||||||
atomic_int64_set(cond->atomic, 0);
|
atomic_int64_set(cond->atomic, 0);
|
||||||
|
|
||||||
|
#ifdef SYS_UNIX
|
||||||
pthread_mutexattr_init(&attr);
|
pthread_mutexattr_init(&attr);
|
||||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||||
pthread_mutex_init(&cond->mutex, &attr);
|
pthread_mutex_init(&cond->mutex, &attr);
|
||||||
pthread_mutexattr_destroy(&attr);
|
pthread_mutexattr_destroy(&attr);
|
||||||
|
#else
|
||||||
|
pthread_mutex_init(&cond->mutex, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
return cond;
|
return cond;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef SYS_UNIX
|
|
||||||
|
|
||||||
#include "fiber/libfiber.h"
|
#include "fiber/libfiber.h"
|
||||||
#include "fiber.h"
|
#include "fiber.h"
|
||||||
|
|
||||||
@ -57,11 +55,15 @@ ACL_FIBER_EVENT *acl_fiber_event_create(unsigned flag)
|
|||||||
atomic_int64_set(event->atomic, 0);
|
atomic_int64_set(event->atomic, 0);
|
||||||
|
|
||||||
if ((flag & FIBER_FLAG_USE_MUTEX)) {
|
if ((flag & FIBER_FLAG_USE_MUTEX)) {
|
||||||
|
#ifdef SYS_WIN
|
||||||
|
pthread_mutex_init(&event->lock.tlock, NULL);
|
||||||
|
#else
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
|
|
||||||
pthread_mutexattr_init(&attr);
|
pthread_mutexattr_init(&attr);
|
||||||
pthread_mutex_init(&event->lock.tlock, &attr);
|
pthread_mutex_init(&event->lock.tlock, &attr);
|
||||||
pthread_mutexattr_destroy(&attr);
|
pthread_mutexattr_destroy(&attr);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
event->lock.atomic.alock = atomic_new();
|
event->lock.atomic.alock = atomic_new();
|
||||||
atomic_set(event->lock.atomic.alock, &event->lock.atomic.value);
|
atomic_set(event->lock.atomic.alock, &event->lock.atomic.value);
|
||||||
@ -119,7 +121,11 @@ int acl_fiber_event_wait(ACL_FIBER_EVENT *event)
|
|||||||
FIBER_BASE *fbase;
|
FIBER_BASE *fbase;
|
||||||
unsigned wakeup;
|
unsigned wakeup;
|
||||||
|
|
||||||
|
#ifdef SYS_WIN
|
||||||
|
if (atomic_int64_cas(event->atomic, 0, 1) == 0) {
|
||||||
|
#else
|
||||||
if (LIKELY(atomic_int64_cas(event->atomic, 0, 1) == 0)) {
|
if (LIKELY(atomic_int64_cas(event->atomic, 0, 1) == 0)) {
|
||||||
|
#endif
|
||||||
__ll_lock(event);
|
__ll_lock(event);
|
||||||
event->owner = fiber ? &fiber->base : NULL;
|
event->owner = fiber ? &fiber->base : NULL;
|
||||||
event->tid = __pthread_self();
|
event->tid = __pthread_self();
|
||||||
@ -254,5 +260,3 @@ int acl_fiber_event_notify(ACL_FIBER_EVENT *event)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SYS_UNIX
|
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
#include "define.h"
|
#include "define.h"
|
||||||
|
|
||||||
#if 1
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
# define LIKELY
|
||||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
# define UNLIKELY
|
||||||
#else
|
#else
|
||||||
#define LIKELY
|
# define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||||
#define UNLIKELY
|
# define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "fiber_cpp_define.hpp"
|
#include "fiber_cpp_define.hpp"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
struct ACL_FIBER_COND;
|
struct ACL_FIBER_COND;
|
||||||
|
|
||||||
namespace acl {
|
namespace acl {
|
||||||
@ -52,4 +50,3 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "fiber_cpp_define.hpp"
|
#include "fiber_cpp_define.hpp"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
struct ACL_FIBER_EVENT;
|
struct ACL_FIBER_EVENT;
|
||||||
|
|
||||||
namespace acl {
|
namespace acl {
|
||||||
@ -65,5 +63,3 @@ private:
|
|||||||
|
|
||||||
} // namespace acl
|
} // namespace acl
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include "fiber_event.hpp"
|
#include "fiber_event.hpp"
|
||||||
#include "fiber_cond.hpp"
|
#include "fiber_cond.hpp"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
namespace acl {
|
namespace acl {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,4 +207,3 @@ private:
|
|||||||
|
|
||||||
} // namespace acl
|
} // namespace acl
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include "fiber/fiber_event.hpp"
|
#include "fiber/fiber_event.hpp"
|
||||||
#include "fiber/fiber_cond.hpp"
|
#include "fiber/fiber_cond.hpp"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
namespace acl {
|
namespace acl {
|
||||||
|
|
||||||
fiber_cond::fiber_cond(void)
|
fiber_cond::fiber_cond(void)
|
||||||
@ -38,4 +36,3 @@ bool fiber_cond::notify(void)
|
|||||||
|
|
||||||
} // namespace acl
|
} // namespace acl
|
||||||
|
|
||||||
#endif // !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "stdafx.hpp"
|
#include "stdafx.hpp"
|
||||||
#include "fiber/fiber_event.hpp"
|
#include "fiber/fiber_event.hpp"
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(_WIN64)
|
|
||||||
|
|
||||||
namespace acl {
|
namespace acl {
|
||||||
|
|
||||||
fiber_event::fiber_event(bool use_mutex /* = true */,
|
fiber_event::fiber_event(bool use_mutex /* = true */,
|
||||||
@ -38,4 +36,3 @@ bool fiber_event::notify(void)
|
|||||||
|
|
||||||
} // namespace acl
|
} // namespace acl
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Binary file not shown.
@ -90,6 +90,7 @@ BEGIN_MESSAGE_MAP(CWinFiberDlg, CDialogEx)
|
|||||||
ON_BN_CLICKED(IDC_START_HTTPD, &CWinFiberDlg::OnBnClickedStartHttpd)
|
ON_BN_CLICKED(IDC_START_HTTPD, &CWinFiberDlg::OnBnClickedStartHttpd)
|
||||||
ON_BN_CLICKED(IDOK, &CWinFiberDlg::OnBnClickedOk)
|
ON_BN_CLICKED(IDOK, &CWinFiberDlg::OnBnClickedOk)
|
||||||
ON_BN_CLICKED(IDCANCEL, &CWinFiberDlg::OnBnClickedCancel)
|
ON_BN_CLICKED(IDCANCEL, &CWinFiberDlg::OnBnClickedCancel)
|
||||||
|
ON_BN_CLICKED(IDC_AWAIT_DNS, &CWinFiberDlg::OnBnClickedAwaitDns)
|
||||||
END_MESSAGE_MAP()
|
END_MESSAGE_MAP()
|
||||||
|
|
||||||
// CWinFiberDlg 消息处理程序
|
// CWinFiberDlg 消息处理程序
|
||||||
@ -302,8 +303,10 @@ void CWinFiberDlg::OnBnClickedCreateTimer()
|
|||||||
void CWinFiberDlg::OnBnClickedStartHttpd()
|
void CWinFiberDlg::OnBnClickedStartHttpd()
|
||||||
{
|
{
|
||||||
// TODO: 在此添加控件通知处理程序代码
|
// TODO: 在此添加控件通知处理程序代码
|
||||||
|
GetDlgItem(IDC_START_HTTPD)->EnableWindow(FALSE);
|
||||||
acl::fiber* fb = new CFiberHttpd(m_httpdAddr.c_str());
|
acl::fiber* fb = new CFiberHttpd(m_httpdAddr.c_str());
|
||||||
fb->start();
|
fb->start();
|
||||||
|
//GetDlgItem(IDC_START_HTTPD)->EnableWindow(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWinFiberDlg::OnBnClickedOk()
|
void CWinFiberDlg::OnBnClickedOk()
|
||||||
@ -319,3 +322,43 @@ void CWinFiberDlg::OnBnClickedCancel()
|
|||||||
CDialogEx::OnCancel();
|
CDialogEx::OnCancel();
|
||||||
StopFiber(); // 停止协程调度过程
|
StopFiber(); // 停止协程调度过程
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CWinFiberDlg::ResolveDNS(const char* name, std::vector<std::string>* addrs)
|
||||||
|
{
|
||||||
|
struct hostent *ent = gethostbyname(name);
|
||||||
|
if (ent == NULL) {
|
||||||
|
printf("gethostbyname error: %s, name=%s\r\n", acl::last_serror(), name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; ent->h_addr_list[i]; i++) {
|
||||||
|
char* addr = ent->h_addr_list[i];
|
||||||
|
char ip[64];
|
||||||
|
const char* ptr = inet_ntop(ent->h_addrtype, addr, ip, sizeof(ip));
|
||||||
|
if (ptr) {
|
||||||
|
addrs->push_back(ptr);
|
||||||
|
} else {
|
||||||
|
printf(">>>inet_ntop error\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWinFiberDlg::OnBnClickedAwaitDns()
|
||||||
|
{
|
||||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||||
|
std::string name = "www.google.com";
|
||||||
|
std::vector<std::string> addrs;
|
||||||
|
go_wait[&]{
|
||||||
|
if (!ResolveDNS(name.c_str(), &addrs)) {
|
||||||
|
printf(">>>resolve DNS error, name=%s\r\n", name.c_str());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
printf(">>>name=%s, result count=%zd\r\n", name.c_str(), addrs.size());
|
||||||
|
for (std::vector<std::string>::const_iterator cit = addrs.begin();
|
||||||
|
cit != addrs.end(); ++cit) {
|
||||||
|
printf(">>>ip=%s\r\n", (*cit).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -48,6 +48,8 @@ private:
|
|||||||
void InitFiber();
|
void InitFiber();
|
||||||
void StopFiber();
|
void StopFiber();
|
||||||
|
|
||||||
|
bool ResolveDNS(const char* name, std::vector<std::string>* addrs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void OnFiberConnectExit(acl::fiber* fb);
|
void OnFiberConnectExit(acl::fiber* fb);
|
||||||
|
|
||||||
@ -59,4 +61,5 @@ public:
|
|||||||
afx_msg void OnBnClickedStartHttpd();
|
afx_msg void OnBnClickedStartHttpd();
|
||||||
afx_msg void OnBnClickedOk();
|
afx_msg void OnBnClickedOk();
|
||||||
afx_msg void OnBnClickedCancel();
|
afx_msg void OnBnClickedCancel();
|
||||||
|
afx_msg void OnBnClickedAwaitDns();
|
||||||
};
|
};
|
||||||
|
@ -162,7 +162,7 @@
|
|||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -187,7 +187,7 @@
|
|||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -262,7 +262,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -291,7 +291,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -14,5 +14,6 @@
|
|||||||
#include "acl_cpp/lib_acl.hpp"
|
#include "acl_cpp/lib_acl.hpp"
|
||||||
#include "fiber/lib_fiber.h"
|
#include "fiber/lib_fiber.h"
|
||||||
#include "fiber/lib_fiber.hpp"
|
#include "fiber/lib_fiber.hpp"
|
||||||
|
#include "fiber/go_fiber.hpp"
|
||||||
|
|
||||||
#endif //PCH_H
|
#endif //PCH_H
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#define IDC_CONNECT 1002
|
#define IDC_CONNECT 1002
|
||||||
#define IDC_CREATE_TIMER 1003
|
#define IDC_CREATE_TIMER 1003
|
||||||
#define IDC_START_HTTPD 1004
|
#define IDC_START_HTTPD 1004
|
||||||
|
#define IDC_BUTTON1 1005
|
||||||
|
#define IDC_AWAIT_DNS 1005
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
//
|
//
|
||||||
@ -19,7 +21,7 @@
|
|||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
#define _APS_NEXT_RESOURCE_VALUE 130
|
||||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1005
|
#define _APS_NEXT_CONTROL_VALUE 1006
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user