Skynet源码赏析一 | 启动初始化的过程
入口文件
skynet_main.c
加载配置
struct skynet_config config;
config.thread = optint("thread",8);
config.module_path = optstring("cpath","./cservice/?.so");
config.harbor = optint("harbor", 1);
config.bootstrap = optstring("bootstrap","snlua bootstrap");
config.daemon = optstring("daemon", NULL);
config.logger = optstring("logger", NULL);
config.logservice = optstring("logservice", "logger");
config.profile = optboolean("profile", 1);
从上述代码可以看到,配置都已经加载到变量struct skynet_config config;中了。
初始化
- 初始化
skynet_context管理模块,skynet_handle_init(config->harbor);; - 初始化
static struct global_queue *Q消息队列,skynet_mq_init();; - 初始化
static struct modules * M管理模块,skynet_module_init(config->module_path);; - 初始化定时器,
skynet_timer_init();;
启动C服务
- 启动
logger日志服务,struct skynet_context *ctx = skynet_context_new(config->logservice, config->logger);; - 启动
snlua服务, ``; - 通过
snlua服务启动boostrap服务,bootstrap(ctx, config->bootstrap);; - 启动线程:
- 监听线程,检测线程是否阻塞。
create_thread(&pid[0], thread_monitor, m);; - 启动定时器线程。
create_thread(&pid[1], thread_timer, m);; - 启动
socket线程。create_thread(&pid[2], thread_socket, m); - 启动工作线程,用于lua服务消息的调度。
create_thread(&pid[i+3], thread_worker, &wp[i]);;
启动lua服务
默认启动的lua服务,在boostrap.lua文件中可以看到都是通过snlua服务启动的。
- 启动
launch服务。 - 启动
cdummy - 启动
cmaster - 启动
cslave - …
总结
本文简单讲述了skynet的启动流程,使用了那些数据结构,以及启了那些C服务和lua服务。后续将会讲解这些基础的数据结构和怎么启动C服务和lua服务。
--完--
- 原文作者: 留白
- 原文链接: https://zfunnily.github.io/2021/10/skynetone/
- 更新时间:2024-04-16 01:01:05
- 本文声明:转载请标记原文作者及链接