gobject初探

目前最新的glib版本为glib-2.28.8
首先第一层目录里大多数都是编译相关的文件,包括README等说明文件
共有以下文件夹:
build   windows支持的一些东西
docs    文档
gio     
glib
gmodule
gobject
gthread
m2macros m4的文件,应该也是编译相关的
po      多语言支持的文件
tests   测试用的文件
这里面有一些有的没得文件夹,剩下的五个文件夹是我们最为关心的:
gio/glib/gmodule/gobject/gthread
那么首先看一下这五个文件夹里面的代码量
发现gthread和gobject包括gmodule都不是很多的文件

而glib和gio的文件都有很多。因此考虑先分析简单的文件夹然后再分析复杂的文件夹。


首先看一下目录结构
只有两层,里面这层还是个tests文件夹
看看顶层的文件,基本上都是没什么用的:
ChangleLog      变更记录
gthread.def
gthread.rc      应该是配置文件,不知道谁用的
gthread.rc.in   跟rc文件配套的文件吧
gthread-impl.c
gthread-none.c
gthread-posix.c
gthread_win32.c
Makefile.am     编译相关的文件
Makefile.in     编译相关的文件
makefile.msc    windows下编译相关的文件吧
makefile.msc.in 和makefile.msc相关的文件


找到重点文件:
gthread.def
gthread-impl.c
gthread-none.c
gthread-posix.c
gthread-win32.c


gthread.def文件里只是导出了两个符号,或者说两个函数~
EXPORTS
g_thread_init
g_thread_init_with_errorcheck_mutexes
一个是线程初始化,另一个是带互斥锁的错误检查的线程初始化~~


ghtread-impl.c是线程的实现函数,线程功能通过宏G_THEADS_ENABLED来进行开关控制的。
这个函数里面当然是实现了g_thread_init和g_thead_init_with_errorcheck_mutexes这两个函数了。
也有好多其他的函数,用到的头文件有config.h/glib.h/gthreadprivate.h


gthread-none.c里只是写了
static GThreadFunctions
g_thread_fucntions_for_glib_use_default;
static guint64(*g_thread_gettime_impl)(void) = NULL;


gthread-posix.c里面就很多代码了,使用了pthread.h,应该说是实现了posix标准的gthread.


同理gthread-win32.c是windows平台的实现,不过我看不懂那些代码。


下面看看tests文件夹里有什么
Makefile.am和Makefile.in都是编译相关的
1bit-mutex.c 一位的互斥锁,还不知道具体干吗用的
642026.c 是一个关于大数据迭代的测试,看样子是创建很多的线程看看会不会出问题

gmodule里面的东西也是比较少的
主要代码无关的我们就先不看了
主要的是下面几个文件
gmodule.c
gmodule.h
gmodule-ar.c
gmodule-beos.c
gmodule-dl.c
gmodule-dld.c
gmodule-dyld.c
gmodule-os2.c
gmodule-win32.c


后面的7个文件都是实现的不同平台的相关的代码,最主要的gmodule的代码只有开始的.c/.h文件


gmodule用到了glib.h
定义了G_MODULE_IMPORT为extern


定义了一个枚举体
typdef enum
{
    G_MODULE_BIND_LAZY  = 1 << 0,
    G_MODULE_BIND_LOCAL = 1 << 1,
    G_MODULE_BIND_MASK  = 0x03
}GModuleFlags;


然后头文件里声明了8个函数:
gboolean g_module_supported(void)G_GNUC_CONST;
GModule* g_module_open(const gchar *file_name, GMduleFlags flags);
gboolean g_module_close(GModule *module);
void g_module_make_resident(GModule *module);
G_CONST_RETURN gchar *g_module_error (void);
gboolean g_module_symbol(GModule *module, const gchar *symbol_name, gpointer *symbol);
G_CONST_RETURN gchar* g_module_name (GModule *module);
gchar *g_module_build_path(const gchar *directory, const gchar *module_name);


gmodule.c中则包含了config.h/glib.h/gmodule.h/gmoduleconf.h/gstdio.h这几个头文件


定义了一个模块相关的结构体
struct _GModule
{
    gchar *file_name;
    #if defined (G_OS_WIN32)&&!defined(_WIN64)
    gchar *cp_file_name;
    #endif
    gpointer handle;
    guint ref_count:31;
    guint is_resident:1;
    GModuleUnload unload;
    GModule *next;
};


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值