On Wed, 2007-10-31 at 22:27 -0700, Joe Wilson wrote:
> After reading Dan's response, I must be mis-interpreting these comments.

I was a bit terse. See below.

> > 
> > See comments for unixLock() and unixUnlock() in os_unix.c.
> > 
> > /*
> > ** 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,

>From SQLite's point of view, locks are on a per file-handle basis. If
a unix process that uses sqlite has two file-handles open on the same
file (i.e. because the user has opened two separate connections with
two calls to sqlite3_open()), SQLite expects them to be able to 
obtain and hold locks independently. A shared lock on one handle
should prevent obtaining an exclusive lock on the other, just as it
would if the two handles were opened by different processes. If a
shared lock is obtained on both handles, then released on one, SQLite
expects that the other handle still holds it's shared lock.

The above paragraph describes how sqlite expects the vfs implementation
to work. Unix doesn't share this simple view of the world, so the
implementation of sqlite3_vfs for unix has to jump through all sorts
of hoops to implement it.

So when I say you don't need to worry about reference counting, I
mean if sqlite calls xLock() on a file-handle twice, then xUnlock()
once, the file-handle should move into the "unlocked" state.

Dan.




>  so each unixFile
> > ** structure contains a pointer to an instance of this object and this
> > ** object keeps a count of the number of unixFile 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 */
> > };
> > 
> > ...
> > 
> >   /* If a SHARED lock is requested, and some thread using this PID already
> >   ** has a SHARED or RESERVED lock, then increment reference counts and
> >   ** return SQLITE_OK.
> >   */
> >   if( locktype==SHARED_LOCK &&
> >       (pLock->locktype==SHARED_LOCK || pLock->locktype==RESERVED_LOCK) ){
> >     assert( locktype==SHARED_LOCK );
> >     assert( pFile->locktype==0 );
> >     assert( pLock->cnt>0 );
> >     pFile->locktype = SHARED_LOCK;
> >     pLock->cnt++;
> >     pFile->pOpen->nLock++;
> >     goto end_lock;
> >   }
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [EMAIL PROTECTED]
> -----------------------------------------------------------------------------
> 


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to