/*----------------------------------------------------------------------------*/ static void __read_notify_callback(int event_type, ACL_IOCTL *h_ioctl, ACL_VSTREAM *cstream, void *context) { const char *myname = "__read_notify_callback"; ACL_APP_HANDLE *app; int ret; app = (ACL_APP_HANDLE *) context; switch (event_type) { case ACL_EVENT_READ: ret = __run_fn(cstream, __run_ctx); if (ret < 0) { if (__app_on_close != NULL) __app_on_close(cstream, __run_ctx); acl_vstream_close(cstream); } else if (ret == 0) { if (acl_msg_verbose) acl_msg_info("enable(%s), fd=%d, h_ioctl(%p)", myname, ACL_VSTREAM_SOCK(cstream), (void*) h_ioctl); acl_ioctl_enable_read(h_ioctl, cstream, acl_var_ioctl_rw_timeout, __read_notify_callback, (void *) app); } break; case ACL_EVENT_RW_TIMEOUT: if (__app_on_timeout == NULL) { if (__app_on_close != NULL) __app_on_close(cstream, __run_ctx); acl_vstream_close(cstream); } else if (__app_on_timeout(cstream, __run_ctx) < 0) { if (__app_on_close != NULL) __app_on_close(cstream, __run_ctx); acl_vstream_close(cstream); } else { acl_ioctl_enable_read(h_ioctl, cstream, acl_var_ioctl_rw_timeout, __read_notify_callback, (void *) app); } break; case ACL_EVENT_XCPT: if (__app_on_close != NULL) __app_on_close(cstream, __run_ctx); acl_vstream_close(cstream); break; default: acl_msg_fatal("%s, %s(%d): unknown event type(%d)", __FILE__, myname, __LINE__, event_type); /* not reached */ break; } if (acl_msg_verbose) acl_msg_info("%s(%d): total alloc: %d", myname, __LINE__, acl_mempool_total_allocated()); }
static void mempool_bench_test2(const char *label, int use_pool, int mutex, int loop, int size) { char *buf; time_t begin, end; int i; static int __pool_inited = 0; if (use_pool) { if (__pool_inited == 0) { acl_mempool_open(__max_size, mutex); __pool_inited = 1; } else { acl_mempool_ctl(ACL_MEMPOOL_CTL_MUTEX, mutex, ACL_MEMPOOL_CTL_END); } i = 0; time(&begin); while (i++ < loop) { buf = MALLOC(size); FREE(buf); } time(&end); } else { acl_pthread_mutex_t lock; if (mutex) acl_pthread_mutex_init(&lock, NULL); if (__pool_inited) { acl_mempool_ctl(ACL_MEMPOOL_CTL_DISABLE, 1, ACL_MEMPOOL_CTL_END); } i = 0; time(&begin); while (i++ < loop) { buf = MALLOC(size); FREE(buf); } time(&end); if (mutex) acl_pthread_mutex_destroy(&lock); } if (use_pool) printf("%s: time cost is %ld seconds, count is %d, total pool alloc %d\r\n", label, (long int) end - begin, loop, acl_mempool_total_allocated()); else printf("%s: time cost is %ld seconds, count is %d\r\n", label, (long int) end - begin, loop); }