亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? os_unix.c

?? 調用sqlite開源數據的小程序
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*** 2004 May 22**** The author disclaims copyright to this source code.  In place of** a legal notice, here is a blessing:****    May you do good and not evil.**    May you find forgiveness for yourself and forgive others.**    May you share freely, never taking more than you give.************************************************************************************ This file contains code that is specific to Unix systems.*/#include "sqliteInt.h"#include "os.h"#if OS_UNIX              /* This file is used on unix only */#include <time.h>#include <sys/time.h>#include <errno.h>#include <unistd.h>/*** Do not include any of the File I/O interface procedures if the** SQLITE_OMIT_DISKIO macro is defined (indicating that there database** will be in-memory only)*/#ifndef SQLITE_OMIT_DISKIO/*** Define various macros that are missing from some systems.*/#ifndef O_LARGEFILE# define O_LARGEFILE 0#endif#ifdef SQLITE_DISABLE_LFS# undef O_LARGEFILE# define O_LARGEFILE 0#endif#ifndef O_NOFOLLOW# define O_NOFOLLOW 0#endif#ifndef O_BINARY# define O_BINARY 0#endif/*** The DJGPP compiler environment looks mostly like Unix, but it** lacks the fcntl() system call.  So redefine fcntl() to be something** that always succeeds.  This means that locking does not occur under** DJGPP.  But its DOS - what did you expect?*/#ifdef __DJGPP__# define fcntl(A,B,C) 0#endif/*** Include code that is common to all os_*.c files*/#include "os_common.h"/*** The threadid macro resolves to the thread-id or to 0.  Used for** testing and debugging only.*/#ifdef SQLITE_UNIX_THREADS#define threadid pthread_self()#else#define threadid 0#endif/*** Set or check the OsFile.tid field.  This field is set when an OsFile** is first opened.  All subsequent uses of the OsFile verify that the** same thread is operating on the OsFile.  Some operating systems do** not allow locks to be overridden by other threads and that restriction** means that sqlite3* database handles cannot be moved from one thread** to another.  This logic makes sure a user does not try to do that** by mistake.*/#ifdef SQLITE_UNIX_THREADS# define SET_THREADID(X)   X->tid = pthread_self()# define CHECK_THREADID(X) (!pthread_equal(X->tid, pthread_self()))#else# define SET_THREADID(X)# define CHECK_THREADID(X) 0#endif/*** Here is the dirt on POSIX advisory locks:  ANSI STD 1003.1 (1996)** section 6.5.2.2 lines 483 through 490 specify that when a process** sets or clears a lock, that operation overrides any prior locks set** by the same process.  It does not explicitly say so, but this implies** that it overrides locks set by the same process using a different** file descriptor.  Consider this test case:****       int fd1 = open("./file1", O_RDWR|O_CREAT, 0644);**       int fd2 = open("./file2", O_RDWR|O_CREAT, 0644);**** Suppose ./file1 and ./file2 are really the same file (because** one is a hard or symbolic link to the other) then if you set** an exclusive lock on fd1, then try to get an exclusive lock** on fd2, it works.  I would have expected the second lock to** fail since there was already a lock on the file due to fd1.** But not so.  Since both locks came from the same process, the** second overrides the first, even though they were on different** file descriptors opened on different file names.**** Bummer.  If you ask me, this is broken.  Badly broken.  It means** that we cannot use POSIX locks to synchronize file access among** competing threads of the same process.  POSIX locks will work fine** to synchronize access for threads in separate processes, but not** threads within the same process.**** To work around the problem, SQLite has to manage file locks internally** on its own.  Whenever a new database is opened, we have to find the** specific inode of the database file (the inode is determined by the** st_dev and st_ino fields of the stat structure that fstat() fills in)** and check for locks already existing on that inode.  When locks are** created or removed, we have to look at our own internal record of the** locks to see if another thread has previously set a lock on that same** inode.**** The OsFile structure for POSIX is no longer just an integer file** descriptor.  It is now a structure that holds the integer file** descriptor and a pointer to a structure that describes the internal** locks on the corresponding inode.  There is one locking structure** per inode, so if the same inode is opened twice, both OsFile structures** point to the same locking structure.  The locking structure keeps** a reference count (so we will know when to delete it) and a "cnt"** field that tells us its internal lock status.  cnt==0 means the** file is unlocked.  cnt==-1 means the file has an exclusive lock.** cnt>0 means there are cnt shared locks on the file.**** Any attempt to lock or unlock a file first checks the locking** structure.  The fcntl() system call is only invoked to set a ** POSIX lock if the internal lock structure transitions between** a locked and an unlocked state.**** 2004-Jan-11:** More recent discoveries about POSIX advisory locks.  (The more** I discover, the more I realize the a POSIX advisory locks are** an abomination.)**** If you close a file descriptor that points to a file that has locks,** all locks on that file that are owned by the current process are** released.  To work around this problem, each OsFile structure contains** a pointer to an openCnt structure.  There is one openCnt structure** per open inode, which means that multiple OsFiles can point to a single** openCnt.  When an attempt is made to close an OsFile, if there are** other OsFiles open on the same inode that are holding locks, the call** to close() the file descriptor is deferred until all of the locks clear.** The openCnt structure keeps a list of file descriptors that need to** be closed and that list is walked (and cleared) when the last lock** clears.**** First, under Linux threads, because each thread has a separate** process ID, lock operations in one thread do not override locks** to the same file in other threads.  Linux threads behave like** separate processes in this respect.  But, if you close a file** descriptor in linux threads, all locks are cleared, even locks** on other threads and even though the other threads have different** process IDs.  Linux threads is inconsistent in this respect.** (I'm beginning to think that linux threads is an abomination too.)** The consequence of this all is that the hash table for the lockInfo** structure has to include the process id as part of its key because** locks in different threads are treated as distinct.  But the ** openCnt structure should not include the process id in its** key because close() clears lock on all threads, not just the current** thread.  Were it not for this goofiness in linux threads, we could** combine the lockInfo and openCnt structures into a single structure.**** 2004-Jun-28:** On some versions of linux, threads can override each others locks.** On others not.  Sometimes you can change the behavior on the same** system by setting the LD_ASSUME_KERNEL environment variable.  The** POSIX standard is silent as to which behavior is correct, as far** as I can tell, so other versions of unix might show the same** inconsistency.  There is no little doubt in my mind that posix** advisory locks and linux threads are profoundly broken.**** To work around the inconsistencies, we have to test at runtime ** whether or not threads can override each others locks.  This test** is run once, the first time any lock is attempted.  A static ** variable is set to record the results of this test for future** use.*//*** An instance of the following structure serves as the key used** to locate a particular lockInfo structure given its inode.**** If threads cannot override each others locks, then we set the** lockKey.tid field to the thread ID.  If threads can override** each others locks then tid is always set to zero.  tid is also** set to zero if we compile without threading support.*/struct lockKey {  dev_t dev;       /* Device number */  ino_t ino;       /* Inode number */#ifdef SQLITE_UNIX_THREADS  pthread_t tid;   /* Thread ID or zero if threads cannot override each other */#endif};/*** An instance of the following structure is allocated for each open** inode on each thread with a different process ID.  (Threads have** different process IDs on linux, but not on most other unixes.)**** A single inode can have multiple file descriptors, so each OsFile** structure contains a pointer to an instance of this object and this** object keeps a count of the number of OsFiles pointing to it.*/struct lockInfo {  struct lockKey key;  /* The lookup key */  int cnt;             /* Number of SHARED locks held */  int locktype;        /* One of SHARED_LOCK, RESERVED_LOCK etc. */  int nRef;            /* Number of pointers to this structure */};/*** An instance of the following structure serves as the key used** to locate a particular openCnt structure given its inode.  This** is the same as the lockKey except that the thread ID is omitted.*/struct openKey {  dev_t dev;   /* Device number */  ino_t ino;   /* Inode number */};/*** An instance of the following structure is allocated for each open** inode.  This structure keeps track of the number of locks on that** inode.  If a close is attempted against an inode that is holding** locks, the close is deferred until all locks clear by adding the** file descriptor to be closed to the pending list.*/struct openCnt {  struct openKey key;   /* The lookup key */  int nRef;             /* Number of pointers to this structure */  int nLock;            /* Number of outstanding locks */  int nPending;         /* Number of pending close() operations */  int *aPending;        /* Malloced space holding fd's awaiting a close() */};/* ** These hash table maps inodes and process IDs into lockInfo and openCnt** structures.  Access to these hash tables must be protected by a mutex.*/static Hash lockHash = { SQLITE_HASH_BINARY, 0, 0, 0, 0, 0 };static Hash openHash = { SQLITE_HASH_BINARY, 0, 0, 0, 0, 0 };#ifdef SQLITE_UNIX_THREADS/*** This variable records whether or not threads can override each others** locks.****    0:  No.  Threads cannot override each others locks.**    1:  Yes.  Threads can override each others locks.**   -1:  We don't know yet.*/static int threadsOverrideEachOthersLocks = -1;/*** This structure holds information passed into individual test** threads by the testThreadLockingBehavior() routine.*/struct threadTestData {  int fd;                /* File to be locked */  struct flock lock;     /* The locking operation */  int result;            /* Result of the locking operation */};#ifdef SQLITE_LOCK_TRACE/*** Print out information about all locking operations.**** This routine is used for troubleshooting locks on multithreaded** platforms.  Enable by compiling with the -DSQLITE_LOCK_TRACE** command-line option on the compiler.  This code is normally** turnned off.*/static int lockTrace(int fd, int op, struct flock *p){  char *zOpName, *zType;  int s;  int savedErrno;  if( op==F_GETLK ){    zOpName = "GETLK";  }else if( op==F_SETLK ){    zOpName = "SETLK";  }else{    s = fcntl(fd, op, p);    sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);    return s;  }  if( p->l_type==F_RDLCK ){    zType = "RDLCK";  }else if( p->l_type==F_WRLCK ){    zType = "WRLCK";  }else if( p->l_type==F_UNLCK ){    zType = "UNLCK";  }else{    assert( 0 );  }  assert( p->l_whence==SEEK_SET );  s = fcntl(fd, op, p);  savedErrno = errno;  sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",     threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,     (int)p->l_pid, s);  if( s && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){    struct flock l2;    l2 = *p;    fcntl(fd, F_GETLK, &l2);    if( l2.l_type==F_RDLCK ){      zType = "RDLCK";    }else if( l2.l_type==F_WRLCK ){      zType = "WRLCK";    }else if( l2.l_type==F_UNLCK ){      zType = "UNLCK";    }else{      assert( 0 );    }    sqlite3DebugPrintf("fcntl-failure-reason: %s %d %d %d\n",       zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid);  }  errno = savedErrno;  return s;}#define fcntl lockTrace#endif /* SQLITE_LOCK_TRACE *//*** The testThreadLockingBehavior() routine launches two separate** threads on this routine.  This routine attempts to lock a file** descriptor then returns.  The success or failure of that attempt** allows the testThreadLockingBehavior() procedure to determine** whether or not threads can override each others locks.*/static void *threadLockingTest(void *pArg){  struct threadTestData *pData = (struct threadTestData*)pArg;  pData->result = fcntl(pData->fd, F_SETLK, &pData->lock);  return pArg;}/*** This procedure attempts to determine whether or not threads** can override each others locks then sets the ** threadsOverrideEachOthersLocks variable appropriately.*/static void testThreadLockingBehavior(fd_orig){  int fd;  struct threadTestData d[2];  pthread_t t[2];  fd = dup(fd_orig);  if( fd<0 ) return;  memset(d, 0, sizeof(d));  d[0].fd = fd;  d[0].lock.l_type = F_RDLCK;  d[0].lock.l_len = 1;  d[0].lock.l_start = 0;  d[0].lock.l_whence = SEEK_SET;  d[1] = d[0];  d[1].lock.l_type = F_WRLCK;  pthread_create(&t[0], 0, threadLockingTest, &d[0]);  pthread_create(&t[1], 0, threadLockingTest, &d[1]);  pthread_join(t[0], 0);  pthread_join(t[1], 0);  close(fd);  threadsOverrideEachOthersLocks =  d[0].result==0 && d[1].result==0;}#endif /* SQLITE_UNIX_THREADS *//*** Release a lockInfo structure previously allocated by findLockInfo().*/static void releaseLockInfo(struct lockInfo *pLock){  pLock->nRef--;  if( pLock->nRef==0 ){    sqlite3HashInsert(&lockHash, &pLock->key, sizeof(pLock->key), 0);    sqliteFree(pLock);  }}/*** Release a openCnt structure previously allocated by findLockInfo().*/static void releaseOpenCnt(struct openCnt *pOpen){  pOpen->nRef--;  if( pOpen->nRef==0 ){    sqlite3HashInsert(&openHash, &pOpen->key, sizeof(pOpen->key), 0);    sqliteFree(pOpen->aPending);    sqliteFree(pOpen);  }}/*** Given a file descriptor, locate lockInfo and openCnt structures that** describes that file descriptor.  Create a new ones if necessary.  The** return values might be unset if an error occurs.**** Return the number of errors.*/static int findLockInfo(  int fd,                      /* The file descriptor used in the key */  struct lockInfo **ppLock,    /* Return the lockInfo structure here */  struct openCnt **ppOpen      /* Return the openCnt structure here */){  int rc;  struct lockKey key1;  struct openKey key2;  struct stat statbuf;  struct lockInfo *pLock;  struct openCnt *pOpen;  rc = fstat(fd, &statbuf);  if( rc!=0 ) return 1;  memset(&key1, 0, sizeof(key1));  key1.dev = statbuf.st_dev;  key1.ino = statbuf.st_ino;#ifdef SQLITE_UNIX_THREADS  if( threadsOverrideEachOthersLocks<0 ){    testThreadLockingBehavior(fd);  }  key1.tid = threadsOverrideEachOthersLocks ? 0 : pthread_self();#endif  memset(&key2, 0, sizeof(key2));  key2.dev = statbuf.st_dev;  key2.ino = statbuf.st_ino;  pLock = (struct lockInfo*)sqlite3HashFind(&lockHash, &key1, sizeof(key1));  if( pLock==0 ){    struct lockInfo *pOld;    pLock = sqliteMallocRaw( sizeof(*pLock) );    if( pLock==0 ) return 1;    pLock->key = key1;    pLock->nRef = 1;    pLock->cnt = 0;    pLock->locktype = 0;    pOld = sqlite3HashInsert(&lockHash, &pLock->key, sizeof(key1), pLock);    if( pOld!=0 ){      assert( pOld==pLock );      sqliteFree(pLock);      return 1;    }  }else{    pLock->nRef++;  }  *ppLock = pLock;  pOpen = (struct openCnt*)sqlite3HashFind(&openHash, &key2, sizeof(key2));  if( pOpen==0 ){    struct openCnt *pOld;    pOpen = sqliteMallocRaw( sizeof(*pOpen) );    if( pOpen==0 ){      releaseLockInfo(pLock);      return 1;    }    pOpen->key = key2;    pOpen->nRef = 1;    pOpen->nLock = 0;    pOpen->nPending = 0;    pOpen->aPending = 0;    pOld = sqlite3HashInsert(&openHash, &pOpen->key, sizeof(key2), pOpen);    if( pOld!=0 ){      assert( pOld==pOpen );      sqliteFree(pOpen);      releaseLockInfo(pLock);      return 1;    }  }else{    pOpen->nRef++;  }  *ppOpen = pOpen;  return 0;}/*** Delete the named file*/int sqlite3OsDelete(const char *zFilename){  unlink(zFilename);  return SQLITE_OK;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久国际精品| 强制捆绑调教一区二区| 国产99精品在线观看| 日韩午夜电影av| 婷婷丁香激情综合| 欧美日韩一区二区三区在线| 中文字幕亚洲综合久久菠萝蜜| 国产乱子轮精品视频| 日韩欧美国产一区二区三区| 免费在线观看视频一区| 欧美一区二区三区在| 美女视频黄免费的久久| 日韩精品一区国产麻豆| 亚洲国产一区二区在线播放| 欧美午夜寂寞影院| 亚洲18女电影在线观看| 911精品国产一区二区在线| 五月综合激情婷婷六月色窝| 777午夜精品免费视频| 尤物在线观看一区| 欧美日韩成人高清| 麻豆91在线看| 久久综合色一综合色88| 国产成人精品一区二区三区网站观看| 日本一区二区三区视频视频| 成人中文字幕合集| 亚洲色图.com| 欧美偷拍一区二区| 奇米精品一区二区三区四区| 精品国产凹凸成av人导航| 国产乱色国产精品免费视频| 最新不卡av在线| 欧美日韩免费一区二区三区视频 | 成人性生交大片免费看中文| 亚洲国产精品激情在线观看| 在线日韩国产精品| 免费成人美女在线观看| 久久久国产精品麻豆| 91视视频在线观看入口直接观看www| 一区二区三区四区在线免费观看| 7777精品久久久大香线蕉| 国产又黄又大久久| 一区二区久久久久| 日韩欧美成人一区二区| 高清av一区二区| 午夜久久久影院| 国产欧美精品区一区二区三区| 91美女片黄在线观看91美女| 秋霞午夜av一区二区三区| 中文字幕国产精品一区二区| 欧美亚洲国产一区在线观看网站| 久久99深爱久久99精品| 亚洲免费av观看| 欧美色图免费看| 国产aⅴ综合色| 欧美a一区二区| 中文字幕在线不卡一区| 91精品啪在线观看国产60岁| 国产成都精品91一区二区三| 日韩av一二三| 亚洲三级在线免费观看| 精品国产a毛片| 欧美视频一区二区| 国产91清纯白嫩初高中在线观看| 亚洲小说欧美激情另类| 中文字幕成人网| 日韩欧美一区在线观看| 一本到不卡精品视频在线观看| 久久成人免费网| 亚洲成人精品影院| 国产精品嫩草影院av蜜臀| 日韩欧美国产不卡| 欧美日韩一二三区| www.日韩精品| 国产黄色精品网站| 激情综合五月天| 五月激情六月综合| 亚洲伦理在线精品| 精品久久久久久久一区二区蜜臀| 欧美色图激情小说| 欧洲一区在线电影| 色综合久久天天综合网| 成人爱爱电影网址| 精品一区二区三区的国产在线播放| 亚洲福利视频三区| 亚洲韩国一区二区三区| 一色桃子久久精品亚洲| 中文字幕不卡的av| 久久影院电视剧免费观看| 日韩免费高清av| 欧美一区二区精品久久911| 欧美午夜影院一区| 欧美三区在线视频| 欧美在线视频日韩| 日本高清不卡aⅴ免费网站| av电影在线观看一区| 成人午夜免费视频| 成人午夜电影久久影院| 国产91精品一区二区麻豆网站| 国产精一区二区三区| 国产麻豆视频一区| 国产suv一区二区三区88区| 国产91丝袜在线播放| 成人av高清在线| av成人免费在线观看| 9久草视频在线视频精品| 在线视频一区二区三| 国产麻豆9l精品三级站| 国产超碰在线一区| 97精品国产97久久久久久久久久久久| 成人高清视频免费观看| 91视频精品在这里| a4yy欧美一区二区三区| 在线免费观看不卡av| 99在线热播精品免费| 日本韩国欧美在线| 久久丝袜美腿综合| 亚洲一区二区三区精品在线| 久久国产日韩欧美精品| 99re亚洲国产精品| 欧美一区二区观看视频| 国产精品―色哟哟| 日本va欧美va精品发布| 波多野结衣中文字幕一区| 欧美美女直播网站| 久久久久久免费网| 婷婷一区二区三区| 91在线观看视频| 久久先锋资源网| 丝袜亚洲另类丝袜在线| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 日日欢夜夜爽一区| 成人福利在线看| 精品国产123| 婷婷国产v国产偷v亚洲高清| 91天堂素人约啪| 久久久久久99精品| 美国欧美日韩国产在线播放| 在线观看不卡视频| 综合久久久久久久| 国产精品夜夜嗨| 日韩三区在线观看| 亚洲成人免费av| 色婷婷亚洲精品| 国产精品视频一二三区 | 精品久久久久久久久久久久久久久 | 国产一区二区三区香蕉| 91高清视频免费看| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 国产成人综合网| 在线成人av网站| 亚洲自拍偷拍九九九| 99re这里只有精品首页| 国产精品蜜臀av| 国产精品99久久久久久久女警| 日韩精品中午字幕| 日韩av电影免费观看高清完整版| 色一情一乱一乱一91av| 国产精品灌醉下药二区| 国产成人av一区二区三区在线| 精品国产91洋老外米糕| 精品写真视频在线观看| 欧美一级免费观看| 日本91福利区| 欧美大肚乱孕交hd孕妇| 久久99久久精品欧美| 日韩精品一区在线| 精品一区二区影视| 精品国产髙清在线看国产毛片| 麻豆中文一区二区| 日韩女同互慰一区二区| 六月丁香婷婷久久| 日韩欧美国产综合| 国产一区二区日韩精品| 久久久.com| 成人黄色电影在线| 综合久久一区二区三区| 在线观看日产精品| 日韩成人dvd| 精品国产免费人成电影在线观看四季| 毛片av中文字幕一区二区| 精品国产污网站| 成人激情视频网站| 一区二区三区国产| 欧美日韩不卡在线| 紧缚奴在线一区二区三区| 国产精品乱人伦| 欧美性欧美巨大黑白大战| 日本欧美一区二区在线观看| 欧美va亚洲va| a级高清视频欧美日韩| 夜夜嗨av一区二区三区| 一区二区视频在线| 欧美色偷偷大香| 极品少妇一区二区三区精品视频| 欧美激情综合在线| 欧美丝袜自拍制服另类| 激情文学综合丁香| 亚洲精品欧美综合四区| 日韩小视频在线观看专区|