aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authorchw <chw@noemail.net>2009-04-07 05:35:03 +0000
committerchw <chw@noemail.net>2009-04-07 05:35:03 +0000
commit78a1318b2e6a1a1713df0b1ecda3a26e59af9b33 (patch)
tree2795c62b6225f2f80dca3dcf09cf52e060023431 /src/os_unix.c
parent1086172f7dbc4806089caccbeaaa019302d94114 (diff)
downloadsqlite-78a1318b2e6a1a1713df0b1ecda3a26e59af9b33.tar.gz
sqlite-78a1318b2e6a1a1713df0b1ecda3a26e59af9b33.zip
Compile fixes and improvements for vxwork: fixed deadlock in semClose,
detect if fcntl is usable, fall back to named semaphores if not. (CVS 6460) FossilOrigin-Name: efd0682b7e78acc4242cf257fc246350fc29b5c8
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 75f595326..8776acaa5 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -43,7 +43,7 @@
** * Definitions of sqlite3_vfs objects for all locking methods
** plus implementations of sqlite3_os_init() and sqlite3_os_end().
**
-** $Id: os_unix.c,v 1.249 2009/04/07 00:35:20 drh Exp $
+** $Id: os_unix.c,v 1.250 2009/04/07 05:35:04 chw Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_UNIX /* This file is used on unix only */
@@ -2213,8 +2213,8 @@ static int semClose(sqlite3_file *id) {
unixEnterMutex();
releaseLockInfo(pFile->pLock);
releaseOpenCnt(pFile->pOpen);
- closeUnixFile(id);
unixLeaveMutex();
+ closeUnixFile(id);
}
return SQLITE_OK;
}
@@ -3207,7 +3207,7 @@ IOMETHODS(
dotlockCheckReservedLock /* xCheckReservedLock method */
)
-#if SQLITE_ENABLE_LOCKING_STYLE
+#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
IOMETHODS(
flockIoFinder, /* Finder function name */
flockIoMethods, /* sqlite3_io_methods object name */
@@ -3331,6 +3331,44 @@ static const sqlite3_io_methods *(*const autolockIoFinder)(const char*,int)
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
+#if OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE
+/*
+** This "finder" function attempts to determine the best locking strategy
+** for the database file "filePath". It then returns the sqlite3_io_methods
+** object that implements that strategy.
+**
+** This is for VXWorks only.
+*/
+static const sqlite3_io_methods *autolockIoFinderImpl(
+ const char *filePath, /* name of the database file */
+ int fd /* file descriptor open on the database file */
+){
+ struct flock lockInfo;
+
+ if( !filePath ){
+ /* If filePath==NULL that means we are dealing with a transient file
+ ** that does not need to be locked. */
+ return &nolockIoMethods;
+ }
+
+ /* Test if fcntl() is supported and use POSIX style locks.
+ ** Otherwise fall back to the named semaphore method.
+ */
+ lockInfo.l_len = 1;
+ lockInfo.l_start = 0;
+ lockInfo.l_whence = SEEK_SET;
+ lockInfo.l_type = F_RDLCK;
+ if( fcntl(fd, F_GETLK, &lockInfo)!=-1 ) {
+ return &posixIoMethods;
+ }else{
+ return &semIoMethods;
+ }
+}
+static const sqlite3_io_methods *(*const autolockIoFinder)(const char*,int)
+ = autolockIoFinderImpl;
+
+#endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */
+
/*
** An abstract type for a pointer to a IO method finder function:
*/
@@ -5061,7 +5099,7 @@ int sqlite3_os_init(void){
** array cannot be const.
*/
static sqlite3_vfs aVfs[] = {
-#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
+#if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__))
UNIXVFS("unix", autolockIoFinder ),
#else
UNIXVFS("unix", posixIoFinder ),
@@ -5073,8 +5111,10 @@ int sqlite3_os_init(void){
#endif
#if SQLITE_ENABLE_LOCKING_STYLE
UNIXVFS("unix-posix", posixIoFinder ),
+#if !OS_VXWORKS
UNIXVFS("unix-flock", flockIoFinder ),
#endif
+#endif
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
UNIXVFS("unix-afp", afpIoFinder ),
UNIXVFS("unix-proxy", proxyIoFinder ),