diff --git a/configure b/configure index ede0137c..cabb0772 100755 --- a/configure +++ b/configure @@ -114,6 +114,90 @@ else debug='' fi + +#event +event_flag="-DMLN_SELECT" + +echo "#include +#include +int main(void){epoll_create(10);return 0;}" > ev_test.c +$cc -o ev_test ev_test.c 2>/dev/null +if [ "$?" == "0" ]; then + event_flag="-DMLN_EPOLL" + echo -e "event\t\t\t[EPOLL]" + rm -f ev_test ev_test.c +fi + +echo "#include +#include +#include +#include +int main(void){kqueue();return 0;}" > ev_test.c +$cc -o ev_test ev_test.c 2>/dev/null +if [ "$?" == "0" ]; then + event_flag="-DMLN_KQUEUE" + echo -e "event\t\t\t[KQUEUE]" + rm -f ev_test ev_test.c +fi +rm -f ev_test ev_test.c +echo -e "event\t\t\t[SELECT]" + + +#sendfile +sendfile_flag="" +echo "#include +int main(void){sendfile(1,0,0,1);return 0;}" > sendfile_test.c +$cc -o sendfile_test sendfile_test.c 2>/dev/null +if [ "$?" == "0" ]; then + sendfile_flag="-DMLN_SENDFILE" + echo -e "sendfile\t\t[support]" +else + echo -e "sendfile\t\t[NOT support]" +fi +rm -f sendfile_test sendfile_test.c + + +#writev +writev_flag="" +echo -e "#include \n#include " > writev_test.c +echo "int main(void){writev(0,NULL,0);return 0;}" >> writev_test.c +$cc -o writev_test writev_test.c 2>/dev/null +if [ "$?" == "0" ]; then + writev_flag="-DMLN_WRITEV" + echo -e "writev\t\t\t[support]" +else + echo -e "writev\t\t\t[NOT support]" +fi +rm -f writev_test writev_test.c + + +#unix98 +unix98_flag="" +echo -e "#ifndef __USE_UNIX98\n#define __USE_UNIX98\n#endif\n#include \n" > unix98_test.c +echo "int main(void){pthread_setconcurrency(0);return 0;}" >> unix98_test.c +$cc -o unix98_test unix98_test.c -lpthread 2>/dev/null +if [ "$?" == "0" ]; then + echo -e "__USE_UNIX98\t\t[support]" + unix98_flag="-DMLN_USE_UNIX98" +else + echo -e "__USE_UNIX98\t\t[not support]" +fi +rm -fr unix98_test unix98_test.c + + +#mmap +mmap_flag="" +echo -e "#include \n#include " >> mmap_test.c +echo "int main(void){mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0);return 0;}" >> mmap_test.c +$cc -o mmap_test mmap_test.c 2>/dev/null +if [ "$?" == "0" ]; then + mmap_flag="-DMLN_MMAP" + echo -e "mmap\t\t\t[support]" +else + echo -e "mmap\t\t\t[NOT support]" +fi +rm -f mmap_test mmap_test.c + #output installation path echo -e "Installation Path \t[$install_path]" echo -e "Melang script Path \t[$melang_script_path]" @@ -210,7 +294,7 @@ echo "}" >> src/mln_path.c get_source_files() { files=() if [ $1 = 'all' ]; then - for f in `find src/ -name "*.c"` + for f in `find src -name "*.c"` do files+=$f" " done @@ -221,7 +305,7 @@ get_source_files() { do IFS=$old_ifs fname='mln_'$f'.c' - fname=`find src/ -name $fname` + fname=`find src -name $fname` if [ -z $fname ]; then echo "[$f] not found" exit 1 @@ -232,7 +316,7 @@ get_source_files() { suffix=`echo $header | cut -d '.' -f 2` if [ $suffix == 'h' ]; then source_file=`echo $header | cut -d '.' -f 1`'.c' - source_file=`find src/ -name $source_file` + source_file=`find src -name $source_file` if [ ! -z $source_file ]; then if [[ ! "${files[@]}" =~ $source_file ]]; then files+=$source_file" " @@ -342,99 +426,9 @@ do if [ $wasm -eq 1 ]; then echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile - continue - fi - - test $fname = "./src/mln_event.c" - if [ $? -eq 0 ]; then - #test event system call - echo "#include - #include - int main(void){epoll_create(10);return 0;}" > ev_test.c - $cc -o ev_test ev_test.c 2>/dev/null - if [ "$?" == "0" ]; then - echo -e "event\t\t\t[EPOLL]" - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_EPOLL" >> Makefile - rm -f ev_test ev_test.c - continue - fi - - echo "#include - #include - #include - #include - int main(void){kqueue();return 0;}" > ev_test.c - $cc -o ev_test ev_test.c 2>/dev/null - if [ "$?" == "0" ]; then - echo -e "event\t\t\t[KQUEUE]" - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_KQUEUE" >> Makefile - rm -f ev_test ev_test.c - continue - fi - rm -f ev_test ev_test.c - - echo -e "event\t\t\t[SELECT]" - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_SELECT" >> Makefile - continue - fi - - #test sendfile & writev - test $fname = "./src/mln_connection.c" - if [ $? -eq 0 ]; then - sendfile=0 - echo "#include - int main(void){sendfile(1,0,0,1);return 0;}" > sendfile_test.c - $cc -o sendfile_test sendfile_test.c 2>/dev/null - if [ "$?" == "0" ]; then - sendfile=1 - echo -e "sendfile\t\t[support]" - else - echo -e "sendfile\t\t[NOT support]" - fi - rm -f sendfile_test sendfile_test.c - - #test writev - echo -e "#include \n#include " > writev_test.c - echo "int main(void){writev(0,NULL,0);return 0;}" >> writev_test.c - $cc -o writev_test writev_test.c 2>/dev/null - if [ "$?" == "0" ]; then - echo -e "writev\t\t\t[support]" - if [ $sendfile -eq "1" ]; then - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_SENDFILE -DMLN_WRITEV" >> Makefile - else - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_WRITEV" >> Makefile - fi - else - echo -e "writev\t\t\t[NOT support]" - if [ $sendfile -eq "1" ]; then - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_SENDFILE" >> Makefile - else - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile - fi - fi - rm -f writev_test writev_test.c - continue - fi - - #test __USE_UNIX98 - test $fname = "./src/mln_thread_pool.c" - if [ $? -eq 0 ]; then - unix98=0 - echo -e "#ifndef __USE_UNIX98\n#define __USE_UNIX98\n#endif\n#include \n" > unix98_test.c - echo "int main(void){pthread_setconcurrency(0);return 0;}" >> unix98_test.c - $cc -o unix98_test unix98_test.c -lpthread 2>/dev/null - if [ "$?" == "0" ]; then - echo -e "__USE_UNIX98\t\t[support]" - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname -DMLN_USE_UNIX98" >> Makefile - else - echo -e "__USE_UNIX98\t\t[not support]" - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile - fi - rm -fr unix98_test unix98_test.c - continue + else + echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname $event_flag $sendfile_flag $writev_flag $unix98_flag $mmap_flag" >> Makefile fi - - echo -e "\t\$(CC) \$(FLAGS) -o \$@ $fname" >> Makefile done #generate conf file diff --git a/include/mln_alloc.h b/include/mln_alloc.h index 5d5822f4..87abebd9 100644 --- a/include/mln_alloc.h +++ b/include/mln_alloc.h @@ -12,9 +12,6 @@ #else #include #endif -#include -#include -#include #include "mln_types.h" typedef int (*mln_alloc_shm_lock_cb_t)(void *); diff --git a/src/mln_alloc.c b/src/mln_alloc.c index 9dd65668..2aabc3e8 100644 --- a/src/mln_alloc.c +++ b/src/mln_alloc.c @@ -5,6 +5,8 @@ #include "mln_alloc.h" #include "mln_utils.h" +#include +#include MLN_CHAIN_FUNC_DECLARE(mln_blk, \ @@ -119,8 +121,12 @@ mln_alloc_t *mln_alloc_shm_init(struct mln_alloc_shm_attr_s *attr) pool->map_handle = handle; #else +#if defined(MLN_MMAP) pool = (mln_alloc_t *)mmap(NULL, attr->size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0); if (pool == NULL) return NULL; +#else + return NULL; +#endif #endif pool->parent = NULL; pool->large_used_head = pool->large_used_tail = NULL; @@ -219,7 +225,9 @@ void mln_alloc_destroy(mln_alloc_t *pool) UnmapViewOfFile(pool->mem); CloseHandle(handle); #else +#if defined(MLN_MMAP) munmap(pool->mem, pool->shm_size); +#endif #endif } if (parent != NULL && mln_alloc_is_shm(parent)) diff --git a/src/mln_chain.c b/src/mln_chain.c index 648facfa..fab418be 100644 --- a/src/mln_chain.c +++ b/src/mln_chain.c @@ -14,7 +14,7 @@ mln_buf_t *mln_buf_new(mln_alloc_t *pool) b->file_left_pos = b->file_pos = b->file_last = 0; b->file = NULL; b->temporary = b->in_memory = b->in_file = 0; -#if !defined(WIN32) +#if !defined(WIN32) && defined(MLN_MMAP) b->mmap = 0; #endif b->flush = b->sync = b->last_buf = b->last_in_chain = 0; @@ -39,7 +39,7 @@ void mln_buf_pool_release(mln_buf_t *b) } if (b->in_memory) { -#if !defined(WIN32) +#if !defined(WIN32) && defined(MLN_MMAP) if (b->mmap) { if (b->start != NULL) { munmap(b->start, b->end - b->start); @@ -53,7 +53,7 @@ void mln_buf_pool_release(mln_buf_t *b) } else { mln_alloc_free(b->pos); } -#if !defined(WIN32) +#if !defined(WIN32) && defined(MLN_MMAP) } #endif mln_alloc_free(b);