Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Changes to the thread routines to disable them when threading is turned off using sqlite3_config(). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | threads-sort-ex1 |
Files: | files | file ages | folders |
SHA1: |
555fc07efd1a1bc597804dcacbbcd95e |
User & Date: | drh 2012-08-20 12:36:53.934 |
References
2012-08-21
| ||
17:36 | Cherry-pick [555fc07]: Changes to the thread routines to disable them when threading is turned off using sqlite3_config(). Also merge all recent trunk changes. (check-in: c92b0fe137 user: drh tags: threads) | |
Context
2012-08-21
| ||
17:46 | Merge in all the latest trunk changes. (check-in: 45cdc32f1e user: drh tags: threads-sort-ex1) | |
2012-08-20
| ||
12:36 | Changes to the thread routines to disable them when threading is turned off using sqlite3_config(). (check-in: 555fc07efd user: drh tags: threads-sort-ex1) | |
2012-08-16
| ||
20:05 | Attempt to use two cores to do sorting. Unfortunately, instead of making sorts go faster as was hoped, this changes slows sorting down by about 10%. (Later:) The previous measurement was compiled using -pg. When compiled using -Os, this new code is roughly 10% faster than the original. (check-in: 11dd05e598 user: drh tags: threads-sort-ex1) | |
Changes
Changes to src/threads.c.
︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */ #include <pthread.h> /* A running thread */ struct SQLiteThread { pthread_t tid; }; /* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; int rc; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; | > > > > | | > | < > > > > | > | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */ #include <pthread.h> /* A running thread */ struct SQLiteThread { pthread_t tid; int done; void *pOut; }; /* Create a new thread */ int sqlite3ThreadCreate( SQLiteThread **ppThread, /* OUT: Write the thread object here */ void *(*xTask)(void*), /* Routine to run in a separate thread */ void *pIn /* Argument passed into xTask() */ ){ SQLiteThread *p; int rc; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; memset(p, 0, sizeof(*p)); if( sqlite3GlobalConfig.bCoreMutex==0 || pthread_create(&p->tid, 0, xTask, pIn)!=0 ){ p->done = 1; p->pOut = xTask(pIn); } *ppThread = p; return SQLITE_OK; } /* Get the results of the thread */ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ int rc; assert( ppOut!=0 ); if( p==0 ) return SQLITE_NOMEM; if( p->done ){ *ppOut = p->pOut; rc = SQLITE_OK; }else{ rc = pthread_join(p->tid, ppOut); } sqlite3_free(p); return rc ? SQLITE_ERROR : SQLITE_OK; } #endif /* SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS) */ /******************************** End Unix Pthreads *************************/ |
︙ | ︙ | |||
111 112 113 114 115 116 117 | SQLiteThread *p; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; | > > > | > | | | < > > > > > > > | | > | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | SQLiteThread *p; assert( ppThread!=0 ); assert( xTask!=0 ); *ppThread = 0; p = sqlite3Malloc(sizeof(*p)); if( p==0 ) return SQLITE_NOMEM; if( sqlite3GlobalConfig.bCoreMutex==0 ){ memset(p, 0, sizeof(*p)); }else{ p->xTask = xTask; p->pIn = pIn; p->tid = _beginthread(sqlite3ThreadProc, 0, p); if( p->tid==(uintptr_t)-1 ){ memset(p, 0, sizeof(*p)); } } if( p->xTask==0 ){ p->pResult = xTask(pIn); } *ppThread = p; return SQLITE_OK; } /* Get the results of the thread */ int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ DWORD rc; assert( ppOut!=0 ); if( p==0 ) return SQLITE_NOMEM; if( p->xTask==0 ){ rc = WAIT_OBJECT_O; }else{ rc = sqlite3Win32Wait((HANDLE)p->tid); assert( rc!=WAIT_IO_COMPLETION ); } if( rc==WAIT_OBJECT_0 ) *ppOut = p->pResult; sqlite3_free(p); return (rc==WAIT_OBJECT_0) ? SQLITE_OK : SQLITE_ERROR; } #endif /* SQLITE_OS_WIN && !SQLITE_OS_WINRT */ /******************************** End Win32 Threads *************************/ |
︙ | ︙ |