add file locked_list.h

storage_pool
YuQing 2021-04-09 21:28:22 +08:00
parent c1bb9d6532
commit 6a3bcd4547
3 changed files with 60 additions and 3 deletions

View File

@ -1,5 +1,5 @@
Version 1.49 2021-04-07
Version 1.49 2021-04-09
* add macros: FC_ABS and FC_NEGATIVE
* uniq_skiplist.c: add uniq_skiplist_pair struct and init function
* add functions: fc_mkdirs and str_replace
@ -7,6 +7,7 @@ Version 1.49 2021-04-07
* add functions: fc_string_case_compare, fc_string_case_equal etc.
* add function: fc_check_filename_ex
* add functions: fc_queue_push_queue_to_tail etc.
* add file locked_list.h
Version 1.48 2021-02-01
* fast_buffer.[hc]: add function fast_buffer_append_binary

View File

@ -42,8 +42,9 @@ HEADER_FILES = common_define.h hash.h chain.h logger.h base64.h \
php7_ext_wrapper.h id_generator.h char_converter.h \
char_convert_loader.h common_blocked_queue.h \
multi_socket_client.h skiplist_set.h uniq_skiplist.h \
fc_list.h json_parser.h buffered_file_writer.h server_id_func.h \
fc_queue.h fc_memory.h shared_buffer.h thread_pool.h fc_atomic.h
fc_list.h locked_list.h json_parser.h buffered_file_writer.h \
server_id_func.h fc_queue.h fc_memory.h shared_buffer.h \
thread_pool.h fc_atomic.h
ALL_OBJS = $(FAST_STATIC_OBJS) $(FAST_SHARED_OBJS)

55
src/locked_list.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef _LOCKED_LIST_H
#define _LOCKED_LIST_H
#include "fc_list.h"
#include "pthread_func.h"
typedef struct fc_locked_list {
struct fc_list_head head;
pthread_mutex_t lock;
} FCLockedList;
#ifdef __cplusplus
extern "C" {
#endif
static inline int locked_list_init(FCLockedList *list)
{
int result;
if ((result=init_pthread_lock(&list->lock)) != 0) {
return result;
}
FC_INIT_LIST_HEAD(&list->head);
return 0;
}
static inline void locked_list_add(struct fc_list_head *_new,
FCLockedList *list)
{
PTHREAD_MUTEX_LOCK(&list->lock);
fc_list_add(_new, &list->head);
PTHREAD_MUTEX_UNLOCK(&list->lock);
}
static inline void locked_list_add_tail(struct fc_list_head *_new,
FCLockedList *list)
{
PTHREAD_MUTEX_LOCK(&list->lock);
fc_list_add_tail(_new, &list->head);
PTHREAD_MUTEX_UNLOCK(&list->lock);
}
static inline void locked_list_del(struct fc_list_head *old,
FCLockedList *list)
{
PTHREAD_MUTEX_LOCK(&list->lock);
fc_list_del_init(old);
PTHREAD_MUTEX_UNLOCK(&list->lock);
}
#ifdef __cplusplus
}
#endif
#endif