lk中的threadlocal 变量

lk中提供了threadlocal 变量来保存和thread相关联的变量,在new thread的时候可以从父进程继承threadlocal变量
在thread结构体变量中是通过tls这个uint32的数组来保存threadlocal 变量的
typedef struct thread {

/* thread local storage */
uint32_t tls[MAX_TLS_ENTRY];


char name[32];
} thread_t;


可以通过tls_get 和 tls_set 来设置和取回threadlocal 变量
/* thread local storage */
static inline __ALWAYS_INLINE uint32_t tls_get(uint entry)
{
return current_thread->tls[entry];
}


static inline __ALWAYS_INLINE uint32_t tls_set(uint entry, uint32_t val)
{
uint32_t oldval = current_thread->tls[entry];
current_thread->tls[entry] = val;
return oldval;
}


在new thread的时候会从父进程继承threadlocal 变量
当我们电泳thread_create new 一个thread的时候会从父进程继承threadlocal变量


thread_t *thread_create(const char *name, thread_start_routine entry, void *arg, int priority, size_t stack_size)
{
/* inheirit thread local storage from the parent */
int i;
for (i=0; i < MAX_TLS_ENTRY; i++)
t->tls[i] = current_thread->tls[i];
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值