forked from ossrs/srs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use libco instead of state-thread(st), still have some bug
- Loading branch information
1 parent
51d6c36
commit 7c8a35a
Showing
88 changed files
with
4,836 additions
and
19,273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
project(libco) | ||
|
||
# This for mac osx only | ||
set(CMAKE_MACOSX_RPATH 0) | ||
|
||
# Set lib version | ||
set(LIBCO_VERSION 0.5) | ||
|
||
# Set cflags | ||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -g -fno-strict-aliasing -O2 -Wall -export-dynamic -Wall -pipe -D_GNU_SOURCE -D_REENTRANT -fPIC -Wno-deprecated -m64) | ||
|
||
# Use c and asm | ||
enable_language(C ASM) | ||
|
||
# Add source files | ||
set(SOURCE_FILES | ||
co_epoll.cpp | ||
co_hook_sys_call.cpp | ||
co_routine.cpp | ||
coctx.cpp | ||
coctx_swap.S) | ||
|
||
# Add static and shared library target | ||
add_library(colib_static STATIC ${SOURCE_FILES}) | ||
add_library(colib_shared SHARED ${SOURCE_FILES}) | ||
|
||
# Set library output name | ||
set_target_properties(colib_static PROPERTIES OUTPUT_NAME colib) | ||
set_target_properties(colib_shared PROPERTIES OUTPUT_NAME colib) | ||
|
||
set_target_properties(colib_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) | ||
set_target_properties(colib_shared PROPERTIES CLEAN_DIRECT_OUTPUT 1) | ||
|
||
# Set shared library version, will generate libcolib.${LIBCO_VERSION}.so and a symbol link named libcolib.so | ||
# For mac osx, the extension name will be .dylib | ||
set_target_properties(colib_shared PROPERTIES VERSION ${LIBCO_VERSION} SOVERSION ${LIBCO_VERSION}) | ||
|
||
|
||
|
||
# Macro for add example target | ||
macro(add_example_target EXAMPLE_TARGET) | ||
add_executable("example_${EXAMPLE_TARGET}" "example_${EXAMPLE_TARGET}.cpp") | ||
target_link_libraries("example_${EXAMPLE_TARGET}" colib_static pthread dl) | ||
endmacro(add_example_target) | ||
|
||
add_example_target(closure) | ||
add_example_target(cond) | ||
add_example_target(copystack) | ||
add_example_target(echocli) | ||
add_example_target(echosvr) | ||
add_example_target(poll) | ||
add_example_target(setenv) | ||
add_example_target(specific) | ||
add_example_target(thread) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# | ||
# Tencent is pleased to support the open source community by making Libco available. | ||
# | ||
# Copyright (C) 2014 THL A29 Limited, a Tencent company. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
|
||
COMM_MAKE = 1 | ||
COMM_ECHO = 1 | ||
version=0.5 | ||
v=debug | ||
include co.mk | ||
|
||
########## options ########## | ||
CFLAGS += -g -fno-strict-aliasing -O2 -Wall -export-dynamic \ | ||
-Wall -pipe -D_GNU_SOURCE -D_REENTRANT -fPIC -Wno-deprecated -m64 | ||
|
||
UNAME := $(shell uname -s) | ||
|
||
ifeq ($(UNAME), FreeBSD) | ||
LINKS += -g -L./lib -lcolib -lpthread | ||
else | ||
LINKS += -g -L./lib -lcolib -lpthread -ldl | ||
endif | ||
|
||
COLIB_OBJS=co_epoll.o co_routine.o co_hook_sys_call.o coctx_swap.o coctx.o | ||
#co_swapcontext.o | ||
|
||
PROGS = colib example_poll example_echosvr example_echocli example_thread example_cond example_specific example_copystack example_closure | ||
|
||
all:$(PROGS) | ||
|
||
colib:libcolib.a libcolib.so | ||
|
||
libcolib.a: $(COLIB_OBJS) | ||
$(ARSTATICLIB) | ||
libcolib.so: $(COLIB_OBJS) | ||
$(BUILDSHARELIB) | ||
|
||
example_echosvr:example_echosvr.o | ||
$(BUILDEXE) | ||
example_echocli:example_echocli.o | ||
$(BUILDEXE) | ||
example_thread:example_thread.o | ||
$(BUILDEXE) | ||
example_poll:example_poll.o | ||
$(BUILDEXE) | ||
example_exit:example_exit.o | ||
$(BUILDEXE) | ||
example_cond:example_cond.o | ||
$(BUILDEXE) | ||
example_specific:example_specific.o | ||
$(BUILDEXE) | ||
example_copystack:example_copystack.o | ||
$(BUILDEXE) | ||
example_setenv:example_setenv.o | ||
$(BUILDEXE) | ||
example_closure:example_closure.o | ||
$(BUILDEXE) | ||
|
||
dist: clean libco-$(version).src.tar.gz | ||
|
||
libco-$(version).src.tar.gz: | ||
@find . -type f | grep -v CVS | grep -v .svn | sed s:^./:libco-$(version)/: > MANIFEST | ||
@(cd ..; ln -s libco_pub libco-$(version)) | ||
(cd ..; tar cvf - `cat libco_pub/MANIFEST` | gzip > libco_pub/libco-$(version).src.tar.gz) | ||
@(cd ..; rm libco-$(version)) | ||
|
||
clean: | ||
$(CLEAN) *.o $(PROGS) | ||
rm -fr MANIFEST lib solib libco-$(version).src.tar.gz libco-$(version) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# | ||
# Tencent is pleased to support the open source community by making Libco available. | ||
# | ||
# Copyright (C) 2014 THL A29 Limited, a Tencent company. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
|
||
|
||
##### Makefile Rules ########## | ||
MAIL_ROOT=. | ||
SRCROOT=. | ||
|
||
##define the compliers | ||
CPP = $(CXX) | ||
AR = ar -rc | ||
RANLIB = ranlib | ||
|
||
CPPSHARE = $(CPP) -fPIC -shared -O2 -pipe -L$(SRCROOT)/solib/ -o | ||
CSHARE = $(CC) -fPIC -shared -O2 -pipe -L$(SRCROOT)/solib/ -o | ||
|
||
ifeq ($v,release) | ||
CFLAGS= -O2 $(INCLS) -fPIC -DLINUX -pipe -Wno-deprecated -c | ||
else | ||
CFLAGS= -g $(INCLS) -fPIC -DLINUX -pipe -c -fno-inline | ||
endif | ||
|
||
ifneq ($v,release) | ||
BFLAGS= -g | ||
endif | ||
|
||
STATICLIBPATH=$(SRCROOT)/lib | ||
DYNAMICLIBPATH=$(SRCROOT)/solib | ||
|
||
INCLS += -I$(SRCROOT) | ||
|
||
## default links | ||
ifeq ($(LINKS_DYNAMIC), 1) | ||
LINKS += -L$(DYNAMICLIBPATH) -L$(STATICLIBPATH) | ||
else | ||
LINKS += -L$(STATICLIBPATH) | ||
endif | ||
|
||
CPPSRCS = $(wildcard *.cpp) | ||
CSRCS = $(wildcard *.c) | ||
CPPOBJS = $(patsubst %.cpp,%.o,$(CPPSRCS)) | ||
COBJS = $(patsubst %.c,%.o,$(CSRCS)) | ||
|
||
SRCS = $(CPPSRCS) $(CSRCS) | ||
OBJS = $(CPPOBJS) $(COBJS) | ||
|
||
CPPCOMPI=$(CPP) $(CFLAGS) -Wno-deprecated | ||
CCCOMPI=$(CC) $(CFLAGS) | ||
|
||
BUILDEXE = $(CPP) $(BFLAGS) -o $@ $^ $(LINKS) | ||
CLEAN = rm -f *.o | ||
|
||
CPPCOMPILE = $(CPPCOMPI) $< $(FLAGS) $(INCLS) $(MTOOL_INCL) -o $@ | ||
CCCOMPILE = $(CCCOMPI) $< $(FLAGS) $(INCLS) $(MTOOL_INCL) -o $@ | ||
|
||
ARSTATICLIB = $(AR) $@.tmp $^ $(AR_FLAGS); \ | ||
if [ $$? -ne 0 ]; then exit 1; fi; \ | ||
test -d $(STATICLIBPATH) || mkdir -p $(STATICLIBPATH); \ | ||
mv -f $@.tmp $(STATICLIBPATH)/$@; | ||
|
||
BUILDSHARELIB = $(CPPSHARE) $@.tmp $^ $(BS_FLAGS); \ | ||
if [ $$? -ne 0 ]; then exit 1; fi; \ | ||
test -d $(DYNAMICLIBPATH) || mkdir -p $(DYNAMICLIBPATH); \ | ||
mv -f $@.tmp $(DYNAMICLIBPATH)/$@; | ||
|
||
.cpp.o: | ||
$(CPPCOMPILE) | ||
.c.o: | ||
$(CCCOMPILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Libco available. | ||
* Copyright (C) 2014 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __CO_CLOSURE_H__ | ||
#define __CO_CLOSURE_H__ | ||
struct stCoClosure_t | ||
{ | ||
public: | ||
virtual void exec() = 0; | ||
}; | ||
|
||
//1.base | ||
//-- 1.1 comac_argc | ||
|
||
#define comac_get_args_cnt( ... ) comac_arg_n( __VA_ARGS__ ) | ||
#define comac_arg_n( _0,_1,_2,_3,_4,_5,_6,_7,N,...) N | ||
#define comac_args_seqs() 7,6,5,4,3,2,1,0 | ||
#define comac_join_1( x,y ) x##y | ||
|
||
#define comac_argc( ... ) comac_get_args_cnt( 0,##__VA_ARGS__,comac_args_seqs() ) | ||
#define comac_join( x,y) comac_join_1( x,y ) | ||
|
||
//-- 1.2 repeat | ||
#define repeat_0( fun,a,... ) | ||
#define repeat_1( fun,a,... ) fun( 1,a,__VA_ARGS__ ) repeat_0( fun,__VA_ARGS__ ) | ||
#define repeat_2( fun,a,... ) fun( 2,a,__VA_ARGS__ ) repeat_1( fun,__VA_ARGS__ ) | ||
#define repeat_3( fun,a,... ) fun( 3,a,__VA_ARGS__ ) repeat_2( fun,__VA_ARGS__ ) | ||
#define repeat_4( fun,a,... ) fun( 4,a,__VA_ARGS__ ) repeat_3( fun,__VA_ARGS__ ) | ||
#define repeat_5( fun,a,... ) fun( 5,a,__VA_ARGS__ ) repeat_4( fun,__VA_ARGS__ ) | ||
#define repeat_6( fun,a,... ) fun( 6,a,__VA_ARGS__ ) repeat_5( fun,__VA_ARGS__ ) | ||
|
||
#define repeat( n,fun,... ) comac_join( repeat_,n )( fun,__VA_ARGS__) | ||
|
||
//2.implement | ||
#if __cplusplus <= 199711L | ||
#define decl_typeof( i,a,... ) typedef typeof( a ) typeof_##a; | ||
#else | ||
#define decl_typeof( i,a,... ) typedef decltype( a ) typeof_##a; | ||
#endif | ||
#define impl_typeof( i,a,... ) typeof_##a & a; | ||
#define impl_typeof_cpy( i,a,... ) typeof_##a a; | ||
#define con_param_typeof( i,a,... ) typeof_##a & a##r, | ||
#define param_init_typeof( i,a,... ) a(a##r), | ||
|
||
|
||
//2.1 reference | ||
|
||
#define co_ref( name,... )\ | ||
repeat( comac_argc(__VA_ARGS__) ,decl_typeof,__VA_ARGS__ )\ | ||
class type_##name\ | ||
{\ | ||
public:\ | ||
repeat( comac_argc(__VA_ARGS__) ,impl_typeof,__VA_ARGS__ )\ | ||
int _member_cnt;\ | ||
type_##name( \ | ||
repeat( comac_argc(__VA_ARGS__),con_param_typeof,__VA_ARGS__ ) ... ): \ | ||
repeat( comac_argc(__VA_ARGS__),param_init_typeof,__VA_ARGS__ ) _member_cnt(comac_argc(__VA_ARGS__)) \ | ||
{}\ | ||
} name( __VA_ARGS__ ) ; | ||
|
||
|
||
//2.2 function | ||
|
||
#define co_func(name,...)\ | ||
repeat( comac_argc(__VA_ARGS__) ,decl_typeof,__VA_ARGS__ )\ | ||
class name:public stCoClosure_t\ | ||
{\ | ||
public:\ | ||
repeat( comac_argc(__VA_ARGS__) ,impl_typeof_cpy,__VA_ARGS__ )\ | ||
int _member_cnt;\ | ||
public:\ | ||
name( repeat( comac_argc(__VA_ARGS__),con_param_typeof,__VA_ARGS__ ) ... ): \ | ||
repeat( comac_argc(__VA_ARGS__),param_init_typeof,__VA_ARGS__ ) _member_cnt(comac_argc(__VA_ARGS__))\ | ||
{}\ | ||
void exec() | ||
|
||
#define co_func_end } | ||
|
||
|
||
#endif | ||
|
Oops, something went wrong.