Fixed client serials not being unique on Windows (
bug 5285, r=psychonic).
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** This file implements a FIFO queue of rowids used for processing
13 ** UPDATE and DELETE statements.
15 #include "sqliteInt.h"
19 ** Allocate a new FifoPage and return a pointer to it. Return NULL if
20 ** we run out of memory. Leave space on the page for nEntry entries.
22 static FifoPage *allocateFifoPage(int nEntry){
27 pPage = sqlite3_malloc( sizeof(FifoPage) + sizeof(i64)*(nEntry-1) );
29 pPage->nSlot = nEntry;
38 ** Initialize a Fifo structure.
40 void sqlite3VdbeFifoInit(Fifo *pFifo){
41 memset(pFifo, 0, sizeof(*pFifo));
45 ** Push a single 64-bit integer value into the Fifo. Return SQLITE_OK
46 ** normally. SQLITE_NOMEM is returned if we are unable to allocate
49 int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){
53 pPage = pFifo->pLast = pFifo->pFirst = allocateFifoPage(20);
57 }else if( pPage->iWrite>=pPage->nSlot ){
58 pPage->pNext = allocateFifoPage(pFifo->nEntry);
59 if( pPage->pNext==0 ){
62 pPage = pFifo->pLast = pPage->pNext;
64 pPage->aSlot[pPage->iWrite++] = val;
70 ** Extract a single 64-bit integer value from the Fifo. The integer
71 ** extracted is the one least recently inserted. If the Fifo is empty
72 ** return SQLITE_DONE.
74 int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
76 if( pFifo->nEntry==0 ){
79 assert( pFifo->nEntry>0 );
80 pPage = pFifo->pFirst;
82 assert( pPage->iWrite>pPage->iRead );
83 assert( pPage->iWrite<=pPage->nSlot );
84 assert( pPage->iRead<pPage->nSlot );
85 assert( pPage->iRead>=0 );
86 *pVal = pPage->aSlot[pPage->iRead++];
88 if( pPage->iRead>=pPage->iWrite ){
89 pFifo->pFirst = pPage->pNext;
91 if( pFifo->nEntry==0 ){
92 assert( pFifo->pLast==pPage );
95 assert( pFifo->pFirst!=0 );
98 assert( pFifo->nEntry>0 );
104 ** Delete all information from a Fifo object. Free all memory held
107 void sqlite3VdbeFifoClear(Fifo *pFifo){
108 FifoPage *pPage, *pNextPage;
109 for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){
110 pNextPage = pPage->pNext;
113 sqlite3VdbeFifoInit(pFifo);