Skip to content

Commit b20e0b6

Browse files
committed
acl 3.0.16 版本发布!
该版本主要优化了线程池调度的性能,同时优化了多线程事件引擎的效率
1 parent e2bbbac commit b20e0b6

File tree

13 files changed

+125
-53
lines changed

13 files changed

+125
-53
lines changed

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
�޸���ʷ�б���
22
------------------------------------------------------------------------
3+
66) 2014.2.17 --- acl 3.0.16 �汾������
34
65) 2014.1.25 --- acl 3.0.15 �汾������
45
64) 2014.1.11
56
64.1) ��������� VC2008 ��֧��

lib_acl/changes.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
�޸���ʷ�б���
2+
23
------------------------------------------------------------------------
34

5+
426) 2014.2.17
6+
426.1) feature: acl_event.c ���Ӻ��� acl_event_set_check_inter����������
7+
�����¼�ѭ�����̽���ȫ�������ּ���ʱ����
8+
49
425) 2014.2.14
510
425.1) performance: acl_pthread_pool.c���� pthread_cond_signal ����
611
pthread_mutex_unlock ֮�󣬴Ӷ����������̵߳ȴ����񱻴�����ʱ��(Ϊ�˷�ֹ
@@ -47,6 +52,8 @@ acl_aio_server.c, acl_udp_server.c
4752
Ϊÿ���߳�һ���������߳������������Ӷ��������߳�֮�������ͻ����������
4853
�̳߳ص���������
4954

55+
------------------------------------------------------------------------
56+
5057
415) 2014.1.11
5158
415.1) compile: ȥ���� ACL_MS_WINDOWS �궨�壬��WINDOWS������ͳһʹ�� WIN32
5259
����ʶ VC ���뻷��

lib_acl/include/event/acl_events.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,25 @@ ACL_API HWND acl_event_wmsg_hwnd(ACL_EVENT *eventp);
147147
*/
148148
ACL_API void acl_event_add_dog(ACL_EVENT *eventp);
149149

150-
ACL_API void acl_event_fire_hook(ACL_EVENT *eventp,
150+
/**
151+
* 设置事件触发的前置和后置处理过程
152+
* @param eventp {ACL_EVENT*} 事件对象指针, 不为能为空
153+
* @param fire_begin {void (*)(ACL_EVENT*, void*)} 当事件被统一触发前的回调过程
154+
* @param fire_end {void (*)(ACL_EVENT*, void*)} 当事件被统一触发后的回调过程
155+
* @param ctx {void*} fire_begin / fire_end 的第二个参数
156+
*/
157+
ACL_API void acl_event_set_fire_hook(ACL_EVENT *eventp,
151158
void (*fire_begin)(ACL_EVENT*, void*),
152159
void (*fire_end)(ACL_EVENT*, void*),
153160
void* ctx);
154161

162+
/**
163+
* 设置事件循环过程中定时检查所有描述字状态的时间间隔,内部缺少值为 100 ms
164+
* @param eventp {ACL_EVENT*} 事件对象指针, 不为能为空
165+
* @param n {int} 定时查检时间间隔 (毫秒级)
166+
*/
167+
ACL_API void acl_event_set_check_inter(ACL_EVENT *eventp, int n);
168+
155169
/**
156170
* 释放事件结构
157171
* @param eventp {ACL_EVENT*} 事件对象指针, 不为能为空

lib_acl/include/master/acl_threads_params.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ extern int acl_var_threads_schedule_warn;
116116
#define ACL_DEF_THREADS_SCHEDULE_WAIT 50
117117
extern int acl_var_threads_schedule_wait;
118118

119+
#define ACL_VAR_THREADS_CHECK_INTER "ioctl_check_inter"
120+
#define ACL_DEF_THREADS_CHECK_INTER 100
121+
extern int acl_var_threads_check_inter;
122+
123+
#define ACL_VAR_THREADS_QLEN_WARN "ioctl_qlen_warn"
124+
#define ACL_DEF_THREADS_QLEN_WARN 0
125+
extern int acl_var_threads_qlen_warn;
126+
119127
#endif /* ACL_UNIX */
120128

121129
#ifdef __cplusplus

lib_acl/src/event/acl_events.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ static void event_init(ACL_EVENT *eventp, int fdsize,
4545

4646
eventp->delay_sec = delay_sec + delay_usec / 1000000;
4747
eventp->delay_usec = delay_usec % 1000000;
48-
/*
49-
acl_ring_init(&eventp->used_ring);
50-
acl_ring_init(&eventp->slot_ring);
51-
*/
5248

5349
acl_ring_init(&eventp->timer_head);
5450
eventp->timer_keep = 0;
5551
SET_TIME(eventp->present);
5652
SET_TIME(eventp->last_debug);
5753

54+
eventp->check_inter = 100000; /* default: 100 ms */
55+
5856
if (eventp->init_fn)
5957
eventp->init_fn(eventp);
6058
}
@@ -214,18 +212,21 @@ ACL_EVENT *acl_event_new_wmsg(unsigned int nMsg)
214212
#endif
215213
}
216214

217-
ACL_EVENT *acl_event_new(int event_mode, int use_thr, int delay_sec, int delay_usec)
215+
ACL_EVENT *acl_event_new(int event_mode, int use_thr,
216+
int delay_sec, int delay_usec)
218217
{
219218
const char *myname = "acl_event_new";
220219
ACL_EVENT *eventp = NULL;
221220

222221
if (use_thr) {
223222
switch (event_mode) {
224223
case ACL_EVENT_SELECT:
225-
eventp = acl_event_new_select_thr(delay_sec, delay_usec);
224+
eventp = acl_event_new_select_thr(delay_sec,
225+
delay_usec);
226226
break;
227227
case ACL_EVENT_KERNEL:
228-
eventp = acl_event_new_kernel_thr(delay_sec, delay_usec);
228+
eventp = acl_event_new_kernel_thr(delay_sec,
229+
delay_usec);
229230
break;
230231
case ACL_EVENT_POLL:
231232
eventp = acl_event_new_poll_thr(delay_sec, delay_usec);
@@ -260,7 +261,13 @@ ACL_EVENT *acl_event_new(int event_mode, int use_thr, int delay_sec, int delay_u
260261
return eventp;
261262
}
262263

263-
void acl_event_fire_hook(ACL_EVENT *eventp, void (*fire_begin)(ACL_EVENT*, void*),
264+
void acl_event_set_check_inter(ACL_EVENT *eventp, int n)
265+
{
266+
eventp->check_inter = n * 1000;
267+
}
268+
269+
void acl_event_set_fire_hook(ACL_EVENT *eventp,
270+
void (*fire_begin)(ACL_EVENT*, void*),
264271
void (*fire_end)(ACL_EVENT*, void*), void* ctx)
265272
{
266273
eventp->fire_begin = fire_begin;
@@ -282,6 +289,7 @@ void acl_event_free(ACL_EVENT *eventp)
282289
acl_ring_detach(&timer->ring);
283290
acl_myfree(timer);
284291
}
292+
285293
acl_myfree(eventp->fdtabs);
286294
acl_myfree(eventp->fdtabs_ready);
287295
free_fn(eventp);
@@ -300,7 +308,8 @@ void acl_event_enable_read(ACL_EVENT *eventp, ACL_VSTREAM *stream,
300308
if (sockfd == ACL_SOCKET_INVALID)
301309
acl_msg_fatal("%s(%d): sockfd(%d) invalid",
302310
myname, __LINE__, sockfd);
303-
eventp->enable_read_fn(eventp, stream, read_timeout, callback, context);
311+
eventp->enable_read_fn(eventp, stream, read_timeout,
312+
callback, context);
304313
}
305314

306315
void acl_event_enable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream,
@@ -311,13 +320,15 @@ void acl_event_enable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream,
311320
if (sockfd == ACL_SOCKET_INVALID)
312321
acl_msg_fatal("%s(%d): sockfd(%d) invalid",
313322
myname, __LINE__, sockfd);
314-
eventp->enable_write_fn(eventp, stream, write_timeout, callback, context);
323+
eventp->enable_write_fn(eventp, stream, write_timeout,
324+
callback, context);
315325
}
316326

317327
void acl_event_enable_listen(ACL_EVENT *eventp, ACL_VSTREAM *stream,
318328
int read_timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context)
319329
{
320-
eventp->enable_listen_fn(eventp, stream, read_timeout, callback, context);
330+
eventp->enable_listen_fn(eventp, stream, read_timeout,
331+
callback, context);
321332
}
322333

323334
void acl_event_disable_read(ACL_EVENT *eventp, ACL_VSTREAM *stream)

lib_acl/src/event/events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct ACL_EVENT {
8080
/* 当前时间截(微秒级) */
8181
acl_int64 present;
8282
acl_int64 last_check;
83+
acl_int64 check_inter;
8384
acl_int64 last_debug;
8485
/* 事件引擎的最大等待时间(秒) */
8586
int delay_sec;

lib_acl/src/event/events_epoll_thr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static void event_loop(ACL_EVENT *eventp)
343343

344344
eventp->fdcnt_ready = 0;
345345

346-
if (eventp->present - eventp->last_check >= 100000) {
346+
if (eventp->present - eventp->last_check >= eventp->check_inter) {
347347
eventp->last_check = eventp->present;
348348

349349
THREAD_LOCK(&event_thr->event.tb_mutex);
@@ -371,7 +371,7 @@ static void event_loop(ACL_EVENT *eventp)
371371

372372
if (nready < 0) {
373373
if (acl_last_error() != ACL_EINTR)
374-
acl_msg_fatal("%s(%d), %s: event_loop: select: %s",
374+
acl_msg_fatal("%s(%d), %s: event_loop: epoll: %s",
375375
__FILE__, __LINE__, myname, acl_last_serror());
376376
goto TAG_DONE;
377377
} else if (nready == 0)

lib_acl/src/event/events_kernel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static void event_set_all(ACL_EVENT *eventp)
592592

593593
eventp->fdcnt_ready = 0;
594594

595-
if (eventp->present - eventp->last_check >= 100000) {
595+
if (eventp->present - eventp->last_check >= eventp->check_inter) {
596596
eventp->last_check = eventp->present;
597597
event_check_fds(eventp);
598598
}

lib_acl/src/event/events_poll_thr.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ static void event_enable_listen(ACL_EVENT *eventp, ACL_VSTREAM *stream,
153153
if (eventp->maxfd == ACL_SOCKET_INVALID || eventp->maxfd < sockfd)
154154
eventp->maxfd = sockfd;
155155

156-
acl_fdmap_add(event_thr->fdmap, sockfd, fdp);
157-
158156
THREAD_UNLOCK(&event_thr->event.tb_mutex);
157+
158+
acl_fdmap_add(event_thr->fdmap, sockfd, fdp);
159159
}
160160

161161
static void event_enable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream,
@@ -261,10 +261,10 @@ static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream)
261261
event_thr->fds[fdp->fdidx] = event_thr->fds[eventp->fdcnt];
262262
}
263263

264-
THREAD_UNLOCK(&event_thr->event.tb_mutex);
265-
266264
acl_fdmap_del(event_thr->fdmap, sockfd);
267265

266+
THREAD_UNLOCK(&event_thr->event.tb_mutex);
267+
268268
if (fdp->flag & EVENT_FDTABLE_FLAG_READ)
269269
stream->nrefer--;
270270
if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE)
@@ -314,24 +314,25 @@ static void event_loop(ACL_EVENT *eventp)
314314
ACL_EVENT_NOTIFY_TIME timer_fn;
315315
ACL_EVENT_TIMER *timer;
316316
void *timer_arg;
317-
int delay, nready, i, revents;
317+
int delay, nready, i, revents, fdcnt;
318318
ACL_EVENT_FDTABLE *fdp;
319319

320320
acl_ring_init(&timer_ring);
321321

322322
delay = eventp->delay_sec * 1000 + eventp->delay_usec / 1000;
323-
if (delay <= 0)
323+
if (delay < 0)
324324
delay = 100; /* 100 milliseconds at least */
325325

326326
SET_TIME(eventp->present);
327327
THREAD_LOCK(&event_thr->event.tm_mutex);
328328

329329
/*
330-
* Find out when the next timer would go off. Timer requests are sorted.
331-
* If any timer is scheduled, adjust the delay appropriately.
330+
* Find out when the next timer would go off. Timer requests
331+
* are sorted. If any timer is scheduled, adjust the delay
332+
* appropriately.
332333
*/
333334
if ((timer = ACL_FIRST_TIMER(&eventp->timer_head)) != 0) {
334-
int n = (int) (timer->when - eventp->present + 1000000 - 1)
335+
int n = (int) (timer->when - eventp->present + 1000000 - 1)
335336
/ 1000000;
336337
if (n <= 0)
337338
delay = 0;
@@ -343,12 +344,13 @@ static void event_loop(ACL_EVENT *eventp)
343344

344345
eventp->fdcnt_ready = 0;
345346

346-
if (eventp->present - eventp->last_check >= 100000) {
347+
if (eventp->present - eventp->last_check >= eventp->check_inter) {
347348
eventp->last_check = eventp->present;
348349

349350
THREAD_LOCK(&event_thr->event.tb_mutex);
350351

351352
if (event_thr_prepare(eventp) == 0) {
353+
352354
THREAD_UNLOCK(&event_thr->event.tb_mutex);
353355

354356
if (eventp->fdcnt_ready == 0)
@@ -358,7 +360,9 @@ static void event_loop(ACL_EVENT *eventp)
358360
goto TAG_DONE;
359361
}
360362

361-
memcpy(event_thr->fdset, event_thr->fds, eventp->fdcnt);
363+
memcpy(event_thr->fdset, event_thr->fds,
364+
eventp->fdcnt * sizeof(struct pollfd));
365+
fdcnt = eventp->fdcnt;
362366

363367
THREAD_UNLOCK(&event_thr->event.tb_mutex);
364368

@@ -367,24 +371,26 @@ static void event_loop(ACL_EVENT *eventp)
367371
} else {
368372
THREAD_LOCK(&event_thr->event.tb_mutex);
369373

370-
memcpy(event_thr->fdset, event_thr->fds, eventp->fdcnt);
374+
memcpy(event_thr->fdset, event_thr->fds,
375+
eventp->fdcnt * sizeof(struct pollfd));
376+
fdcnt = eventp->fdcnt;
371377

372378
THREAD_UNLOCK(&event_thr->event.tb_mutex);
373379
}
374380

375381
event_thr->event.blocked = 1;
376-
nready = poll(event_thr->fdset, eventp->fdcnt, delay);
382+
nready = poll(event_thr->fdset, fdcnt, delay);
377383
event_thr->event.blocked = 0;
378384

379385
if (nready < 0) {
380386
if (acl_last_error() != ACL_EINTR)
381-
acl_msg_fatal("%s(%d), %s: event_loop: select: %s",
387+
acl_msg_fatal("%s(%d), %s: event_loop: poll: %s",
382388
__FILE__, __LINE__, myname, acl_last_serror());
383389
goto TAG_DONE;
384390
} else if (nready == 0)
385391
goto TAG_DONE;
386392

387-
for (i = 0; i < eventp->fdcnt; i++) {
393+
for (i = 0; i < fdcnt; i++) {
388394
fdp = acl_fdmap_ctx(event_thr->fdmap, event_thr->fdset[i].fd);
389395
if (fdp == NULL || fdp->stream == NULL)
390396
continue;

lib_acl/src/init/acl_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "init.h"
2626

27-
static char *version = "lib_acl_3.0.12";
27+
static char *version = "lib_acl_3.0.16";
2828

2929
const char *acl_version(void)
3030
{

0 commit comments

Comments
 (0)