mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 10:57:34 +08:00
test only
This commit is contained in:
parent
25d33da4de
commit
5291cd0c7a
@ -8,7 +8,7 @@ CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align \
|
||||
###########################################################
|
||||
#Check system:
|
||||
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
|
||||
SYSLIB = -lpthread -lz
|
||||
SYSLIB = -lpthread -lz -ldl
|
||||
CHECKSYSRES = @echo "Unknow system type!";exit 1
|
||||
UNIXNAME = $(shell uname -s)
|
||||
OSTYPE = $(shell uname -m)
|
||||
|
@ -8,7 +8,7 @@ CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align \
|
||||
###########################################################
|
||||
#Check system:
|
||||
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
|
||||
SYSLIB = -lpthread -lz
|
||||
SYSLIB = -lpthread -lz -ldl
|
||||
CHECKSYSRES = @echo "Unknow system type!";exit 1
|
||||
UNIXNAME = $(shell uname -s)
|
||||
OSTYPE = $(shell uname -m)
|
||||
|
@ -84,9 +84,13 @@ ifneq ($(SYSPATH),)
|
||||
endif
|
||||
###########################################################
|
||||
|
||||
CFLAGS += -I../../../../lib_acl/include -I../../../../lib_protocol/include -I../../../../lib_acl_cpp/include
|
||||
CFLAGS += -I../../../../../../lib_acl/include \
|
||||
-I../../../../../../lib_protocol/include \
|
||||
-I../../../../../../lib_acl_cpp/include
|
||||
EXTLIBS =
|
||||
LDFLAGS = -L../../../../lib_acl_cpp/lib -lacl_cpp -L../../../../lib_protocol/lib -lprotocol -L../../../../lib_acl/lib -lacl \
|
||||
LDFLAGS = -L../../../../../../lib_acl_cpp/lib -lacl_cpp \
|
||||
-L../../../../../../lib_protocol/lib -lprotocol \
|
||||
-L../../../../../../lib_acl/lib -lacl \
|
||||
$(EXTLIBS) $(SYSLIB)
|
||||
|
||||
COMPILE = $(CC) $(CFLAGS)
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
// TODO: 在此处引用程序要求的附加头文件
|
||||
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
#include "lib_acl.h"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
#define snprintf _snprintf
|
||||
|
@ -82,16 +82,16 @@ ifneq ($(SYSPATH),)
|
||||
endif
|
||||
###########################################################
|
||||
|
||||
CFLAGS += -I../../../lib_acl/include \
|
||||
-I../../../lib_protocol/include \
|
||||
-I../../../lib_acl_cpp/include \
|
||||
-I../../../lib_fiber/c/include \
|
||||
-I../../../lib_fiber/cpp/include
|
||||
CFLAGS += -I../../../../../lib_acl/include \
|
||||
-I../../../../../lib_protocol/include \
|
||||
-I../../../../../lib_acl_cpp/include \
|
||||
-I../../../../../lib_fiber/c/include \
|
||||
-I../../../../../lib_fiber/cpp/include
|
||||
EXTLIBS =
|
||||
LDFLAGS = -L../../../lib_fiber/lib -lfiber_cpp -lfiber \
|
||||
-L../../../lib_acl_cpp/lib -lacl_cpp \
|
||||
-L../../../lib_protocol/lib -lprotocol \
|
||||
-L../../../lib_acl/lib -lacl \
|
||||
LDFLAGS = -L../../../../../lib_fiber/lib -lfiber_cpp -lfiber \
|
||||
-L../../../../../lib_acl_cpp/lib -lacl_cpp \
|
||||
-L../../../../../lib_protocol/lib -lprotocol \
|
||||
-L../../../../../lib_acl/lib -lacl \
|
||||
$(EXTLIBS) $(SYSLIB)
|
||||
|
||||
COMPILE = $(CC) $(CFLAGS)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "stdlib/acl_define.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef ACL_BCB_COMPILER
|
||||
#pragma hdrstop
|
||||
@ -60,6 +61,7 @@ void acl_debug_init2(const char *str, int max_debug_level)
|
||||
__debug_levels[i] = 0;
|
||||
|
||||
for (i = 0; i < tokens->argc; i++) {
|
||||
size_t n;
|
||||
char* ptr = tokens->argv[i];
|
||||
ACL_ARGV* pair = acl_argv_split(ptr, ":");
|
||||
if (pair->argc != 2) {
|
||||
@ -73,6 +75,10 @@ void acl_debug_init2(const char *str, int max_debug_level)
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr = pair->argv[0];
|
||||
n = strcspn(ptr, "->|,;.@{}[]<>#$%^&()+*!");
|
||||
ptr[n] = 0;
|
||||
|
||||
section = atoi(pair->argv[0]);
|
||||
level = atoi(pair->argv[1]);
|
||||
|
||||
|
@ -7,35 +7,36 @@ struct ACL_MBOX;
|
||||
namespace acl
|
||||
{
|
||||
|
||||
class ACL_CPP_API mobj
|
||||
{
|
||||
public:
|
||||
mobj(void) {}
|
||||
virtual ~mobj(void) {}
|
||||
};
|
||||
|
||||
class ACL_CPP_API mbox : public noncopyable
|
||||
//class ACL_CPP_API mbox : public noncopyable
|
||||
template<typename T>
|
||||
class mbox
|
||||
{
|
||||
public:
|
||||
mbox(void);
|
||||
~mbox(void);
|
||||
~mbox(void) {}
|
||||
|
||||
/**
|
||||
* 发送消息对象
|
||||
* @param o {mobj*} 非空消息对象
|
||||
* @param t {T*} 非空消息对象
|
||||
* @return {bool} 发送是否成功
|
||||
*/
|
||||
bool push(mobj* o);
|
||||
bool push(T* t)
|
||||
{
|
||||
return push_one((void*) t);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收消息对象
|
||||
* @param timeout {int} 大于 0 时设置读等待超时时间(毫秒级别),否则
|
||||
* 永远等待直到读到消息对象或出错
|
||||
* @param success {bool*} 可以用于辅助确定读操作是否成功
|
||||
* @return {mobj*} 非 NULL 表示读到一个消息对象,为 NULL 时,还需通过
|
||||
* @return {T*} 非 NULL 表示读到一个消息对象,为 NULL 时,还需通过
|
||||
* success 参数的返回值检查操作是否成功
|
||||
*/
|
||||
mobj* pop(int timeout = 0, bool* success = NULL);
|
||||
T* pop(int timeout = 0, bool* success = NULL)
|
||||
{
|
||||
return (T*) pop_one(timeout, success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计当前已经发送的消息数
|
||||
@ -51,6 +52,9 @@ public:
|
||||
|
||||
private:
|
||||
ACL_MBOX* mbox_;
|
||||
|
||||
bool push_one(void* o);
|
||||
void* pop_one(int timeout, bool* success);
|
||||
};
|
||||
|
||||
} // namespace acl
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
logger_open("test.log", "logger", "all:1");
|
||||
acl::log::stdout_open(true);
|
||||
logger_open("test.log", "logger", "101->DEBUG_TEST1:1");
|
||||
|
||||
logger("logger opened!");
|
||||
acl::log::logger_test1();
|
||||
|
@ -8,42 +8,42 @@
|
||||
namespace acl
|
||||
{
|
||||
|
||||
static void free_callback(void *ctx)
|
||||
{
|
||||
mbox* o = (mbox*) ctx;
|
||||
delete o;
|
||||
}
|
||||
|
||||
mbox::mbox(void)
|
||||
template<typename T>
|
||||
mbox<T>::mbox(void)
|
||||
{
|
||||
mbox_ = acl_mbox_create();
|
||||
}
|
||||
|
||||
mbox::~mbox(void)
|
||||
template<typename T>
|
||||
mbox<T>::~mbox(void)
|
||||
{
|
||||
acl_mbox_free(mbox_, free_callback);
|
||||
acl_mbox_free(mbox_, NULL);
|
||||
}
|
||||
|
||||
bool mbox::push(mobj* o)
|
||||
template<typename T>
|
||||
bool mbox<T>::push_one(void* o)
|
||||
{
|
||||
return acl_mbox_send(mbox_, o) == 0;
|
||||
}
|
||||
|
||||
mobj* mbox::pop(int timeout /* = 0 */, bool* success /* = NULL */)
|
||||
template<typename T>
|
||||
void* mbox<T>::pop_one(int timeout /* = 0 */, bool* success /* = NULL */)
|
||||
{
|
||||
int ok;
|
||||
mobj* o = (mobj*) acl_mbox_read(mbox_, timeout, &ok);
|
||||
void* o = (void*) acl_mbox_read(mbox_, timeout, &ok);
|
||||
if (success)
|
||||
*success = ok ? true : false;
|
||||
return o;
|
||||
}
|
||||
|
||||
size_t mbox::push_count(void) const
|
||||
template<typename T>
|
||||
size_t mbox<T>::push_count(void) const
|
||||
{
|
||||
return acl_mbox_nsend(mbox_);
|
||||
}
|
||||
|
||||
size_t mbox::pop_count(void) const
|
||||
template<typename T>
|
||||
size_t mbox<T>::pop_count(void) const
|
||||
{
|
||||
return acl_mbox_nread(mbox_);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class myobj : public acl::mobj
|
||||
class myobj
|
||||
{
|
||||
public:
|
||||
myobj(void) : n_(0) {}
|
||||
@ -31,7 +31,7 @@ private:
|
||||
class mythread : public acl::thread
|
||||
{
|
||||
public:
|
||||
mythread(acl::mbox& mb, myobj& o) : mb_(mb), o_(o) {}
|
||||
mythread(acl::mbox<myobj>& mb, myobj& o) : mb_(mb), o_(o) {}
|
||||
~mythread(void) {}
|
||||
|
||||
protected:
|
||||
@ -44,7 +44,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
acl::mbox& mb_;
|
||||
acl::mbox<myobj>& mb_;
|
||||
myobj& o_;
|
||||
};
|
||||
|
||||
@ -64,7 +64,8 @@ protected:
|
||||
mythread thr(mb_, mo);
|
||||
thr.start();
|
||||
|
||||
myobj* o = (myobj*) mb_.pop();
|
||||
myobj* o = mb_.pop();
|
||||
// myobj* o = (myobj*) mb_.pop();
|
||||
assert(o == &mo);
|
||||
printf("fiber-%u: result = %d\r\n", get_id(), o->get_result());
|
||||
|
||||
@ -73,7 +74,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
acl::mbox mb_;
|
||||
acl::mbox<myobj> mb_;
|
||||
acl::fiber_sem& sem_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user