Skip to content

Commit

Permalink
optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Oct 11, 2023
1 parent bac412e commit 15969bc
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 73 deletions.
20 changes: 10 additions & 10 deletions include/mln_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ struct mln_alloc_shm_attr_s {
* But in Linux, no such kind of problem.
*/
typedef struct mln_alloc_blk_s {
struct mln_alloc_blk_s *prev;
struct mln_alloc_blk_s *next;
mln_alloc_t *pool;
void *data;
mln_alloc_chunk_t *chunk;
mln_size_t blk_size;
mln_size_t is_large:1;
mln_size_t in_used:1;
mln_size_t padding:30;
struct mln_alloc_blk_s *prev;
struct mln_alloc_blk_s *next;
} mln_alloc_blk_t;

struct mln_alloc_chunk_s {
Expand All @@ -78,24 +78,18 @@ struct mln_alloc_mgr_s {
};

typedef struct mln_alloc_shm_s {
struct mln_alloc_shm_s *prev;
struct mln_alloc_shm_s *next;
mln_alloc_t *pool;
void *addr;
mln_size_t size;
mln_u32_t nfree;
mln_u32_t base:31;
mln_u32_t large:1;
mln_u8_t bitmap[M_ALLOC_SHM_BITMAP_LEN];
struct mln_alloc_shm_s *prev;
struct mln_alloc_shm_s *next;
} mln_alloc_shm_t;

struct mln_alloc_s {
mln_alloc_mgr_t mgr_tbl[M_ALLOC_MGR_LEN];
struct mln_alloc_s *parent;
mln_alloc_chunk_t *large_used_head;
mln_alloc_chunk_t *large_used_tail;
mln_alloc_shm_t *shm_head;
mln_alloc_shm_t *shm_tail;
void *mem;
mln_size_t shm_size;
void *locker;
Expand All @@ -104,6 +98,12 @@ struct mln_alloc_s {
#if defined(WIN32)
HANDLE map_handle;
#endif
struct mln_alloc_s *parent;
mln_alloc_mgr_t mgr_tbl[M_ALLOC_MGR_LEN];
mln_alloc_chunk_t *large_used_head;
mln_alloc_chunk_t *large_used_tail;
mln_alloc_shm_t *shm_head;
mln_alloc_shm_t *shm_tail;
};


Expand Down
51 changes: 25 additions & 26 deletions include/mln_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ enum mln_event_type {
};

typedef struct mln_event_fd_s {
int fd;
mln_u32_t active_flag;
mln_u32_t in_process:1;
mln_u32_t is_clear:1;
mln_u32_t in_active:1;
mln_u32_t rd_oneshot:1;
mln_u32_t wr_oneshot:1;
mln_u32_t err_oneshot:1;
mln_u32_t padding:26;
void *rcv_data;
ev_fd_handler rcv_handler;
void *snd_data;
Expand All @@ -76,15 +85,6 @@ typedef struct mln_event_fd_s {
ev_fd_handler timeout_handler;
mln_fheap_node_t *timeout_node;
mln_u64_t end_us;
int fd;
mln_u32_t active_flag;
mln_u32_t in_process:1;
mln_u32_t is_clear:1;
mln_u32_t in_active:1;
mln_u32_t rd_oneshot:1;
mln_u32_t wr_oneshot:1;
mln_u32_t err_oneshot:1;
mln_u32_t padding:26;
} mln_event_fd_t;

typedef struct mln_event_tm_s {
Expand All @@ -94,35 +94,26 @@ typedef struct mln_event_tm_s {
} mln_event_tm_t;

struct mln_event_desc_s {
struct mln_event_desc_s *prev;
struct mln_event_desc_s *next;
struct mln_event_desc_s *act_prev;
struct mln_event_desc_s *act_next;
enum mln_event_type type;
mln_u32_t flag;
union {
mln_event_fd_t fd;
mln_event_tm_t tm;
mln_event_fd_t fd;
} data;
struct mln_event_desc_s *prev;
struct mln_event_desc_s *next;
struct mln_event_desc_s *act_prev;
struct mln_event_desc_s *act_next;
};

struct mln_event_s {
pthread_mutex_t fd_lock;
pthread_mutex_t timer_lock;
pthread_mutex_t cb_lock;
dispatch_callback callback;
void *callback_data;
mln_rbtree_t *ev_fd_tree;
mln_event_desc_t *ev_fd_wait_head;
mln_event_desc_t *ev_fd_wait_tail;
mln_event_desc_t *ev_fd_active_head;
mln_event_desc_t *ev_fd_active_tail;
mln_fheap_t *ev_fd_timeout_heap;
mln_fheap_t *ev_timer_heap;
mln_u32_t is_break:1;
mln_u32_t padding:31;
int rd_fd;
int wr_fd;
pthread_mutex_t fd_lock;
pthread_mutex_t timer_lock;
pthread_mutex_t cb_lock;
#if defined(MLN_EPOLL)
int epollfd;
int unusedfd;
Expand All @@ -135,6 +126,14 @@ struct mln_event_s {
fd_set wr_set;
fd_set err_set;
#endif

mln_rbtree_t *ev_fd_tree;
mln_event_desc_t *ev_fd_wait_head;
mln_event_desc_t *ev_fd_wait_tail;
mln_event_desc_t *ev_fd_active_head;
mln_event_desc_t *ev_fd_active_tail;
mln_fheap_t *ev_fd_timeout_heap;
mln_fheap_t *ev_timer_heap;
};

#define mln_event_break_set(ev) ((ev)->is_break = 1);
Expand Down
14 changes: 7 additions & 7 deletions include/mln_fheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ typedef struct mln_fheap_node_s {
} mln_fheap_node_t;

typedef struct {
void *pool;
fheap_pool_alloc_handler pool_alloc;
fheap_pool_free_handler pool_free;
void *min_val;
mln_fheap_node_t *root_list;
mln_fheap_node_t *min;
fheap_cmp cmp;
fheap_copy copy;
fheap_key_free key_free;
mln_fheap_node_t *min;
mln_fheap_node_t *root_list;
mln_size_t num;
void *min_val;
void *pool;
fheap_pool_alloc_handler pool_alloc;
fheap_pool_free_handler pool_free;
} mln_fheap_t;

/*
Expand Down Expand Up @@ -94,7 +94,7 @@ mln_fheap_del_child(mln_fheap_node_t **root, mln_fheap_node_t *node)
node->left->right = node->right;
}
} else {
// if (node->right == node) abort();
/*if (node->right == node) abort();*/
node->right->left = node->left;
node->left->right = node->right;
}
Expand Down
14 changes: 7 additions & 7 deletions include/mln_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
typedef struct mln_fileset_s mln_fileset_t;

typedef struct mln_file_s {
mln_string_t *file_path;
struct mln_file_s *prev;
struct mln_file_s *next;
int fd;
mln_u32_t is_tmp:1;
mln_string_t *file_path;
mln_fileset_t *fset;
mln_rbtree_node_t *node;
size_t refer_cnt;
size_t size;
time_t mtime;
time_t ctime;
time_t atime;
size_t size;
size_t refer_cnt;
struct mln_file_s *prev;
struct mln_file_s *next;
mln_fileset_t *fset;
mln_rbtree_node_t *node;
} mln_file_t;

struct mln_fileset_s {
Expand Down
20 changes: 10 additions & 10 deletions include/mln_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ typedef enum mln_hash_flag {
} mln_hash_flag_t;

struct mln_hash_attr {
void *pool;
hash_pool_alloc_handler pool_alloc;
hash_pool_free_handler pool_free;
hash_calc_handler hash;
hash_cmp_handler cmp;
hash_free_handler free_key;
hash_free_handler free_val;
mln_u64_t len_base;
mln_u32_t expandable:1;
mln_u32_t calc_prime:1;
void *pool;
hash_pool_alloc_handler pool_alloc;
hash_pool_free_handler pool_free;
};

typedef struct mln_hash_entry_s {
void *val;
void *key;
struct mln_hash_entry_s *prev;
struct mln_hash_entry_s *next;
void *val;
void *key;
} mln_hash_entry_t;

typedef struct {
Expand All @@ -53,19 +53,19 @@ typedef struct {
} mln_hash_mgr_t;

struct mln_hash_s {
void *pool;
hash_pool_alloc_handler pool_alloc;
hash_pool_free_handler pool_free;
mln_hash_mgr_t *tbl;
mln_u64_t len;
hash_calc_handler hash;
hash_cmp_handler cmp;
hash_free_handler free_key;
hash_free_handler free_val;
mln_hash_mgr_t *tbl;
mln_u64_t len;
mln_u32_t nr_nodes;
mln_u32_t threshold;
mln_u32_t expandable:1;
mln_u32_t calc_prime:1;
void *pool;
hash_pool_alloc_handler pool_alloc;
hash_pool_free_handler pool_free;
};

extern int
Expand Down
12 changes: 6 additions & 6 deletions include/mln_iothread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ typedef void *(*mln_iothread_entry_t)(void *);
typedef void (*mln_iothread_msg_process_t)(mln_iothread_t *, mln_iothread_ep_type_t, mln_iothread_msg_t *);

struct mln_iothread_msg_s {
struct mln_iothread_msg_s *prev;
struct mln_iothread_msg_s *next;
mln_u32_t feedback:1;
mln_u32_t hold:1;
mln_u32_t padding:30;
mln_u32_t type;
void *data;
pthread_mutex_t mutex;
struct mln_iothread_msg_s *prev;
struct mln_iothread_msg_s *next;
};

struct mln_iothread_attr {
Expand All @@ -38,19 +38,19 @@ struct mln_iothread_attr {
};

struct mln_iothread_s {
pthread_t *tids;
pthread_mutex_t io_lock;
pthread_mutex_t user_lock;
int io_fd;
int user_fd;
mln_iothread_entry_t entry;
void *args;
mln_iothread_msg_process_t handler;
mln_iothread_msg_t *io_head;
mln_iothread_msg_t *io_tail;
mln_iothread_entry_t entry;
void *args;
pthread_t *tids;
mln_u32_t nthread;
mln_iothread_msg_t *user_head;
mln_iothread_msg_t *user_tail;
mln_u32_t nthread;
};

#define mln_iothread_sockfd_get(p,t) ((t) == io_thread? (p)->io_fd: (p)->user_fd)
Expand Down
8 changes: 4 additions & 4 deletions include/mln_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ typedef enum {
} mln_log_level_t;

typedef struct {
char dir_path[M_LOG_PATH_LEN/2];
char pid_path[M_LOG_PATH_LEN];
char log_path[M_LOG_PATH_LEN];
mln_spin_t thread_lock;
int fd;
mln_u32_t in_daemon:1;
mln_u32_t init:1;
mln_u32_t padding:30;
mln_log_level_t level;
mln_spin_t thread_lock;
char dir_path[M_LOG_PATH_LEN/2];
char pid_path[M_LOG_PATH_LEN];
char log_path[M_LOG_PATH_LEN];
} mln_log_t;


Expand Down
4 changes: 2 additions & 2 deletions src/mln_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ mln_event_fd_timeout_set(mln_event_t *ev, mln_event_desc_t *ed, int timeout_ms);

/*varliables*/
mln_event_desc_t fheap_min = {
NULL, NULL, NULL, NULL,
M_EV_TM, 0,
{{NULL, NULL, 0}},
NULL, NULL, NULL, NULL
{(mln_event_tm_t){NULL, NULL, 0}},
};

mln_event_t *mln_event_new(void)
Expand Down
2 changes: 1 addition & 1 deletion src/mln_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static mln_logger_t _logger = _mln_sys_log_process;
char log_err_level[] = "Log level permission deny.";
char log_err_fmt[] = "Log message format error.";
char log_path_cmd[] = "log_path";
mln_log_t g_log = {{0},{0},{0},STDERR_FILENO,0,0,0,none,(mln_spin_t)0};
mln_log_t g_log = {(mln_spin_t)0, STDERR_FILENO, 0, 0, 0, none, {0},{0},{0}};

/*
* file lock
Expand Down

0 comments on commit 15969bc

Please sign in to comment.