Fixed bugs in acl_fiber_close() API in thread mode that needn't create io fiber.

This commit is contained in:
shuxin   zheng 2024-10-18 14:42:48 +08:00
parent edd41f2e39
commit e9ceaa6029
4 changed files with 23 additions and 21 deletions

View File

@ -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_;
}

View File

@ -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();

View File

@ -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);

View File

@ -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