欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SQLITE源码剖析(8)

程序员文章站 2022-03-02 16:28:13
...

声明:本SQLite源码剖析系列为刘兴(http://deepfuture.iteye.com/)原创,未经笔者授权,任何人和机构不能转载

/*库线程安全

** CAPI3REF: Test To See If The Library Is Threadsafe

**SQLITE_THREADSAFE预处理宏编译时选项设为0,则忽略SQLITE的互斥代码,

**此时,sqlite3_threadsafe()返回0

** ^The sqlite3_threadsafe() function returns zero if and only if

** SQLite was compiled mutexing code omitted due to the

** [SQLITE_THREADSAFE] compile-time option being set to 0.

**SQLITE可在有互斥和没有互斥情况下编译,当SQLITE_THREADSAFE宏是1或2**时,互斥被允许,SQLITE是线程安全的。该宏为0时,不使用互斥,超过一

**个线程同时使用SQLite是不安全的

** SQLite can be compiled with or without mutexes.  When

** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes

** are enabled and SQLite is threadsafe.  When the

** [SQLITE_THREADSAFE] macro is 0, 

** the mutexes are omitted.  Without the mutexes, it is not safe

** to use SQLite concurrently from more than one thread.

**允许互斥,将会产生一些可预见的后果。如果速度是第一位的,最好是禁止

**互斥,对于最好安全性而言,互斥要开启,默认的行为是互斥开启。

** Enabling mutexes incurs a measurable performance penalty.

** So if speed is of utmost importance, it makes sense to disable

** the mutexes.  But for maximum safety, mutexes should be enabled.

** ^The default behavior is for mutexes to be enabled.

**这些接口被应用程序使用,确认该SQLITE版本编译链接时是否使用

**sqlite_threadsafe宏

** This interface can be used by an application to make sure that the

** version of SQLite that it is linking against was compiled with

** the desired setting of the [SQLITE_THREADSAFE] macro.

**该接口仅在编译时,互斥设置了SQLITE_THREADSAFE标志时才报告,如

**果 SQLITE使用SQLITE_THREADSAFE=1或=2的方式编译,互斥被允许,但

**通过SQLITE_CONFIG_SINGLETHREAD、SQLITE_CONFIG_MULTITHREAD能部分或

**完全禁止对sqlite3_config()的调用,

** This interface only reports on the compile-time mutex setting

** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with

** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but

** can be fully or partially disabled using a call to [sqlite3_config()]

** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],

** or [SQLITE_CONFIG_MUTEX].  

**sqlite3_threadsafe()函数的返回值仅指示编译时设置了线程安全

**不能被sqlite3_config()可在运行时改变

**^(The return value of the

** sqlite3_threadsafe() function shows only the compile-time setting of

** thread safety, not any run-time changes to that setting made by

** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()

** is unchanged by calls to sqlite3_config().)^

**调用sqlite3_config()不能改变sqlite3_threadsafe()返回值,

** See the [threading mode] documentation for additional information.

*/

SQLITE_API int sqlite3_threadsafe(void);

 

/*数据库连接句柄

** CAPI3REF: Database Connection Handle

** KEYWORDS: {database connection} {database connections}

**关键字:{database connection} {database connections}

**每个打开的SQLite数据库做为一个指针出现,该指针指向隐藏的sqlite3

**结构的实例,建议将sqlite3指针视 为对象 ,

**sqlite3_open()、sqlite3_open16()、sqlite3_open_v2()接口是这该对象

**的构造器,sqlite3_close()是析构器。

** Each open SQLite database is represented by a pointer to an instance of

** the opaque structure named "sqlite3".  It is useful to think of an sqlite3

** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and

** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]

** is its destructor.  

**还有一些其它接口sqlite3_prepare_v2()、sqlite3_create_function()、

**sqlite3_busy_timeout()为sqlite3 对象 的方法 

There are many other interfaces (such as

** [sqlite3_prepare_v2()], [sqlite3_create_function()], and

** [sqlite3_busy_timeout()] to name but three) that are methods on an

** sqlite3 object.

*/

typedef struct sqlite3 sqlite3;