OLD | NEW |
1 /* | 1 /* |
2 ** 2006 January 07 | 2 ** 2006 January 07 |
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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 pthread_t x; | 466 pthread_t x; |
467 int rc; | 467 int rc; |
468 g.serverHalt = 0; | 468 g.serverHalt = 0; |
469 rc = pthread_create(&x, 0, sqlite3_server, 0); | 469 rc = pthread_create(&x, 0, sqlite3_server, 0); |
470 if( rc==0 ){ | 470 if( rc==0 ){ |
471 pthread_detach(x); | 471 pthread_detach(x); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 /* | 475 /* |
| 476 ** A wrapper around sqlite3_server() that decrements the int variable |
| 477 ** pointed to by the first argument after the sqlite3_server() call |
| 478 ** returns. |
| 479 */ |
| 480 static void *serverWrapper(void *pnDecr){ |
| 481 void *p = sqlite3_server(0); |
| 482 (*(int*)pnDecr)--; |
| 483 return p; |
| 484 } |
| 485 |
| 486 /* |
| 487 ** This function is the similar to sqlite3_server_start(), except that |
| 488 ** the integer pointed to by the first argument is decremented when |
| 489 ** the server thread exits. |
| 490 */ |
| 491 void sqlite3_server_start2(int *pnDecr){ |
| 492 pthread_t x; |
| 493 int rc; |
| 494 g.serverHalt = 0; |
| 495 rc = pthread_create(&x, 0, serverWrapper, (void*)pnDecr); |
| 496 if( rc==0 ){ |
| 497 pthread_detach(x); |
| 498 } |
| 499 } |
| 500 |
| 501 /* |
476 ** If a server thread is running, then stop it. If no server is | 502 ** If a server thread is running, then stop it. If no server is |
477 ** running, this routine is effectively a no-op. | 503 ** running, this routine is effectively a no-op. |
478 ** | 504 ** |
479 ** This routine waits until the server has actually stopped before | 505 ** This routine waits until the server has actually stopped before |
480 ** returning. | 506 ** returning. |
481 */ | 507 */ |
482 void sqlite3_server_stop(void){ | 508 void sqlite3_server_stop(void){ |
483 g.serverHalt = 1; | 509 g.serverHalt = 1; |
484 pthread_cond_broadcast(&g.serverWakeup); | 510 pthread_cond_broadcast(&g.serverWakeup); |
485 pthread_mutex_lock(&g.serverMutex); | 511 pthread_mutex_lock(&g.serverMutex); |
486 pthread_mutex_unlock(&g.serverMutex); | 512 pthread_mutex_unlock(&g.serverMutex); |
487 } | 513 } |
488 | 514 |
489 #endif /* SQLITE_OS_UNIX && SQLITE_THREADSAFE */ | 515 #endif /* SQLITE_OS_UNIX && SQLITE_THREADSAFE */ |
490 #endif /* defined(SQLITE_SERVER) */ | 516 #endif /* defined(SQLITE_SERVER) */ |
OLD | NEW |