在使用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)
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只调用了下面函数来完成线程的初始化:
- 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;
- }
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
增加某一特定信号的处理函数