call fast_mblock_ref_counter_dec for delay free node correctly
parent
01f35da9d2
commit
05f3d62ee1
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
Version 1.72 2024-01-07
|
||||||
|
* call fast_mblock_ref_counter_dec for delay free node correctly
|
||||||
|
|
||||||
Version 1.71 2023-12-23
|
Version 1.71 2023-12-23
|
||||||
* full support IPv6 by pull request #47
|
* full support IPv6 by pull request #47
|
||||||
* replace inet_ntop to getnameinfo for IPv6
|
* replace inet_ntop to getnameinfo for IPv6
|
||||||
|
|
|
||||||
|
|
@ -666,9 +666,11 @@ static inline void fast_mblock_ref_counter_op(struct fast_mblock_man *mblock,
|
||||||
}
|
}
|
||||||
|
|
||||||
#define fast_mblock_ref_counter_inc(mblock, pNode) \
|
#define fast_mblock_ref_counter_inc(mblock, pNode) \
|
||||||
|
mblock->info.element_used_count++; \
|
||||||
fast_mblock_ref_counter_op(mblock, pNode, true)
|
fast_mblock_ref_counter_op(mblock, pNode, true)
|
||||||
|
|
||||||
#define fast_mblock_ref_counter_dec(mblock, pNode) \
|
#define fast_mblock_ref_counter_dec(mblock, pNode) \
|
||||||
|
mblock->info.element_used_count--; \
|
||||||
fast_mblock_ref_counter_op(mblock, pNode, false)
|
fast_mblock_ref_counter_op(mblock, pNode, false)
|
||||||
|
|
||||||
static void fast_mblock_free_trunk(struct fast_mblock_man *mblock,
|
static void fast_mblock_free_trunk(struct fast_mblock_man *mblock,
|
||||||
|
|
@ -748,6 +750,7 @@ static inline struct fast_mblock_node *alloc_node(
|
||||||
mblock->delay_free_chain.tail = NULL;
|
mblock->delay_free_chain.tail = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fast_mblock_ref_counter_dec(mblock, pNode);
|
||||||
mblock->info.delay_free_elements--;
|
mblock->info.delay_free_elements--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -775,7 +778,6 @@ static inline struct fast_mblock_node *alloc_node(
|
||||||
|
|
||||||
if (pNode != NULL)
|
if (pNode != NULL)
|
||||||
{
|
{
|
||||||
mblock->info.element_used_count++;
|
|
||||||
fast_mblock_ref_counter_inc(mblock, pNode);
|
fast_mblock_ref_counter_inc(mblock, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -830,7 +832,6 @@ int fast_mblock_free(struct fast_mblock_man *mblock,
|
||||||
notify = (mblock->free_chain_head == NULL);
|
notify = (mblock->free_chain_head == NULL);
|
||||||
pNode->next = mblock->free_chain_head;
|
pNode->next = mblock->free_chain_head;
|
||||||
mblock->free_chain_head = pNode;
|
mblock->free_chain_head = pNode;
|
||||||
mblock->info.element_used_count--;
|
|
||||||
fast_mblock_ref_counter_dec(mblock, pNode);
|
fast_mblock_ref_counter_dec(mblock, pNode);
|
||||||
|
|
||||||
if (mblock->alloc_elements.need_wait && notify)
|
if (mblock->alloc_elements.need_wait && notify)
|
||||||
|
|
@ -859,7 +860,6 @@ static inline void batch_free(struct fast_mblock_man *mblock,
|
||||||
pNode = chain->head;
|
pNode = chain->head;
|
||||||
while (pNode != NULL)
|
while (pNode != NULL)
|
||||||
{
|
{
|
||||||
mblock->info.element_used_count--;
|
|
||||||
fast_mblock_ref_counter_dec(mblock, pNode);
|
fast_mblock_ref_counter_dec(mblock, pNode);
|
||||||
pNode = pNode->next;
|
pNode = pNode->next;
|
||||||
}
|
}
|
||||||
|
|
@ -1013,9 +1013,7 @@ int fast_mblock_delay_free(struct fast_mblock_man *mblock,
|
||||||
mblock->delay_free_chain.tail = pNode;
|
mblock->delay_free_chain.tail = pNode;
|
||||||
pNode->next = NULL;
|
pNode->next = NULL;
|
||||||
|
|
||||||
mblock->info.element_used_count--;
|
|
||||||
mblock->info.delay_free_elements++;
|
mblock->info.delay_free_elements++;
|
||||||
fast_mblock_ref_counter_dec(mblock, pNode);
|
|
||||||
|
|
||||||
if (mblock->need_lock && (result=pthread_mutex_unlock(
|
if (mblock->need_lock && (result=pthread_mutex_unlock(
|
||||||
&mblock->lcp.lock)) != 0)
|
&mblock->lcp.lock)) != 0)
|
||||||
|
|
@ -1080,65 +1078,65 @@ static int fast_mblock_do_reclaim(struct fast_mblock_man *mblock,
|
||||||
const int reclaim_target, int *reclaim_count,
|
const int reclaim_target, int *reclaim_count,
|
||||||
struct fast_mblock_malloc **ppFreelist)
|
struct fast_mblock_malloc **ppFreelist)
|
||||||
{
|
{
|
||||||
struct fast_mblock_node *pPrevious;
|
struct fast_mblock_node *free_chain_prev;
|
||||||
struct fast_mblock_node *pCurrent;
|
struct fast_mblock_node *current;
|
||||||
struct fast_mblock_malloc *pMallocNode;
|
struct fast_mblock_malloc *malloc_node;
|
||||||
struct fast_mblock_malloc *freelist;
|
struct fast_mblock_malloc *freelist;
|
||||||
bool lookup_done;
|
bool lookup_done;
|
||||||
|
|
||||||
lookup_done = false;
|
lookup_done = false;
|
||||||
*reclaim_count = 0;
|
*reclaim_count = 0;
|
||||||
freelist = NULL;
|
freelist = NULL;
|
||||||
pPrevious = NULL;
|
free_chain_prev = NULL;
|
||||||
pCurrent = mblock->free_chain_head;
|
current = mblock->free_chain_head;
|
||||||
mblock->free_chain_head = NULL;
|
mblock->free_chain_head = NULL;
|
||||||
while (pCurrent != NULL)
|
while (current != NULL)
|
||||||
{
|
{
|
||||||
pMallocNode = FAST_MBLOCK_GET_TRUNK(pCurrent);
|
malloc_node = FAST_MBLOCK_GET_TRUNK(current);
|
||||||
if (pMallocNode->ref_count > 0 ||
|
if (malloc_node->ref_count > 0 ||
|
||||||
(pMallocNode->ref_count == 0 && lookup_done))
|
(malloc_node->ref_count == 0 && lookup_done))
|
||||||
{ //keep in free chain
|
{ /* keep in the free chain */
|
||||||
|
|
||||||
if (pPrevious != NULL)
|
if (free_chain_prev != NULL)
|
||||||
{
|
{
|
||||||
pPrevious->next = pCurrent;
|
free_chain_prev->next = current;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mblock->free_chain_head = pCurrent;
|
mblock->free_chain_head = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
pPrevious = pCurrent;
|
free_chain_prev = current;
|
||||||
pCurrent = pCurrent->next;
|
current = current->next;
|
||||||
if (pCurrent == NULL)
|
if (current == NULL)
|
||||||
{
|
{
|
||||||
goto OUTER;
|
goto OUTER;
|
||||||
}
|
}
|
||||||
pMallocNode = FAST_MBLOCK_GET_TRUNK(pCurrent);
|
malloc_node = FAST_MBLOCK_GET_TRUNK(current);
|
||||||
|
|
||||||
while (pMallocNode->ref_count > 0 ||
|
while (malloc_node->ref_count > 0 ||
|
||||||
(pMallocNode->ref_count == 0 && lookup_done))
|
(malloc_node->ref_count == 0 && lookup_done))
|
||||||
{
|
{
|
||||||
pPrevious = pCurrent;
|
free_chain_prev = current;
|
||||||
pCurrent = pCurrent->next;
|
current = current->next;
|
||||||
if (pCurrent == NULL)
|
if (current == NULL)
|
||||||
{
|
{
|
||||||
goto OUTER;
|
goto OUTER;
|
||||||
}
|
}
|
||||||
pMallocNode = FAST_MBLOCK_GET_TRUNK(pCurrent);
|
malloc_node = FAST_MBLOCK_GET_TRUNK(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (pMallocNode->ref_count < 0 ||
|
while (malloc_node->ref_count < 0 ||
|
||||||
(pMallocNode->ref_count == 0 && !lookup_done))
|
(malloc_node->ref_count == 0 && !lookup_done))
|
||||||
{
|
{
|
||||||
if (pMallocNode->ref_count == 0) //trigger by the first node
|
if (malloc_node->ref_count == 0) //trigger by the first node only
|
||||||
{
|
{
|
||||||
fast_mblock_remove_trunk(mblock, pMallocNode);
|
fast_mblock_remove_trunk(mblock, malloc_node);
|
||||||
pMallocNode->ref_count = -1;
|
malloc_node->ref_count = -1;
|
||||||
|
|
||||||
pMallocNode->next = freelist;
|
malloc_node->next = freelist;
|
||||||
freelist = pMallocNode;
|
freelist = malloc_node;
|
||||||
(*reclaim_count)++;
|
(*reclaim_count)++;
|
||||||
if (reclaim_target > 0 && *reclaim_count == reclaim_target)
|
if (reclaim_target > 0 && *reclaim_count == reclaim_target)
|
||||||
{
|
{
|
||||||
|
|
@ -1146,20 +1144,20 @@ static int fast_mblock_do_reclaim(struct fast_mblock_man *mblock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pCurrent = pCurrent->next;
|
current = current->next;
|
||||||
if (pCurrent == NULL)
|
if (current == NULL)
|
||||||
{
|
{
|
||||||
goto OUTER;
|
goto OUTER;
|
||||||
}
|
}
|
||||||
pMallocNode = FAST_MBLOCK_GET_TRUNK(pCurrent);
|
malloc_node = FAST_MBLOCK_GET_TRUNK(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OUTER:
|
OUTER:
|
||||||
if (pPrevious != NULL)
|
if (free_chain_prev != NULL)
|
||||||
{
|
{
|
||||||
pPrevious->next = NULL;
|
free_chain_prev->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1234,6 +1234,7 @@ int getFileContent1(int fd, const char *filename,
|
||||||
char **buff, int64_t *file_size)
|
char **buff, int64_t *file_size)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
int64_t bytes;
|
||||||
|
|
||||||
if ((*file_size=lseek(fd, 0, SEEK_END)) < 0) {
|
if ((*file_size=lseek(fd, 0, SEEK_END)) < 0) {
|
||||||
*buff = NULL;
|
*buff = NULL;
|
||||||
|
|
@ -1262,12 +1263,13 @@ int getFileContent1(int fd, const char *filename,
|
||||||
filename, result, STRERROR(result));
|
filename, result, STRERROR(result));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (read(fd, *buff, *file_size) != *file_size) {
|
if ((bytes=read(fd, *buff, *file_size)) != *file_size) {
|
||||||
result = errno != 0 ? errno : EIO;
|
result = errno != 0 ? errno : EIO;
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"read from file %s fail, size: %"PRId64", "
|
"read from file %s fail, file size: %"PRId64", "
|
||||||
"errno: %d, error info: %s", __LINE__,
|
"read bytes: %"PRId64", errno: %d, error info: %s",
|
||||||
filename, *file_size, result, STRERROR(result));
|
__LINE__, filename, *file_size, bytes, result,
|
||||||
|
STRERROR(result));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
@ -3150,7 +3152,7 @@ ssize_t fc_safe_read(int fd, char *buf, const size_t count)
|
||||||
}
|
}
|
||||||
|
|
||||||
done = count - remain;
|
done = count - remain;
|
||||||
return done > 0 ? done : -1;
|
return (done > 0 ? done : -1);
|
||||||
}
|
}
|
||||||
else if (n == 0)
|
else if (n == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue