DirectFB源代码阅读(三)线程及信号初始化

在使用DirectFB创建一个程序的时候,要执行两个初始化函数,上一篇文章讲了第一个DirectFBInit,下面几篇讲第二个DirectFBCreate.

DirectFBCreate主要调用了三个函数:

1.direct_initialize:线程及信号初始化

2.dfb_core_create:各个子系统的初始化

3.IDirectFB_Construct:构造一个IDirectFB对象

线程thread.c

先介绍几个下面用到的线程的知识:
1.TSD(Thread Specific Data)的创建与注销:
int pthread_key_create(pthread_key_t *key, void (*destr_function) (void *))
int pthread_key_delete(pthread_key_t key)
2.为每个应用线程提供对一个唯一的对象,访问自己用key定义的绑定数据:
int pthread_setspecific(pthread_key_t key, const void *pointer)
void * pthread_getspecific(pthread_key_t key)

3.int pthread_join __P (pthread _t __th, void **__thread_return);
用来等待一个线程的结束,使用此函数对创建的线程进行资源回收
4. pthread_detach( thread->thread );
使线成分离出来。当这个线程执行完成任务后释放释放资源。不然它会保留退出状态,等待pthread_join来取。
5pthread_create创建线程
direct_initalize只调用了下面函数来完成线程的初始化:
  1. void direct_thread_set_name( const char *name )  
  2. {  
  3.      DirectThread *thread = pthread_getspecific( thread_key );//得到thread_key绑定的数据   
  4.      if (!thread) {  
  5.           if (thread_key == -1)  
  6.                pthread_key_create( &thread_key, NULL );//创建一个类型为 pthread_key_t类型的变量   
  7.   
  8.           thread = D_CALLOC( 1, sizeof(DirectThread) );  
  9.   
  10.           thread->thread = pthread_self();  
  11.           thread->tid    = direct_gettid();  
  12.   
  13.           D_MAGIC_SET( thread, DirectThread );  
  14.   
  15.           pthread_setspecific( thread_key, thread );//保存要绑定的数据   
  16.      }  
  17.      copy = D_STRDUP( name );  
  18.      thread->name = copy;  
  19. }  
void direct_thread_set_name( const char *name )
{
     DirectThread *thread = pthread_getspecific( thread_key );//得到thread_key绑定的数据
     if (!thread) {
          if (thread_key == -1)
               pthread_key_create( &thread_key, NULL );//创建一个类型为 pthread_key_t类型的变量

          thread = D_CALLOC( 1, sizeof(DirectThread) );

          thread->thread = pthread_self();
          thread->tid    = direct_gettid();

          D_MAGIC_SET( thread, DirectThread );

          pthread_setspecific( thread_key, thread );//保存要绑定的数据
     }
     copy = D_STRDUP( name );
     thread->name = copy;
}
还有几个主要的函数:
1.direct_thread_add_init_handler,注册需要线程处理的函数
2.direct_thread_create,主要是调用pthread_creat创建线程
3.direct_thread_main执行前面注册的函数

信号初始化signals.c

DirectFB默认初始化了一系列的处理引起程序退出的信号的处理函数.在程序退出之前这些信号处理函数将重新初始化DirectFB引擎.
主要函数有:
1. install_handlers( void )
信号初始化
2.signal_handler( int num )
处理这一特定的信号
3.direct_signal_handler_add
增加某一特定信号的处理函数
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值