Skip to content

Commit

Permalink
libco
Browse files Browse the repository at this point in the history
Tencent libco
  • Loading branch information
[email protected] committed Oct 12, 2016
0 parents commit 4b41ba0
Show file tree
Hide file tree
Showing 30 changed files with 6,262 additions and 0 deletions.
164 changes: 164 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
cc_library(
name = 'colib',
target_bases = [ 'comm',],
srcs = [
'co_hook_sys_call.cpp',
'co_routine.cpp',
'coctx.cpp',
'coctx_swap.S',
'co_epoll.cpp',

],
deps = [
],
defs = [
'LINUX',
'_PTHREADS',
'TIXML_USE_STL',
],
optimize = [
#'O2',
],
extra_cppflags = [
#'-O2' ,
#'-Werror',
],
)
cc_binary(
name = 'global_sym',
srcs = [
'demangle.cpp',
'global_sym.cpp'

],
deps = [


#GEN_SOURCE_POS__
],
defs = [
'LINUX',
'_PTHREADS',
'TIXML_USE_STL',
'_NEW_LIC',
'_GNU_SOURCE',
'_REENTRANT',

],
optimize = [
'O2',
],
extra_cppflags = [
#'-Werror',
#'-Werror',
'-pipe',
'-fPIC',
'-Wno-deprecated',

],
incs = [
#INCS_POS__
],
)
cc_binary(
name = 'test_specific',
srcs = [
'test_specific.cpp',

],
deps = [
':colib',
'//comm2/core:core',

#GEN_SOURCE_POS__
],
defs = [
'LINUX',
'_PTHREADS',
'TIXML_USE_STL',
'_NEW_LIC',
'_GNU_SOURCE',
'_REENTRANT',

],
optimize = [
'O2',
],
extra_cppflags = [
#'-Werror',
#'-Werror',
'-pipe',
'-fPIC',
'-Wno-deprecated',

],
incs = [
#INCS_POS__
],
)
cc_binary(
name = 'echosvr',
srcs = [
'example_echosvr_copystack.cpp',

],
deps = [
':colib',
'//comm2/core:core',

#GEN_SOURCE_POS__
],
defs = [
'LINUX',
'_PTHREADS',
'TIXML_USE_STL',
'_NEW_LIC',
'_GNU_SOURCE',
'_REENTRANT',

],
optimize = [
'O2',
],
extra_cppflags = [
#'-Werror',
#'-Werror',
'-pipe',
'-fPIC',
'-Wno-deprecated',

],
incs = [
#INCS_POS__
],
)
cc_binary(
name = 'test_colib',
srcs = [
'test_colib.cpp',
'test_xmm.S',
],
deps = [
':colib',
'//mm3rd/gtest:gtest',
'#dl',
#GEN_SOURCE_POS__
],
defs = [
],
optimize = [
'O2',
],
extra_cppflags = [
#'-Werror',
#'-Werror',
'-pipe',
'-fPIC',
'-Wno-deprecated',
'-DLIBCO-USE-GETTICK',

],
incs = [
#INCS_POS__
],
)
Binary file added LICENSE.txt
Binary file not shown.
77 changes: 77 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# 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

LINKS += -g -L./lib -lcolib -lpthread -ldl

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

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)

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)

86 changes: 86 additions & 0 deletions co.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# 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 = g++
CC = gcc
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)
Loading

0 comments on commit 4b41ba0

Please sign in to comment.