Compare commits

..

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

10 changed files with 41 additions and 154 deletions

View File

@ -1,8 +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

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.84
cd libfastcommon; git checkout V1.0.83
./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
* upgrade to 1.0.78-1

View File

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

View File

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

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 + 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->size = queue->min_buff_size;
if (queue->malloc_whole_block) {

View File

@ -236,11 +236,6 @@ 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 int add_thousands_separator(char *str, const int len)
static void add_thousands_separator(char *str, const int len)
{
int new_len;
int addings;
@ -3191,7 +3191,7 @@ static int add_thousands_separator(char *str, const int len)
if (len <= 3)
{
return len;
return;
}
if (*str == '-')
@ -3227,8 +3227,6 @@ static int 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)
@ -4525,33 +4523,3 @@ 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,23 +1191,6 @@ 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

View File

@ -28,68 +28,16 @@
#include "fastcommon/fast_allocator.h"
#define LOOP_COUNT (30 * 1000 * 1000)
#define THREAD_COUNT 2
#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 result;
int k;
int64_t sum;
int64_t start_time;
char time_buff[32];
pthread_mutex_t lock;
log_init();
srand(time(NULL));
@ -101,13 +49,33 @@ int main(int argc, char *argv[])
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 2: %d\n", pthread_mutex_lock(&lock));
printf("unlock 1: %d\n", pthread_mutex_unlock(&lock));
printf("unlock 2: %d\n", pthread_mutex_unlock(&lock));
test("atom", atomic_thread_func);
test("lock", mutex_thread_func);
start_time = get_current_time_ms();
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;
}