Skip to content

Commit

Permalink
improvement the lib_fiber's performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ubuntu14 committed Jun 11, 2016
1 parent 92b0dc1 commit 0ec7e95
Show file tree
Hide file tree
Showing 51 changed files with 3,120 additions and 275 deletions.
2 changes: 1 addition & 1 deletion lib_acl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ CFLAGS = -c -g -W \
-Wuninitialized \
-D_POSIX_PTHREAD_SEMANTICS \
-DACL_PREPARE_COMPILE \
-DUSE_EPOLL \
-Winvalid-pch
#-DUSE_EPOLL \
#-Wno-invalid-source-encoding \
#-Wno-extended-offsetof
#-Wcast-align
Expand Down
3 changes: 3 additions & 0 deletions lib_acl_cpp/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
�޸���ʷ�б���

-----------------------------------------------------------------------
430) 2016.6.7
430.1) bugfix: string ��Ӧ��ֻ����ָ�룬����Ӧ���մ�

429) 2016.5.30
429.1) safety: string �����ָ����������˰�ȫ�Լ��

Expand Down
43 changes: 21 additions & 22 deletions lib_acl_cpp/src/stdlib/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ string::string(size_t len /* = 64 */, bool bin /* = false */)
: use_bin_(bin)
{
init(len);
TERM(vbf_);
}

string::string(const string& s) : use_bin_(false)
{
init(s.length() + 1);
if (!s.empty())
MCP(vbf_, STR(s.vbf_), LEN(s.vbf_));
MCP(vbf_, STR(s.vbf_), LEN(s.vbf_));
TERM(vbf_);
}

string::string(const char* s) : use_bin_(false)
{
if (s == NULL || *s == 0)
if (s == NULL)
{
init(128);
TERM(vbf_);
return;
}

Expand Down Expand Up @@ -198,25 +199,23 @@ char& string::operator [](int n)

string& string::operator =(const char* s)
{
if (s != NULL && *s != 0)
if (s != NULL)
SCP(vbf_, s);

return *this;
}

string& string::operator =(const string& s)
{
if (!s.empty())
{
MCP(vbf_, STR(s.vbf_), LEN(s.vbf_));
TERM(vbf_);
}
MCP(vbf_, STR(s.vbf_), LEN(s.vbf_));
TERM(vbf_);

return *this;
}

string& string::operator =(const string* s)
{
if (s == NULL || s->empty())
if (s == NULL)
return *this;

MCP(vbf_, STR(s->vbf_), LEN(s->vbf_));
Expand Down Expand Up @@ -336,7 +335,7 @@ string& string::operator =(unsigned char n)

string& string::operator +=(const char* s)
{
if (s == NULL || *s == 0)
if (s == NULL)
return *this;

SCAT(vbf_, s);
Expand All @@ -352,7 +351,7 @@ string& string::operator +=(const string& s)

string& string::operator +=(const string* s)
{
if (s == NULL || s->empty())
if (s == NULL)
return *this;

MCAT(vbf_, STR(s->vbf_), LEN(s->vbf_));
Expand Down Expand Up @@ -473,7 +472,7 @@ string& string::operator <<(const string& s)

string& string::operator <<(const string* s)
{
if (s == NULL || s->empty())
if (s == NULL )
return *this;

*this += s;
Expand All @@ -482,7 +481,7 @@ string& string::operator <<(const string* s)

string& string::operator <<(const char* s)
{
if (s == NULL || *s == 0)
if (s == NULL)
return *this;

*this += s;
Expand Down Expand Up @@ -1093,7 +1092,7 @@ std::pair<acl::string, acl::string>& string::split_nameval()

string& string::copy(const char* ptr)
{
if (ptr == NULL || *ptr == 0)
if (ptr == NULL)
return *this;

SCP(vbf_, ptr);
Expand Down Expand Up @@ -1134,15 +1133,15 @@ string& string::append(const string& s)

string& string::append(const string* s)
{
if (s == NULL || s->empty())
if (s == NULL)
return *this;

return append(s->c_str(), s->length());
}

string& string::append(const char* ptr)
{
if (ptr == NULL || *ptr == 0)
if (ptr == NULL)
return *this;

SCAT(vbf_, ptr);
Expand Down Expand Up @@ -1524,7 +1523,7 @@ string& string::base64_decode(void)

string& string::base64_decode(const char* s)
{
if (s == NULL || *s == 0)
if (s == NULL)
return *this;

if (acl_vstring_base64_decode(vbf_, s, (int) strlen(s)) == NULL)
Expand All @@ -1550,7 +1549,7 @@ string& string::base64_decode(const void* ptr, size_t len)

string& string::url_encode(const char* s, dbuf_pool* dbuf /* = NULL */)
{
if (s == NULL || *s == 0)
if (s == NULL)
return *this;

char *ptr = acl_url_encode(s, dbuf ? dbuf->get_dbuf() : NULL);
Expand All @@ -1563,7 +1562,7 @@ string& string::url_encode(const char* s, dbuf_pool* dbuf /* = NULL */)

string& string::url_decode(const char* s, dbuf_pool* dbuf /* = NULL */)
{
if (s == NULL || *s == 0)
if (s == NULL)
return *this;

char *ptr = acl_url_decode(s, dbuf ? dbuf->get_dbuf() : NULL);
Expand Down Expand Up @@ -1594,7 +1593,7 @@ string& string::hex_decode(const char* s, size_t len)

string& string::basename(const char* path)
{
if (path == NULL || *path == 0)
if (path == NULL)
return *this;

(void) acl_sane_basename(vbf_, path);
Expand All @@ -1603,7 +1602,7 @@ string& string::basename(const char* path)

string& string::dirname(const char* path)
{
if (path == NULL || *path == 0)
if (path == NULL)
return *this;

(void) acl_sane_dirname(vbf_, path);
Expand Down
1 change: 1 addition & 0 deletions lib_fiber/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CFLAGS = -c -g -W \
-D_POSIX_PTHREAD_SEMANTICS \
-D_USE_FAST_MACRO \
-Wno-long-long
#-DUSE_VALGRIND

#-pedantic
# -Wcast-align
Expand Down
15 changes: 15 additions & 0 deletions lib_fiber/changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

4) 2016.6.11
4.1) valgrind: 增加编译开关以防止 valgrind 工具对 swapcontext 跳转的误报

3) 2016.6.9
3.1) performance: fiber_schedule.c,由星形切换改为环形切换,从而提升了上下文件
切换的效率 --- by [email protected]

2) 2016.6.5
2.1) feature: 将 fiber_schedule.c, fiber_io.c 中的全局静态变量调整为线程局部
变量,为实现多线程化协程做准备

1) 2016.6.4
1.1) 当前的协程支持 hook: read/redv/redv/recvfrom/recvmsg,
write/writev/send/sendto/sendmsg, poll/select/sleep/gethostbyname/gethostbyname_r
18 changes: 18 additions & 0 deletions lib_fiber/include/fiber/fiber_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef FIBER_IO_INCLUDE_H
#define FIBER_IO_INCLUDE_H

#ifdef __cplusplus
extern "C" {
#endif

void fiber_io_stop(void);
unsigned int fiber_delay(unsigned int milliseconds);
unsigned int fiber_sleep(unsigned int seconds);

void fiber_set_dns(const char* ip, int port);

#ifdef __cplusplus
}
#endif

#endif
20 changes: 20 additions & 0 deletions lib_fiber/include/fiber/fiber_schedule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef FIBER_SCHEDULE_INCLUDE_H
#define FIBER_SCHEDULE_INCLUDE_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct FIBER FIBER;

FIBER *fiber_create(void (*fn)(FIBER *, void *), void *arg, size_t size);
int fiber_id(const FIBER *fiber);
int fiber_yield(void);
void fiber_switch(void);
void fiber_schedule(void);

#ifdef __cplusplus
}
#endif

#endif
7 changes: 7 additions & 0 deletions lib_fiber/include/fiber/lib_fiber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef ACL_FIBER_INCLUDE_H
#define ACL_FIBER_INCLUDE_H

#include "fiber_io.h"
#include "fiber_schedule.h"

#endif
3 changes: 3 additions & 0 deletions lib_fiber/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Author:
[email protected]
[email protected]
26 changes: 26 additions & 0 deletions lib_fiber/samples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

all:
@(cd dns; make)
@(cd fiber; make)
@(cd read; make)
@(cd httpd; make)
@(cd httpd2; make)
@(cd client; make)
@(cd server; make)
@(cd sleep; make)
@(cd poll; make)
@(cd redis; make)
@(cd redis_threads; make)

cl clean:
@(cd dns; make clean)
@(cd fiber; make clean)
@(cd read; make clean)
@(cd httpd; make clean)
@(cd httpd2; make clean)
@(cd client; make clean)
@(cd server; make clean)
@(cd sleep; make clean)
@(cd poll; make clean)
@(cd redis; make clean)
@(cd redis_threads; make clean)
2 changes: 1 addition & 1 deletion lib_fiber/samples/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CFLAGS = -c -g -W \
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB = -lpthread
SYSLIB = -lpthread -ldl
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)

Expand Down
Loading

0 comments on commit 0ec7e95

Please sign in to comment.