Jun

Results 164 comments of Jun

## 创建 ```c // 5.0.3/src/ziplist.c /* Create a new empty ziplist. */ unsigned char *ziplistNew(void) { unsigned int bytes = ZIPLIST_HEADER_SIZE+1; unsigned char *zl = zmalloc(bytes); ZIPLIST_BYTES(zl) = intrev32ifbe(bytes); ZIPLIST_TAIL_OFFSET(zl)...

## 获取 ```c // 5.0.3/src/ziplist.c /* Return the total number of bytes used by the entry pointed to by 'p'. */ unsigned int zipRawEntryLength(unsigned char *p) { unsigned int prevlensize,...

## 查找 ```c // 5.0.3/src/ziplist.c /* Find pointer to the entry equal to the specified entry. Skip 'skip' entries * between every comparison. Returns NULL when the field could not...

## 插入 ```c // 5.0.3/src/ziplist.c /* Insert an entry at "p". */ unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen) { return __ziplistInsert(zl,p,s,slen); }...

## 连锁更新 ```c // 5.0.3/src/ziplist.c /* When an entry is inserted, we need to set the prevlen field of the next * entry to equal the length of the inserted...

## Handlers > Identify resources that are managed by an OS. handler 可以是打开的文件、一个连接(Socket)、Timer 等。这些 handler 可以被用在 `Synchronous Event Demultiplexer`中,以监听 handler 中发生的事件。 Redis 支持两种 handler,文件描述符和计时器,对应文件事件和时间事件。 ```c // 5.0 src/ae.h /* File...

## Synchronous Event Demultiplexer > Blocks awaiting events to occur on a set of Handles. 阻塞等待事件一般使用 I/O 多路复用技术实现,I/O 多路复用允许我们同时检查多个文件描述符上的 I/O 就绪状态。 不同平台有自己实现的 I/O 多路复用, - ae_epoll.c:Linux 平台 - ae_kqueue.c:BSD 平台...

## Initiation Dispatcher > Defines an interface for registering, removing, and dispatching Event Handlers. aeCreateEventLoop 创建并初始化事件循环实例。 ```c // 5.0 src/ae.c aeEventLoop *aeCreateEventLoop(int setsize) { aeEventLoop *eventLoop; int i; if ((eventLoop...

## Event Handler > Specifies an interface consisting of a hook method that abstractly represents the dispatching operation for service-specific events. Redis 的文件事件和时间事件的事件处理器定义: ```c // 5.0 src/ae.h typedef void aeFileProc(struct...

# 0x00 初始化运行环境 通过`_Py_InitializeCore`来初始化Python的运行环境,定义在 **Python/pylifecycle.c** ```c /* Begin interpreter initialization * * On return, the first thread and interpreter state have been created, * but the compiler, signal handling, multithreading...