Skip to content

Commit

Permalink
port to FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
amutu committed Jul 1, 2017
1 parent ca8fe05 commit 4013083
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include co.mk
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
LINKS += -g -L./lib -lcolib -lpthread

COLIB_OBJS=co_epoll.o co_routine.o co_hook_sys_call.o coctx_swap.o coctx.o
#co_swapcontext.o
Expand Down
3 changes: 1 addition & 2 deletions co.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ MAIL_ROOT=.
SRCROOT=.

##define the compliers
CPP = g++
CC = gcc
CPP = $(CXX)
AR = ar -rc
RANLIB = ranlib

Expand Down
2 changes: 1 addition & 1 deletion co_epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <errno.h>
#include <string.h>

#ifndef __APPLE__
#if !defined( __APPLE__ ) && !defined( __FreeBSD__ )

int co_epoll_wait( int epfd,struct co_epoll_res *events,int maxevents,int timeout )
{
Expand Down
2 changes: 1 addition & 1 deletion co_epoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <time.h>
#include <time.h>

#ifndef __APPLE__
#if !defined( __APPLE__ ) && !defined( __FreeBSD__ )

#include <sys/epoll.h>

Expand Down
4 changes: 2 additions & 2 deletions co_hook_sys_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ struct hostent *gethostbyname(const char *name)
{
HOOK_SYS_FUNC( gethostbyname );

#ifdef __APPLE__
#if defined( __APPLE__ ) || defined( __FreeBSD__ )
return g_sys_gethostbyname_func( name );
#else
if (!co_is_enable_sys_hook())
Expand Down Expand Up @@ -913,7 +913,7 @@ struct hostbuf_wrap

CO_ROUTINE_SPECIFIC(hostbuf_wrap, __co_hostbuf_wrap);

#ifndef __APPLE__
#if !defined( __APPLE__ ) && !defined( __FreeBSD__ )
struct hostent *co_gethostbyname(const char *name)
{
if (!name)
Expand Down
6 changes: 6 additions & 0 deletions co_routine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ static pid_t GetPid()
{
tid = pid;
}
#elif defined( __FreeBSD__ )
syscall(SYS_thr_self, &tid);
if( tid < 0 )
{
tid = pid;
}
#else
tid = syscall( __NR_gettid );
#endif
Expand Down
2 changes: 1 addition & 1 deletion coctx_swap.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

.globl coctx_swap
#if !defined( __APPLE__ )
#if !defined( __APPLE__ ) && !defined( __FreeBSD__ )
.type coctx_swap, @function
#endif
coctx_swap:
Expand Down
6 changes: 6 additions & 0 deletions example_echosvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include <unistd.h>
#include <errno.h>

#ifdef __FreeBSD__
#include <cstring>
#include <sys/types.h>
#include <sys/wait.h>
#endif

using namespace std;
struct task_t
{
Expand Down
5 changes: 5 additions & 0 deletions example_poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#include <vector>
#include <set>
#include <unistd.h>

#ifdef __FreeBSD__
#include <cstring>
#endif

using namespace std;

struct task_t
Expand Down

0 comments on commit 4013083

Please sign in to comment.