mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
Fixed bugs in acl_fiber_close() API in thread mode that needn't create io fiber.
This commit is contained in:
parent
edd41f2e39
commit
e9ceaa6029
@ -125,14 +125,14 @@ public:
|
||||
|
||||
/**
|
||||
* 检测连接状态,并关闭断开连接,内部自动加锁保护
|
||||
* @param threads {thread_pool*} 非空时将使用该线程池检测连接状态
|
||||
* @param threads {thread_pool*} 非空时将使用该线程池检测连接状态以提升效率
|
||||
* @return {size_t} 被关闭的连接个数
|
||||
*/
|
||||
size_t check_dead(thread_pool* threads = NULL);
|
||||
|
||||
/**
|
||||
* 尽量保持由 set_conns_min() 设置的最小连接数
|
||||
* @param threads {thread_pool*} 非空时将使用该线程池创建新连接
|
||||
* @param threads {thread_pool*} 非空时将使用该线程池创建新连接以提升效率
|
||||
*/
|
||||
void keep_conns(thread_pool* threads = NULL);
|
||||
|
||||
@ -189,14 +189,15 @@ public:
|
||||
void reset_statistics(int inter);
|
||||
|
||||
/**
|
||||
* 获取该连接池总共被使用的次数
|
||||
* 获取该连接池总共被使用过的次数
|
||||
*/
|
||||
unsigned long long get_total_used() const {
|
||||
return total_used_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该连接池当前的使用次数
|
||||
* 获取该连接池当前的使用次数累加值,当调用reset_statistics时会重置该值,
|
||||
* 这是与get_total_used()的区别所在
|
||||
* @return {unsigned long long}
|
||||
*/
|
||||
unsigned long long get_current_used() const {
|
||||
@ -205,7 +206,7 @@ public:
|
||||
|
||||
public:
|
||||
void set_key(const char* key);
|
||||
const char* get_key(void) const {
|
||||
const char* get_key() const {
|
||||
return key_;
|
||||
}
|
||||
|
||||
|
@ -272,14 +272,16 @@ static acl_pthread_once_t once_control = ACL_PTHREAD_ONCE_INIT;
|
||||
|
||||
conns_pools& connect_manager::get_pools_by_id(unsigned long id)
|
||||
{
|
||||
lock_.lock();
|
||||
manager_it mit = manager_.find(id);
|
||||
if (mit != manager_.end()) {
|
||||
lock_.unlock();
|
||||
return *mit->second;
|
||||
}
|
||||
|
||||
conns_pools* pools = NEW conns_pools;
|
||||
manager_[id] = pools;
|
||||
//printf("thread id=%lu create pools, %lu\r\n", id, pthread_self());
|
||||
lock_.unlock();
|
||||
|
||||
if (id == DEFAULT_ID) {
|
||||
return *pools;
|
||||
@ -361,7 +363,7 @@ connect_pool* connect_manager::get(const char* addr,
|
||||
pools_t::iterator it = pools.pools.begin();
|
||||
for (; it != pools.pools.end(); ++it) {
|
||||
if (key == (*it)->get_key()) {
|
||||
if (restore && (*it)->aliving() == false) {
|
||||
if (restore && !(*it)->aliving()) {
|
||||
(*it)->set_alive(true);
|
||||
}
|
||||
if (exclusive) {
|
||||
@ -611,9 +613,6 @@ connect_pool* connect_manager::peek(const char* addr,
|
||||
}
|
||||
|
||||
unsigned long id = get_id();
|
||||
connect_pool* pool;
|
||||
|
||||
size_t service_size;
|
||||
unsigned n = acl_hash_crc32(addr, strlen(addr));
|
||||
|
||||
if (exclusive) {
|
||||
@ -629,15 +628,16 @@ connect_pool* connect_manager::peek(const char* addr,
|
||||
}
|
||||
|
||||
conns_pools& pools = get_pools_by_id(id);
|
||||
service_size = pools.pools.size();
|
||||
if (service_size == 0) {
|
||||
size_t pools_size = pools.pools.size();
|
||||
|
||||
if (pools_size == 0) {
|
||||
create_pools_for(pools.pools);
|
||||
service_size = pools.pools.size();
|
||||
assert(service_size > 0);
|
||||
pools_size = pools.pools.size();
|
||||
assert(pools_size > 0);
|
||||
}
|
||||
|
||||
n = n % service_size;
|
||||
pool = pools.pools[n];
|
||||
n = n % pools_size;
|
||||
connect_pool* pool = pools.pools[n];
|
||||
|
||||
if (exclusive) {
|
||||
lock_.unlock();
|
||||
|
@ -494,6 +494,8 @@ size_t connect_pool::check_dead(thread_pool* threads /* NULL */)
|
||||
if (threads == NULL) {
|
||||
return check_dead(count);
|
||||
}
|
||||
|
||||
// 采用线程池检测,以提升检测效率
|
||||
return check_dead(count, *threads);
|
||||
}
|
||||
|
||||
@ -605,7 +607,6 @@ connect_client* connect_pool::peek_back()
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
void connect_pool::put_front(connect_client* conn)
|
||||
{
|
||||
//time_t now = time(NULL);
|
||||
|
@ -59,10 +59,10 @@ int WINAPI acl_fiber_close(socket_t fd)
|
||||
#else
|
||||
// In thread mode, we only need to free the fe, because
|
||||
// no fiber was bound with the fe.
|
||||
fe = fiber_file_get(fd);
|
||||
if (fe) {
|
||||
fiber_file_free(fe);
|
||||
}
|
||||
//fe = fiber_file_get(fd);
|
||||
//if (fe) {
|
||||
// fiber_file_free(fe);
|
||||
//}
|
||||
|
||||
return (*sys_close)(fd);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user