This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "skynet.h" | |
#include "skynet_monitor.h" | |
#include "skynet_server.h" | |
#include "skynet.h" | |
#include "atomic.h" | |
#include <stdlib.h> | |
#include <string.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SKYNET_RWLOCK_H | |
#define SKYNET_RWLOCK_H | |
#ifndef USE_PTHREAD_LOCK | |
struct rwlock { | |
int write;// 值为 1 则说明写被锁了 | |
int read; // 读锁的引用计数,不为 0 则说明有别人锁了读 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SKYNET_SPINLOCK_H | |
#define SKYNET_SPINLOCK_H | |
#define SPIN_INIT(q) spinlock_init(&(q)->lock); | |
#define SPIN_LOCK(q) spinlock_lock(&(q)->lock); | |
#define SPIN_UNLOCK(q) spinlock_unlock(&(q)->lock); | |
#define SPIN_DESTROY(q) spinlock_destroy(&(q)->lock); | |
#ifndef USE_PTHREAD_LOCK | |
//用到了gcc自带的原子操作函数实现了spinlock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct socket_server * | |
socket_server_create(uint64_t time) { | |
int i; | |
int fd[2]; | |
poll_fd efd = sp_create(); | |
if (sp_invalid(efd)) { | |
skynet_error(NULL, "socket-server: create event pool failed."); | |
return NULL; | |
} | |
if (pipe(fd)) {//建立管道 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) | |
const lu_byte luaP_opmodes[NUM_OPCODES] = { | |
/* T A B C mode opcode */ | |
opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ | |
,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ | |
,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ | |
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ | |
,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ | |
,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void * | |
thread_timer(void *p) { | |
struct monitor * m = p; | |
skynet_initthread(THREAD_TIMER); | |
for (;;) { | |
skynet_updatetime(); | |
skynet_socket_updatetime(); | |
CHECK_ABORT | |
wakeup(m,m->count-1); // 贪婪唤醒工作线程 | |
usleep(2500); // 睡眠 2.5 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Table *getcurrenv (lua_State *L) { | |
if (L->ci == L->base_ci) /* no enclosing function? *///如果该函数不是内嵌函数,那么直接返回G表 | |
return hvalue(gt(L)); /* use global table as environment */ | |
else {//再则,如果是内嵌函数,就返回其母函数的`env`表 | |
Closure *func = curr_func(L); | |
return func->c.env; | |
} | |
} | |
LUALIB_API int luaL_ref (lua_State *L, int t) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void stack_init (lua_State *L1, lua_State *L) { | |
/* initialize CallInfo array */ | |
L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); | |
L1->ci = L1->base_ci; | |
L1->size_ci = BASIC_CI_SIZE; | |
L1->end_ci = L1->base_ci + L1->size_ci - 1; | |
/* initialize stack array */ | |
L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); | |
L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; | |
L1->top = L1->stack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LUA_API lua_State *lua_newthread (lua_State *L) { | |
lua_State *L1; | |
lua_lock(L); | |
luaC_checkGC(L); | |
L1 = luaE_newthread(L); | |
setthvalue(L, L->top, L1); | |
api_incr_top(L); | |
lua_unlock(L); | |
luai_userstatethread(L, L1); | |
return L1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** basic types | |
*/ | |
#define LUA_TNONE (-1) | |
#define LUA_TNIL 0 | |
#define LUA_TBOOLEAN 1 | |
#define LUA_TLIGHTUSERDATA 2 //void * | |
#define LUA_TNUMBER 3 //lua3后采用double精度表示数字整型 | |
#define LUA_TSTRING 4 //TString |
NewerOlder