Compare commits

..

No commits in common. "master" and "V1.0.82" have entirely different histories.

11 changed files with 49 additions and 160 deletions

View File

@ -1,11 +1,4 @@
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
Version 1.82 2025-11-04 Version 1.82 2025-11-04
* set use_io_uring explicitly * set use_io_uring explicitly

View File

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

18
debian/changelog vendored
View File

@ -1,21 +1,3 @@
libfastcommon (1.0.83-1) unstable; urgency=medium
* upgrade to 1.0.83-1
-- YuQing <384681@qq.com> Sun, 23 Nov 2025 10:47:37 +0000
libfastcommon (1.0.83-1) unstable; urgency=medium
* upgrade to 1.0.83-1
-- YuQing <384681@qq.com> Sun, 23 Nov 2025 10:00:00 +0000
libfastcommon (1.0.83-1) unstable; urgency=medium
* upgrade to 1.0.83-1
-- YuQing <384681@qq.com> Sun, 23 Nov 2025 09:05:57 +0000
libfastcommon (1.0.78-1) unstable; urgency=medium libfastcommon (1.0.78-1) unstable; urgency=medium
* upgrade to 1.0.78-1 * upgrade to 1.0.78-1

View File

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

View File

@ -297,7 +297,9 @@ char *base64_decode_auto(struct base64_context *context, const char *src, \
memcpy(pBuff, src, nSrcLen); memcpy(pBuff, src, nSrcLen);
memset(pBuff + nSrcLen, context->pad_ch, nPadLen); memset(pBuff + nSrcLen, context->pad_ch, nPadLen);
base64_decode(context, pBuff, nNewLen, dest, dest_len); base64_decode(context, pBuff, nNewLen, dest, dest_len);
if (pBuff != tmpBuff) if (pBuff != tmpBuff)
{ {
free(pBuff); free(pBuff);
@ -383,23 +385,16 @@ char *base64_decode(struct base64_context *context, const char *src, \
if (cycle != 0) if (cycle != 0)
{ {
*dest = '\0'; *dest = '\0';
*dest_len = 0; *dest_len = 0;
fprintf(stderr, "Input to decode not an even multiple of " fprintf(stderr, "Input to decode not an even multiple of " \
"4 characters; pad with %c\n", context->pad_ch); "4 characters; pad with %c\n", context->pad_ch);
return dest; return dest;
}
if (dummies > 2)
{
*dest = '\0';
*dest_len = 0;
fprintf(stderr, "pad char: %c count %d exceeds 2\n",
context->pad_ch, dummies);
return dest;
} }
*dest_len = (pDest - dest) - dummies; *dest_len = (pDest - dest) - dummies;
*(dest + (*dest_len)) = '\0'; *(dest + (*dest_len)) = '\0';
return dest; return dest;
} }

View File

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

View File

@ -37,6 +37,7 @@ struct nio_thread_data;
struct fast_task_info; struct fast_task_info;
typedef int (*ThreadLoopCallback) (struct nio_thread_data *pThreadData); typedef int (*ThreadLoopCallback) (struct nio_thread_data *pThreadData);
typedef int (*TaskFinishCallback) (struct fast_task_info *task);
typedef void (*TaskCleanUpCallback) (struct fast_task_info *task); typedef void (*TaskCleanUpCallback) (struct fast_task_info *task);
typedef int (*TaskInitCallback)(struct fast_task_info *task, void *arg); typedef int (*TaskInitCallback)(struct fast_task_info *task, void *arg);
typedef void (*TaskReleaseCallback)(struct fast_task_info *task); typedef void (*TaskReleaseCallback)(struct fast_task_info *task);
@ -148,6 +149,7 @@ struct fast_task_info
struct fc_list_head dlink; //for polling queue struct fc_list_head dlink; //for polling queue
} polling; //for RDMA busy polling } polling; //for RDMA busy polling
TaskContinueCallback continue_callback; //for continue stage TaskContinueCallback continue_callback; //for continue stage
TaskFinishCallback finish_callback;
struct nio_thread_data *thread_data; struct nio_thread_data *thread_data;
struct sf_network_handler *handler; //network handler for libserverframe nio struct sf_network_handler *handler; //network handler for libserverframe nio
struct fast_task_info *next; //for free queue and deleted list struct fast_task_info *next; //for free queue and deleted list
@ -236,11 +238,6 @@ static inline int free_queue_alloc_connections(struct fast_task_queue *queue)
return queue->allocator.info.element_total_count; 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, int free_queue_get_new_buffer_size(const int min_buff_size,
const int max_buff_size, const int expect_size, int *new_size); const int max_buff_size, const int expect_size, int *new_size);

View File

@ -145,7 +145,10 @@ static void deal_timeouts(FastTimerEntry *head)
/* must set NULL because NOT in time wheel */ /* must set NULL because NOT in time wheel */
current->prev = current->next = NULL; current->prev = current->next = NULL;
pEventEntry = (IOEventEntry *)current; pEventEntry = (IOEventEntry *)current;
pEventEntry->callback(pEventEntry->fd, IOEVENT_TIMEOUT, current); if (pEventEntry != NULL)
{
pEventEntry->callback(pEventEntry->fd, IOEVENT_TIMEOUT, current);
}
} }
} }
@ -240,7 +243,7 @@ int ioevent_loop(struct nio_thread_data *thread_data,
} }
if (thread_data->deleted_list != NULL) { if (thread_data->deleted_list != NULL) {
//count = 0; count = 0;
while (thread_data->deleted_list != NULL) { while (thread_data->deleted_list != NULL) {
task = thread_data->deleted_list; task = thread_data->deleted_list;
thread_data->deleted_list = task->next; thread_data->deleted_list = task->next;
@ -254,7 +257,7 @@ int ioevent_loop(struct nio_thread_data *thread_data,
} }
} }
clean_up_callback(task); clean_up_callback(task);
//count++; count++;
} }
//logInfo("cleanup task count: %d", count); //logInfo("cleanup task count: %d", count);
} }

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)); return (((proj_id & 0xFF) << 24) | (hash_code & 0xFFFFFF));
} }
static int add_thousands_separator(char *str, const int len) static void add_thousands_separator(char *str, const int len)
{ {
int new_len; int new_len;
int addings; int addings;
@ -3191,7 +3191,7 @@ static int add_thousands_separator(char *str, const int len)
if (len <= 3) if (len <= 3)
{ {
return len; return;
} }
if (*str == '-') if (*str == '-')
@ -3227,8 +3227,6 @@ static int add_thousands_separator(char *str, const int len)
add_count++; add_count++;
} }
} }
return new_len;
} }
const char *int2str(const int n, char *buff, const bool thousands_separator) const char *int2str(const int n, char *buff, const bool thousands_separator)
@ -4525,33 +4523,3 @@ int fc_compare_int64_ptr(const int64_t *n1, const int64_t *n2)
{ {
return fc_compare_int64(*n1, *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,23 +1191,6 @@ static inline const char *long_to_comma_str(const int64_t n, char *buff)
return long2str(n, buff, true); 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); const char *bytes_to_human_str(const int64_t bytes, char *buff);
/** if the string starts with the needle string /** if the string starts with the needle string

View File

@ -28,68 +28,16 @@
#include "fastcommon/fast_allocator.h" #include "fastcommon/fast_allocator.h"
#define LOOP_COUNT (30 * 1000 * 1000) #define LOOP_COUNT (30 * 1000 * 1000)
#define THREAD_COUNT 2
#define barrier() __asm__ __volatile__("" ::: "memory") #define barrier() __asm__ __volatile__("" ::: "memory")
static volatile int64_t sum;
static pthread_mutex_t lock;
static void *atomic_thread_func(void *arg)
{
int k;
for (k=1; k<=LOOP_COUNT; k++) {
//__sync_synchronize();
//barrier();
__sync_add_and_fetch(&sum, k);
}
return NULL;
}
static void *mutex_thread_func(void *arg)
{
int k;
for (k=1; k<=LOOP_COUNT; k++) {
pthread_mutex_lock(&lock);
sum += k;
pthread_mutex_unlock(&lock);
}
return NULL;
}
typedef void *(*thread_func)(void *arg);
static int test(const char *caption, thread_func thread_run)
{
int64_t start_time;
char time_buff[32];
pthread_t tids[THREAD_COUNT];
int i;
int result;
start_time = get_current_time_ms();
sum = 0;
for (i=0; i<THREAD_COUNT; i++) {
if ((result=pthread_create(tids + i, NULL, thread_run, NULL)) != 0) {
return result;
}
}
for (i=0; i<THREAD_COUNT; i++) {
pthread_join(tids[i], NULL);
}
printf("%s add, LOOP_COUNT: %s, sum: %"PRId64", time used: "
"%"PRId64" ms\n", caption, int_to_comma_str(LOOP_COUNT, time_buff),
sum, get_current_time_ms() - start_time);
return 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int result; int result;
int k;
int64_t sum;
int64_t start_time;
char time_buff[32];
pthread_mutex_t lock;
log_init(); log_init();
srand(time(NULL)); srand(time(NULL));
@ -101,13 +49,33 @@ int main(int argc, char *argv[])
return result; return result;
} }
start_time = get_current_time_ms();
sum = 0;
for (k=1; k<=LOOP_COUNT; k++) {
//__sync_synchronize();
//barrier();
__sync_add_and_fetch(&sum, k);
}
printf("atom add, LOOP_COUNT: %s, sum: %"PRId64", time used: "
"%"PRId64" ms\n", int_to_comma_str(LOOP_COUNT, time_buff),
sum, get_current_time_ms() - start_time);
printf("lock 1: %d\n", pthread_mutex_lock(&lock)); printf("lock 1: %d\n", pthread_mutex_lock(&lock));
printf("lock 2: %d\n", pthread_mutex_lock(&lock)); printf("lock 2: %d\n", pthread_mutex_lock(&lock));
printf("unlock 1: %d\n", pthread_mutex_unlock(&lock)); printf("unlock 1: %d\n", pthread_mutex_unlock(&lock));
printf("unlock 2: %d\n", pthread_mutex_unlock(&lock)); printf("unlock 2: %d\n", pthread_mutex_unlock(&lock));
test("atom", atomic_thread_func); start_time = get_current_time_ms();
test("lock", mutex_thread_func); sum = 0;
for (k=1; k<=LOOP_COUNT; k++) {
pthread_mutex_lock(&lock);
sum += k;
pthread_mutex_unlock(&lock);
}
printf("locked add, LOOP_COUNT: %s, sum: %"PRId64", time used: "
"%"PRId64" ms\n", int_to_comma_str(LOOP_COUNT, time_buff),
sum, get_current_time_ms() - start_time);
return 0; return 0;
} }