Compare commits

..

4 Commits

Author SHA1 Message Date
Hongcai Deng 7354132131
Merge a16fde8070 into 128e04b2ec 2026-01-16 22:30:34 +00:00
YuQing 128e04b2ec upgrade version to 1.0.84 2026-01-16 14:45:48 +08:00
YuQing 233b644ce5 add function double2str and double_to_comma_str 2026-01-16 09:31:12 +08:00
YuQing e009d750a5 fast_task_queue.h: add function free_queue_task_arg_offset 2025-12-23 11:52:42 +08:00
7 changed files with 63 additions and 5 deletions

View File

@ -1,4 +1,8 @@
Version 1.84 2026-01-16
* fast_task_queue.h: add function free_queue_task_arg_offset
* add function double2str and double_to_comma_str
Version 1.83 2025-11-15
* fast_task_queue.h: remove field finish_callback

View File

@ -21,5 +21,5 @@ Debian, Ubuntu etc.:
# the command lines as:
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon; git checkout V1.0.83
cd libfastcommon; git checkout V1.0.84
./make.sh clean && ./make.sh && sudo ./make.sh install

View File

@ -3,7 +3,7 @@
%define CommitVersion %(echo $COMMIT_VERSION)
Name: libfastcommon
Version: 1.0.83
Version: 1.0.84
Release: 1%{?dist}
Summary: c common functions library extracted from my open source projects FastDFS
License: LGPL

View File

@ -28,7 +28,7 @@
static int task_alloc_init(struct fast_task_info *task,
struct fast_task_queue *queue)
{
task->arg = (char *)task + ALIGNED_TASK_INFO_SIZE + queue->padding_size;
task->arg = (char *)task + free_queue_task_arg_offset(queue);
task->send.ptr = &task->send.holder;
task->send.ptr->size = queue->min_buff_size;
if (queue->malloc_whole_block) {

View File

@ -236,6 +236,11 @@ static inline int free_queue_alloc_connections(struct fast_task_queue *queue)
return queue->allocator.info.element_total_count;
}
static inline int free_queue_task_arg_offset(struct fast_task_queue *queue)
{
return ALIGNED_TASK_INFO_SIZE + queue->padding_size;
}
int free_queue_get_new_buffer_size(const int min_buff_size,
const int max_buff_size, const int expect_size, int *new_size);

View File

@ -3178,7 +3178,7 @@ key_t fc_ftok(const char *path, const int proj_id)
return (((proj_id & 0xFF) << 24) | (hash_code & 0xFFFFFF));
}
static void add_thousands_separator(char *str, const int len)
static int add_thousands_separator(char *str, const int len)
{
int new_len;
int addings;
@ -3191,7 +3191,7 @@ static void add_thousands_separator(char *str, const int len)
if (len <= 3)
{
return;
return len;
}
if (*str == '-')
@ -3227,6 +3227,8 @@ static void add_thousands_separator(char *str, const int len)
add_count++;
}
}
return new_len;
}
const char *int2str(const int n, char *buff, const bool thousands_separator)
@ -4523,3 +4525,33 @@ int fc_compare_int64_ptr(const int64_t *n1, const int64_t *n2)
{
return fc_compare_int64(*n1, *n2);
}
const char *double2str(const double d, const int scale,
char *buff, const bool thousands_separator)
{
int len;
int front_len;
int tail_len;
int new_len;
char *point;
char fragment[32];
len = fc_ftoa(d, scale, buff);
*(buff + len) = '\0';
if (!thousands_separator) {
return buff;
}
if (scale <= 0) {
add_thousands_separator(buff, len);
return buff;
}
tail_len = 1 + scale;
front_len = len - tail_len;
point = buff + front_len;
memcpy(fragment, point, tail_len + 1);
new_len = add_thousands_separator(buff, front_len);
memcpy(buff + new_len, fragment, tail_len + 1);
return buff;
}

View File

@ -1191,6 +1191,23 @@ static inline const char *long_to_comma_str(const int64_t n, char *buff)
return long2str(n, buff, true);
}
/** convert double to string
* parameters:
* d: the double number
* scale: number of decimal places (round off)
* buff: output buffer
* thousands_separator: if add thousands separator
* return: string buffer
*/
const char *double2str(const double d, const int scale,
char *buff, const bool thousands_separator);
static inline const char *double_to_comma_str(const double d,
const int scale, char *buff)
{
return double2str(d, scale, buff, true);
}
const char *bytes_to_human_str(const int64_t bytes, char *buff);
/** if the string starts with the needle string