OLD | NEW |
1 /* | 1 /* |
2 ** 2012 July 21 | 2 ** 2012 July 21 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 SQLiteThread *p; | 56 SQLiteThread *p; |
57 int rc; | 57 int rc; |
58 | 58 |
59 assert( ppThread!=0 ); | 59 assert( ppThread!=0 ); |
60 assert( xTask!=0 ); | 60 assert( xTask!=0 ); |
61 /* This routine is never used in single-threaded mode */ | 61 /* This routine is never used in single-threaded mode */ |
62 assert( sqlite3GlobalConfig.bCoreMutex!=0 ); | 62 assert( sqlite3GlobalConfig.bCoreMutex!=0 ); |
63 | 63 |
64 *ppThread = 0; | 64 *ppThread = 0; |
65 p = sqlite3Malloc(sizeof(*p)); | 65 p = sqlite3Malloc(sizeof(*p)); |
66 if( p==0 ) return SQLITE_NOMEM; | 66 if( p==0 ) return SQLITE_NOMEM_BKPT; |
67 memset(p, 0, sizeof(*p)); | 67 memset(p, 0, sizeof(*p)); |
68 p->xTask = xTask; | 68 p->xTask = xTask; |
69 p->pIn = pIn; | 69 p->pIn = pIn; |
70 /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a | 70 /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a |
71 ** function that returns SQLITE_ERROR when passed the argument 200, that | 71 ** function that returns SQLITE_ERROR when passed the argument 200, that |
72 ** forces worker threads to run sequentially and deterministically | 72 ** forces worker threads to run sequentially and deterministically |
73 ** for testing purposes. */ | 73 ** for testing purposes. */ |
74 if( sqlite3FaultSim(200) ){ | 74 if( sqlite3FaultSim(200) ){ |
75 rc = 1; | 75 rc = 1; |
76 }else{ | 76 }else{ |
77 rc = pthread_create(&p->tid, 0, xTask, pIn); | 77 rc = pthread_create(&p->tid, 0, xTask, pIn); |
78 } | 78 } |
79 if( rc ){ | 79 if( rc ){ |
80 p->done = 1; | 80 p->done = 1; |
81 p->pOut = xTask(pIn); | 81 p->pOut = xTask(pIn); |
82 } | 82 } |
83 *ppThread = p; | 83 *ppThread = p; |
84 return SQLITE_OK; | 84 return SQLITE_OK; |
85 } | 85 } |
86 | 86 |
87 /* Get the results of the thread */ | 87 /* Get the results of the thread */ |
88 int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ | 88 int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ |
89 int rc; | 89 int rc; |
90 | 90 |
91 assert( ppOut!=0 ); | 91 assert( ppOut!=0 ); |
92 if( NEVER(p==0) ) return SQLITE_NOMEM; | 92 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; |
93 if( p->done ){ | 93 if( p->done ){ |
94 *ppOut = p->pOut; | 94 *ppOut = p->pOut; |
95 rc = SQLITE_OK; | 95 rc = SQLITE_OK; |
96 }else{ | 96 }else{ |
97 rc = pthread_join(p->tid, ppOut) ? SQLITE_ERROR : SQLITE_OK; | 97 rc = pthread_join(p->tid, ppOut) ? SQLITE_ERROR : SQLITE_OK; |
98 } | 98 } |
99 sqlite3_free(p); | 99 sqlite3_free(p); |
100 return rc; | 100 return rc; |
101 } | 101 } |
102 | 102 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 SQLiteThread **ppThread, /* OUT: Write the thread object here */ | 147 SQLiteThread **ppThread, /* OUT: Write the thread object here */ |
148 void *(*xTask)(void*), /* Routine to run in a separate thread */ | 148 void *(*xTask)(void*), /* Routine to run in a separate thread */ |
149 void *pIn /* Argument passed into xTask() */ | 149 void *pIn /* Argument passed into xTask() */ |
150 ){ | 150 ){ |
151 SQLiteThread *p; | 151 SQLiteThread *p; |
152 | 152 |
153 assert( ppThread!=0 ); | 153 assert( ppThread!=0 ); |
154 assert( xTask!=0 ); | 154 assert( xTask!=0 ); |
155 *ppThread = 0; | 155 *ppThread = 0; |
156 p = sqlite3Malloc(sizeof(*p)); | 156 p = sqlite3Malloc(sizeof(*p)); |
157 if( p==0 ) return SQLITE_NOMEM; | 157 if( p==0 ) return SQLITE_NOMEM_BKPT; |
158 /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a | 158 /* If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a |
159 ** function that returns SQLITE_ERROR when passed the argument 200, that | 159 ** function that returns SQLITE_ERROR when passed the argument 200, that |
160 ** forces worker threads to run sequentially and deterministically | 160 ** forces worker threads to run sequentially and deterministically |
161 ** (via the sqlite3FaultSim() term of the conditional) for testing | 161 ** (via the sqlite3FaultSim() term of the conditional) for testing |
162 ** purposes. */ | 162 ** purposes. */ |
163 if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){ | 163 if( sqlite3GlobalConfig.bCoreMutex==0 || sqlite3FaultSim(200) ){ |
164 memset(p, 0, sizeof(*p)); | 164 memset(p, 0, sizeof(*p)); |
165 }else{ | 165 }else{ |
166 p->xTask = xTask; | 166 p->xTask = xTask; |
167 p->pIn = pIn; | 167 p->pIn = pIn; |
(...skipping 11 matching lines...) Expand all Loading... |
179 } | 179 } |
180 | 180 |
181 DWORD sqlite3Win32Wait(HANDLE hObject); /* os_win.c */ | 181 DWORD sqlite3Win32Wait(HANDLE hObject); /* os_win.c */ |
182 | 182 |
183 /* Get the results of the thread */ | 183 /* Get the results of the thread */ |
184 int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ | 184 int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ |
185 DWORD rc; | 185 DWORD rc; |
186 BOOL bRc; | 186 BOOL bRc; |
187 | 187 |
188 assert( ppOut!=0 ); | 188 assert( ppOut!=0 ); |
189 if( NEVER(p==0) ) return SQLITE_NOMEM; | 189 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; |
190 if( p->xTask==0 ){ | 190 if( p->xTask==0 ){ |
191 /* assert( p->id==GetCurrentThreadId() ); */ | 191 /* assert( p->id==GetCurrentThreadId() ); */ |
192 rc = WAIT_OBJECT_0; | 192 rc = WAIT_OBJECT_0; |
193 assert( p->tid==0 ); | 193 assert( p->tid==0 ); |
194 }else{ | 194 }else{ |
195 assert( p->id!=0 && p->id!=GetCurrentThreadId() ); | 195 assert( p->id!=0 && p->id!=GetCurrentThreadId() ); |
196 rc = sqlite3Win32Wait((HANDLE)p->tid); | 196 rc = sqlite3Win32Wait((HANDLE)p->tid); |
197 assert( rc!=WAIT_IO_COMPLETION ); | 197 assert( rc!=WAIT_IO_COMPLETION ); |
198 bRc = CloseHandle((HANDLE)p->tid); | 198 bRc = CloseHandle((HANDLE)p->tid); |
199 assert( bRc ); | 199 assert( bRc ); |
(...skipping 27 matching lines...) Expand all Loading... |
227 SQLiteThread **ppThread, /* OUT: Write the thread object here */ | 227 SQLiteThread **ppThread, /* OUT: Write the thread object here */ |
228 void *(*xTask)(void*), /* Routine to run in a separate thread */ | 228 void *(*xTask)(void*), /* Routine to run in a separate thread */ |
229 void *pIn /* Argument passed into xTask() */ | 229 void *pIn /* Argument passed into xTask() */ |
230 ){ | 230 ){ |
231 SQLiteThread *p; | 231 SQLiteThread *p; |
232 | 232 |
233 assert( ppThread!=0 ); | 233 assert( ppThread!=0 ); |
234 assert( xTask!=0 ); | 234 assert( xTask!=0 ); |
235 *ppThread = 0; | 235 *ppThread = 0; |
236 p = sqlite3Malloc(sizeof(*p)); | 236 p = sqlite3Malloc(sizeof(*p)); |
237 if( p==0 ) return SQLITE_NOMEM; | 237 if( p==0 ) return SQLITE_NOMEM_BKPT; |
238 if( (SQLITE_PTR_TO_INT(p)/17)&1 ){ | 238 if( (SQLITE_PTR_TO_INT(p)/17)&1 ){ |
239 p->xTask = xTask; | 239 p->xTask = xTask; |
240 p->pIn = pIn; | 240 p->pIn = pIn; |
241 }else{ | 241 }else{ |
242 p->xTask = 0; | 242 p->xTask = 0; |
243 p->pResult = xTask(pIn); | 243 p->pResult = xTask(pIn); |
244 } | 244 } |
245 *ppThread = p; | 245 *ppThread = p; |
246 return SQLITE_OK; | 246 return SQLITE_OK; |
247 } | 247 } |
248 | 248 |
249 /* Get the results of the thread */ | 249 /* Get the results of the thread */ |
250 int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ | 250 int sqlite3ThreadJoin(SQLiteThread *p, void **ppOut){ |
251 | 251 |
252 assert( ppOut!=0 ); | 252 assert( ppOut!=0 ); |
253 if( NEVER(p==0) ) return SQLITE_NOMEM; | 253 if( NEVER(p==0) ) return SQLITE_NOMEM_BKPT; |
254 if( p->xTask ){ | 254 if( p->xTask ){ |
255 *ppOut = p->xTask(p->pIn); | 255 *ppOut = p->xTask(p->pIn); |
256 }else{ | 256 }else{ |
257 *ppOut = p->pResult; | 257 *ppOut = p->pResult; |
258 } | 258 } |
259 sqlite3_free(p); | 259 sqlite3_free(p); |
260 | 260 |
261 #if defined(SQLITE_TEST) | 261 #if defined(SQLITE_TEST) |
262 { | 262 { |
263 void *pTstAlloc = sqlite3Malloc(10); | 263 void *pTstAlloc = sqlite3Malloc(10); |
264 if (!pTstAlloc) return SQLITE_NOMEM; | 264 if (!pTstAlloc) return SQLITE_NOMEM_BKPT; |
265 sqlite3_free(pTstAlloc); | 265 sqlite3_free(pTstAlloc); |
266 } | 266 } |
267 #endif | 267 #endif |
268 | 268 |
269 return SQLITE_OK; | 269 return SQLITE_OK; |
270 } | 270 } |
271 | 271 |
272 #endif /* !defined(SQLITE_THREADS_IMPLEMENTED) */ | 272 #endif /* !defined(SQLITE_THREADS_IMPLEMENTED) */ |
273 /****************************** End Single-Threaded *************************/ | 273 /****************************** End Single-Threaded *************************/ |
274 #endif /* SQLITE_MAX_WORKER_THREADS>0 */ | 274 #endif /* SQLITE_MAX_WORKER_THREADS>0 */ |
OLD | NEW |