gitlab.com/danp128/sqlite@v1.0.0/internal/threadtest4/threadtest4_linux_386.go (about) 1 // Code generated by ccgo. DO NOT EDIT. 2 3 // threadtest4 4 // /* 5 // ** 2014-12-11 6 // ** 7 // ** The author disclaims copyright to this source code. In place of 8 // ** a legal notice, here is a blessing: 9 // ** 10 // ** May you do good and not evil. 11 // ** May you find forgiveness for yourself and forgive others. 12 // ** May you share freely, never taking more than you give. 13 // ** 14 // ************************************************************************* 15 // ** This file implements a simple standalone program used to stress the 16 // ** SQLite library when accessing the same set of databases simultaneously 17 // ** from multiple threads in shared-cache mode. 18 // ** 19 // ** This test program runs on unix-like systems only. It uses pthreads. 20 // ** To compile: 21 // ** 22 // ** gcc -g -Wall -I. threadtest4.c sqlite3.c -ldl -lpthread 23 // ** 24 // ** To run: 25 // ** 26 // ** ./a.out 10 27 // ** 28 // ** The argument is the number of threads. There are also options, such 29 // ** as -wal and -multithread and -serialized. 30 // ** 31 // ** Consider also compiling with clang instead of gcc and adding the 32 // ** -fsanitize=thread option. 33 // */ 34 package main 35 36 import ( 37 "math" 38 "os" 39 "unsafe" 40 41 "modernc.org/ccgo/crt" 42 "modernc.org/sqlite/internal/bin" 43 ) 44 45 var argv []*int8 46 47 func main() { 48 for _, v := range os.Args { 49 argv = append(argv, (*int8)(crt.CString(v))) 50 } 51 argv = append(argv, nil) 52 X_start(crt.NewTLS(), int32(len(os.Args)), &argv[0]) 53 } 54 55 func X_start(tls *crt.TLS, _argc int32, _argv **int8) { 56 crt.X__register_stdfiles(tls, Xstdin, Xstdout, Xstderr) 57 crt.X__builtin_exit(tls, Xmain(tls, _argc, _argv)) 58 } 59 60 var Xstdin unsafe.Pointer 61 62 func init() { 63 Xstdin = unsafe.Pointer(&X__stdfiles) 64 } 65 66 var X__stdfiles [3]unsafe.Pointer 67 68 var Xstdout unsafe.Pointer 69 70 func init() { 71 Xstdout = unsafe.Pointer(uintptr(unsafe.Pointer(&X__stdfiles)) + 4) 72 } 73 74 var Xstderr unsafe.Pointer 75 76 func init() { 77 Xstderr = unsafe.Pointer(uintptr(unsafe.Pointer(&X__stdfiles)) + 8) 78 } 79 80 func Xmain(tls *crt.TLS, _argc int32, _argv **int8) (r0 int32) { 81 var _nWorker, _i, _nErr, _nTest, _rc int32 82 var _wkrFlags uint32 83 var _1_z *int8 84 var _db unsafe.Pointer 85 var _wrMutex crt.Xpthread_mutex_t 86 var _infoTop XWorkerInfo 87 var _aInfo, _p *XWorkerInfo 88 r0 = int32(0) 89 _nWorker = int32(0) 90 _wkrFlags = uint32(0) 91 _nErr = int32(0) 92 _nTest = int32(0) 93 _db = nil 94 bin.Xsqlite3_config(tls, int32(2)) 95 _i = int32(1) 96 _0: 97 if _i >= _argc { 98 goto _3 99 } 100 _1_z = *elem0(_argv, uintptr(_i)) 101 if int32(*elem1(_1_z, 0)) != int32(45) { 102 goto _4 103 } 104 if (int32(*elem1(_1_z, uintptr(1))) == int32(45)) && (int32(*elem1(_1_z, uintptr(2))) != int32(0)) { 105 *(*uintptr)(unsafe.Pointer(&_1_z)) += uintptr(1) 106 } 107 if crt.Xstrcmp(tls, _1_z, str(0)) == int32(0) { 108 bin.Xsqlite3_config(tls, int32(2)) 109 _wkrFlags &= uint32(4294967294) 110 goto _14 111 } 112 if crt.Xstrcmp(tls, _1_z, str(13)) == int32(0) { 113 bin.Xsqlite3_config(tls, int32(3)) 114 _wkrFlags |= uint32(1) 115 goto _14 116 } 117 if crt.Xstrcmp(tls, _1_z, str(25)) == int32(0) { 118 _wkrFlags |= uint32(2) 119 goto _14 120 } 121 if crt.Xstrcmp(tls, _1_z, str(30)) == int32(0) { 122 _wkrFlags |= uint32(4) 123 goto _14 124 } 125 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(37), unsafe.Pointer(*elem0(_argv, uintptr(_i)))) 126 crt.Xexit(tls, int32(1)) 127 _14: 128 goto _20 129 _4: 130 if int32(*elem1(_1_z, 0)) < int32(49) || int32(*elem1(_1_z, 0)) > int32(57) || _nWorker != int32(0) { 131 goto _18 132 } 133 _nWorker = crt.Xatoi(tls, _1_z) 134 if _nWorker < int32(2) { 135 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(70)) 136 crt.Xexit(tls, int32(1)) 137 } 138 goto _20 139 _18: 140 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(92), unsafe.Pointer(*elem0(_argv, uintptr(_i)))) 141 crt.Xexit(tls, int32(1)) 142 _20: 143 _i += 1 144 goto _0 145 _3: 146 if _nWorker == int32(0) { 147 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(127), unsafe.Pointer(*elem0(_argv, 0))) 148 crt.Xexit(tls, int32(1)) 149 } 150 if bin.Xsqlite3_threadsafe(tls) == 0 { 151 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(260)) 152 crt.Xexit(tls, int32(1)) 153 } 154 bin.Xsqlite3_initialize(tls) 155 bin.Xsqlite3_enable_shared_cache(tls, int32(1)) 156 crt.Xpthread_mutex_init(tls, &_wrMutex, nil) 157 crt.Xunlink(tls, str(299)) 158 crt.Xunlink(tls, str(312)) 159 crt.Xunlink(tls, str(325)) 160 _rc = bin.Xsqlite3_open(tls, str(299), (**bin.Xsqlite3)(unsafe.Pointer(&_db))) 161 if _rc != int32(0) { 162 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(338)) 163 crt.Xexit(tls, int32(1)) 164 } 165 crt.Xmemset(tls, unsafe.Pointer(&_infoTop), int32(0), uint32(40)) 166 _infoTop.Xdb = _db 167 _infoTop.XwkrFlags = _wkrFlags 168 _p = &_infoTop 169 if (_wkrFlags & uint32(2)) != 0 { 170 _run_sql(tls, _p, str(382)) 171 } 172 _run_sql(tls, _p, str(406)) 173 _run_sql(tls, _p, str(429)) 174 _run_sql(tls, _p, str(485)) 175 _run_sql(tls, _p, str(515)) 176 _run_sql(tls, _p, str(544)) 177 _run_sql(tls, _p, str(577)) 178 _run_sql(tls, _p, str(639)) 179 _run_sql(tls, _p, str(675)) 180 _run_sql(tls, _p, str(710)) 181 _run_sql(tls, _p, str(743)) 182 _run_sql(tls, _p, str(805)) 183 _run_sql(tls, _p, str(841)) 184 _aInfo = (*XWorkerInfo)(_safe_malloc(tls, int32(uint32(40)*uint32(_nWorker)))) 185 crt.Xmemset(tls, unsafe.Pointer(_aInfo), int32(0), uint32(40)*uint32(_nWorker)) 186 _i = int32(0) 187 _25: 188 if _i >= _nWorker { 189 goto _28 190 } 191 elem2(_aInfo, uintptr(_i)).Xtid = _i + int32(1) 192 elem2(_aInfo, uintptr(_i)).XnWorker = _nWorker 193 elem2(_aInfo, uintptr(_i)).XwkrFlags = _wkrFlags 194 elem2(_aInfo, uintptr(_i)).XmainDb = _db 195 *(**crt.Xpthread_mutex_t)(unsafe.Pointer(&(elem2(_aInfo, uintptr(_i)).XpWrMutex))) = &_wrMutex 196 _rc = crt.Xpthread_create(tls, &(elem2(_aInfo, uintptr(_i)).Xid), nil, _worker_thread, unsafe.Pointer(elem2(_aInfo, uintptr(_i)))) 197 if _rc != int32(0) { 198 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(876), _i+int32(1)) 199 crt.Xexit(tls, int32(1)) 200 } 201 crt.Xsched_yield(tls) 202 _i += 1 203 goto _25 204 _28: 205 _i = int32(0) 206 _30: 207 if _i >= _nWorker { 208 goto _33 209 } 210 crt.Xpthread_join(tls, elem2(_aInfo, uintptr(_i)).Xid, nil) 211 crt.Xprintf(tls, str(914), elem2(_aInfo, uintptr(_i)).Xtid, elem2(_aInfo, uintptr(_i)).XnErr, elem2(_aInfo, uintptr(_i)).XnTest) 212 if (elem2(_aInfo, uintptr(_i)).XzMsg) != nil { 213 crt.Xprintf(tls, str(954), unsafe.Pointer(elem2(_aInfo, uintptr(_i)).XzMsg)) 214 goto _35 215 } 216 crt.Xprintf(tls, str(960)) 217 _35: 218 _nErr += elem2(_aInfo, uintptr(_i)).XnErr 219 _nTest += elem2(_aInfo, uintptr(_i)).XnTest 220 crt.Xfflush(tls, (*crt.XFILE)(Xstdout)) 221 _i += 1 222 goto _30 223 _33: 224 bin.Xsqlite3_close(tls, (*bin.Xsqlite3)(_db)) 225 bin.Xsqlite3_free(tls, unsafe.Pointer(_aInfo)) 226 crt.Xprintf(tls, str(962), _nErr, _nTest) 227 return _nErr 228 } 229 230 // C comment 231 // /* 232 // ** Run a SQL statements. Panic if unable. 233 // */ 234 func _run_sql(tls *crt.TLS, _p *XWorkerInfo, _zFormat *int8, args ...interface{}) { 235 var _rc, _i, _nRetry int32 236 var _zSql *int8 237 var _pStmt unsafe.Pointer 238 var _ap []interface{} 239 _pStmt = nil 240 _nRetry = int32(0) 241 _ap = args 242 _zSql = bin.Xsqlite3_vmprintf(tls, _zFormat, _ap) 243 _ap = nil 244 _check_oom(tls, unsafe.Pointer(_zSql)) 245 _i = int32(0) 246 _0: 247 if _i >= int32(1000) { 248 goto _3 249 } 250 _rc = bin.Xsqlite3_prepare_v2(tls, (*bin.Xsqlite3)(_p.Xdb), _zSql, int32(-1), &_pStmt, nil) 251 if _rc == int32(0) { 252 goto _3 253 } 254 _i += 1 255 goto _0 256 _3: 257 if _rc != int32(0) { 258 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(991), _rc, bin.Xsqlite3_extended_errcode(tls, (*bin.Xsqlite3)(_p.Xdb)), unsafe.Pointer(bin.Xsqlite3_errmsg(tls, (*bin.Xsqlite3)(_p.Xdb))), unsafe.Pointer(_zSql)) 259 crt.Xexit(tls, int32(1)) 260 } 261 _worker_trace(tls, _p, str(1036), unsafe.Pointer(_zSql)) 262 _6: 263 if store3(&_rc, bin.Xsqlite3_step(tls, _pStmt)) == int32(101) { 264 goto _7 265 } 266 if (_rc&int32(255)) != int32(5) && (_rc&int32(255)) != int32(6) { 267 goto _9 268 } 269 bin.Xsqlite3_reset(tls, _pStmt) 270 _nRetry += 1 271 if _nRetry < int32(10) { 272 _worker_trace(tls, _p, str(1049), _nRetry, unsafe.Pointer(_zSql)) 273 crt.Xsched_yield(tls) 274 goto _6 275 } 276 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(1067), _p.Xtid, unsafe.Pointer(_zSql)) 277 crt.Xexit(tls, int32(1)) 278 _9: 279 if _rc != int32(100) { 280 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(1109), _rc, bin.Xsqlite3_extended_errcode(tls, (*bin.Xsqlite3)(_p.Xdb)), unsafe.Pointer(bin.Xsqlite3_errmsg(tls, (*bin.Xsqlite3)(_p.Xdb))), unsafe.Pointer(_zSql)) 281 crt.Xexit(tls, int32(1)) 282 } 283 goto _6 284 _7: 285 bin.Xsqlite3_free(tls, unsafe.Pointer(_zSql)) 286 bin.Xsqlite3_finalize(tls, _pStmt) 287 } 288 289 // C comment 290 // /* 291 // ** Report an OOM error and die if the argument is NULL 292 // */ 293 func _check_oom(tls *crt.TLS, _x unsafe.Pointer) { 294 if _x == nil { 295 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(1151)) 296 crt.Xexit(tls, int32(1)) 297 } 298 } 299 300 // C comment 301 // /* 302 // ** Print a trace message for a worker 303 // */ 304 func _worker_trace(tls *crt.TLS, _p *XWorkerInfo, _zFormat *int8, args ...interface{}) { 305 var _zMsg *int8 306 var _ap []interface{} 307 if (_p.XwkrFlags & uint32(4)) == (0) { 308 return 309 } 310 _ap = args 311 _zMsg = bin.Xsqlite3_vmprintf(tls, _zFormat, _ap) 312 _check_oom(tls, unsafe.Pointer(_zMsg)) 313 _ap = nil 314 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(1166), _p.Xtid, unsafe.Pointer(_zMsg)) 315 bin.Xsqlite3_free(tls, unsafe.Pointer(_zMsg)) 316 } 317 318 // C comment 319 // /* 320 // ** Allocate memory. If the allocation fails, print an error message and 321 // ** kill the process. 322 // */ 323 func _safe_malloc(tls *crt.TLS, _sz int32) (r0 unsafe.Pointer) { 324 var _x unsafe.Pointer 325 _x = bin.Xsqlite3_malloc(tls, func() int32 { 326 if _sz > int32(0) { 327 return _sz 328 } 329 return int32(1) 330 }()) 331 _check_oom(tls, _x) 332 return _x 333 } 334 335 // C comment 336 // /* 337 // ** Each thread runs the following function. 338 // */ 339 func _worker_thread(tls *crt.TLS, _pArg unsafe.Pointer) (r0 unsafe.Pointer) { 340 var _iOuter, _i, _rc int32 341 var _pStmt unsafe.Pointer 342 var _p *XWorkerInfo 343 _p = (*XWorkerInfo)(_pArg) 344 crt.Xprintf(tls, str(1183), _p.Xtid) 345 crt.Xfflush(tls, (*crt.XFILE)(Xstdout)) 346 _iOuter = int32(1) 347 _0: 348 if _iOuter > _p.XnWorker { 349 goto _3 350 } 351 _worker_open_connection(tls, _p, _iOuter) 352 _i = int32(0) 353 _4: 354 if _i >= int32(4) { 355 goto _7 356 } 357 _worker_add_content(tls, _p, (_i*int32(100))+int32(1), (_i+int32(1))*int32(100), ((_p.Xtid+_iOuter)%int32(3))+int32(1)) 358 _worker_add_content(tls, _p, (_i*int32(100))+int32(1), (_i+int32(1))*int32(100), (((_p.Xtid+_iOuter)+int32(1))%int32(3))+int32(1)) 359 _worker_add_content(tls, _p, (_i*int32(100))+int32(1), (_i+int32(1))*int32(100), (((_p.Xtid+_iOuter)+int32(2))%int32(3))+int32(1)) 360 _i += 1 361 goto _4 362 _7: 363 _pStmt = _prep_sql(tls, _p.Xdb, str(1202), _p.Xtid) 364 _worker_trace(tls, _p, str(1239), unsafe.Pointer(bin.Xsqlite3_sql(tls, _pStmt))) 365 _rc = bin.Xsqlite3_step(tls, _pStmt) 366 if _rc != int32(100) { 367 _worker_error(tls, _p, str(1250), unsafe.Pointer(bin.Xsqlite3_sql(tls, _pStmt))) 368 goto _10 369 } 370 if bin.Xsqlite3_column_int(tls, _pStmt, int32(0)) != int32(400) { 371 _worker_error(tls, _p, str(1269), bin.Xsqlite3_column_int(tls, _pStmt, int32(0))) 372 } 373 _10: 374 bin.Xsqlite3_finalize(tls, _pStmt) 375 if _p.XnErr != 0 { 376 goto _3 377 } 378 if ((_iOuter + _p.Xtid) % int32(3)) == int32(0) { 379 bin.Xsqlite3_db_release_memory(tls, (*bin.Xsqlite3)(_p.Xdb)) 380 _p.XnTest += 1 381 } 382 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 383 _run_sql(tls, _p, str(1286)) 384 _run_sql(tls, _p, str(1293)) 385 _run_sql(tls, _p, str(1325)) 386 _run_sql(tls, _p, str(1357)) 387 _run_sql(tls, _p, str(1389)) 388 _p.XnTest += 1 389 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 390 if _iOuter == _p.Xtid { 391 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 392 _run_sql(tls, _p, str(1399)) 393 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 394 } 395 _pStmt = _prep_sql(tls, _p.Xdb, str(1406), _p.Xtid, _p.Xtid, _p.Xtid) 396 _worker_trace(tls, _p, str(1239), unsafe.Pointer(bin.Xsqlite3_sql(tls, _pStmt))) 397 _i = int32(0) 398 _14: 399 if _i >= _p.XnWorker { 400 goto _17 401 } 402 _rc = bin.Xsqlite3_step(tls, _pStmt) 403 if _rc != int32(100) { 404 _worker_error(tls, _p, str(1250), unsafe.Pointer(bin.Xsqlite3_sql(tls, _pStmt))) 405 goto _17 406 } 407 crt.Xsched_yield(tls) 408 _i += 1 409 goto _14 410 _17: 411 bin.Xsqlite3_finalize(tls, _pStmt) 412 if _p.XnErr != 0 { 413 goto _3 414 } 415 _worker_delete_all_content(tls, _p, (_p.Xtid+_iOuter)%int32(2)) 416 _worker_close_connection(tls, _p) 417 _p.Xdb = nil 418 _iOuter += 1 419 goto _0 420 _3: 421 _worker_close_connection(tls, _p) 422 crt.Xprintf(tls, str(1552), _p.Xtid) 423 crt.Xfflush(tls, (*crt.XFILE)(Xstdout)) 424 return nil 425 } 426 427 // C comment 428 // /* 429 // ** Open the database connection for WorkerInfo. The order in which 430 // ** the files are opened is a function of the tid value. 431 // */ 432 func _worker_open_connection(tls *crt.TLS, _p *XWorkerInfo, _iCnt int32) { 433 var _x, _rc int32 434 var _zFile *int8 435 _x = (_p.Xtid + _iCnt) % int32(6) 436 _zFile = bin.Xsqlite3_mprintf(tls, str(1572), int32(*elem4((*uint8)(unsafe.Pointer(elem5((*[3]uint8)(unsafe.Pointer(&_worker_open_connectionØ00aOrderØ001)), uintptr(_x)))), 0))) 437 _check_oom(tls, unsafe.Pointer(_zFile)) 438 _worker_trace(tls, _p, str(1586), unsafe.Pointer(_zFile)) 439 _rc = bin.Xsqlite3_open_v2(tls, _zFile, (**bin.Xsqlite3)(unsafe.Pointer(&_p.Xdb)), int32(131074), nil) 440 if _rc != int32(0) { 441 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(1594), unsafe.Pointer(_zFile), _p.Xtid) 442 crt.Xexit(tls, int32(1)) 443 } 444 bin.Xsqlite3_free(tls, unsafe.Pointer(_zFile)) 445 _run_sql(tls, _p, str(1634)) 446 bin.Xsqlite3_busy_timeout(tls, (*bin.Xsqlite3)(_p.Xdb), int32(10000)) 447 _run_sql(tls, _p, str(1662)) 448 _run_sql(tls, _p, str(1686), int32(*elem4((*uint8)(unsafe.Pointer(elem5((*[3]uint8)(unsafe.Pointer(&_worker_open_connectionØ00aOrderØ001)), uintptr(_x)))), uintptr(1)))) 449 _run_sql(tls, _p, str(1717), int32(*elem4((*uint8)(unsafe.Pointer(elem5((*[3]uint8)(unsafe.Pointer(&_worker_open_connectionØ00aOrderØ001)), uintptr(_x)))), uintptr(2)))) 450 } 451 452 var _worker_open_connectionØ00aOrderØ001 [6][3]uint8 453 454 func init() { 455 _worker_open_connectionØ00aOrderØ001 = [6][3]uint8{[3]uint8{uint8(1), uint8(2), uint8(3)}, [3]uint8{uint8(1), uint8(3), uint8(2)}, [3]uint8{uint8(2), uint8(1), uint8(3)}, [3]uint8{uint8(2), uint8(3), uint8(1)}, [3]uint8{uint8(3), uint8(1), uint8(2)}, [3]uint8{uint8(3), uint8(2), uint8(1)}} 456 } 457 458 // C comment 459 // /* 460 // ** Create rows mn through mx in table iTab for the given worker 461 // */ 462 func _worker_add_content(tls *crt.TLS, _p *XWorkerInfo, _mn int32, _mx int32, _iTab int32) { 463 var _zTabDef *int8 464 switch _iTab { 465 case int32(1): 466 goto _1 467 case int32(2): 468 goto _2 469 case int32(3): 470 goto _3 471 default: 472 goto _4 473 } 474 475 _1: 476 _zTabDef = str(1748) 477 goto _4 478 _2: 479 _zTabDef = str(1765) 480 goto _4 481 _3: 482 _zTabDef = str(1782) 483 goto _4 484 _4: 485 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 486 _run_sql(tls, _p, str(1799), _mn, _mx, unsafe.Pointer(_zTabDef), _p.Xtid) 487 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 488 _p.XnTest += 1 489 } 490 491 // C comment 492 // /* 493 // ** Prepare a single SQL query 494 // */ 495 func _prep_sql(tls *crt.TLS, _db unsafe.Pointer, _zFormat *int8, args ...interface{}) (r0 unsafe.Pointer) { 496 var _rc, _i int32 497 var _zSql *int8 498 var _pStmt unsafe.Pointer 499 var _ap []interface{} 500 _pStmt = nil 501 _ap = args 502 _zSql = bin.Xsqlite3_vmprintf(tls, _zFormat, _ap) 503 _ap = nil 504 _check_oom(tls, unsafe.Pointer(_zSql)) 505 _i = int32(0) 506 _0: 507 if _i >= int32(1000) { 508 goto _3 509 } 510 _rc = bin.Xsqlite3_prepare_v2(tls, (*bin.Xsqlite3)(_db), _zSql, int32(-1), &_pStmt, nil) 511 if _rc == int32(0) { 512 goto _3 513 } 514 _i += 1 515 goto _0 516 _3: 517 if _rc != int32(0) { 518 crt.Xfprintf(tls, (*crt.XFILE)(Xstderr), str(991), _rc, bin.Xsqlite3_extended_errcode(tls, (*bin.Xsqlite3)(_db)), unsafe.Pointer(bin.Xsqlite3_errmsg(tls, (*bin.Xsqlite3)(_db))), unsafe.Pointer(_zSql)) 519 crt.Xexit(tls, int32(1)) 520 } 521 bin.Xsqlite3_free(tls, unsafe.Pointer(_zSql)) 522 return _pStmt 523 } 524 525 // C comment 526 // /* 527 // ** Set an error message on a worker 528 // */ 529 func _worker_error(tls *crt.TLS, _p *XWorkerInfo, _zFormat *int8, args ...interface{}) { 530 var _ap []interface{} 531 _p.XnErr += 1 532 bin.Xsqlite3_free(tls, unsafe.Pointer(_p.XzMsg)) 533 _ap = args 534 _p.XzMsg = bin.Xsqlite3_vmprintf(tls, _zFormat, _ap) 535 _ap = nil 536 } 537 538 // C comment 539 // /* 540 // ** Delete all content in the three databases associated with a 541 // ** single thread. Make this happen all in a single transaction if 542 // ** inTrans is true, or separately for each database if inTrans is 543 // ** false. 544 // */ 545 func _worker_delete_all_content(tls *crt.TLS, _p *XWorkerInfo, _inTrans int32) { 546 if _inTrans != 0 { 547 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 548 _run_sql(tls, _p, str(1947)) 549 _run_sql(tls, _p, str(1953), _p.Xtid) 550 _run_sql(tls, _p, str(1981), _p.Xtid) 551 _run_sql(tls, _p, str(2009), _p.Xtid) 552 _run_sql(tls, _p, str(2037)) 553 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 554 _p.XnTest += 1 555 goto _1 556 } 557 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 558 _run_sql(tls, _p, str(1953), _p.Xtid) 559 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 560 _p.XnTest += 1 561 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 562 _run_sql(tls, _p, str(1981), _p.Xtid) 563 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 564 _p.XnTest += 1 565 crt.Xpthread_mutex_lock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 566 _run_sql(tls, _p, str(2009), _p.Xtid) 567 crt.Xpthread_mutex_unlock(tls, (*crt.Xpthread_mutex_t)(_p.XpWrMutex)) 568 _p.XnTest += 1 569 _1: 570 } 571 572 // C comment 573 // /* 574 // ** Close the worker database connection 575 // */ 576 func _worker_close_connection(tls *crt.TLS, _p *XWorkerInfo) { 577 if _p.Xdb != nil { 578 _worker_trace(tls, _p, str(2044)) 579 bin.Xsqlite3_close(tls, (*bin.Xsqlite3)(_p.Xdb)) 580 _p.Xdb = nil 581 } 582 } 583 584 func bool2int(b bool) int32 { 585 if b { 586 return 1 587 } 588 return 0 589 } 590 func bug20530(interface{}) {} //TODO remove when https://github.com/golang/go/issues/20530 is fixed. 591 func init() { nzf32 *= -1; nzf64 *= -1 } 592 593 var inf = math.Inf(1) 594 var nzf32 float32 // -0.0 595 var nzf64 float64 // -0.0 596 func elem0(a **int8, index uintptr) **int8 { 597 return (**int8)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + 4*index)) 598 } 599 func elem5(a *[3]uint8, index uintptr) *[3]uint8 { 600 return (*[3]uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + 3*index)) 601 } 602 func elem1(a *int8, index uintptr) *int8 { 603 return (*int8)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + 1*index)) 604 } 605 func elem2(a *XWorkerInfo, index uintptr) *XWorkerInfo { 606 return (*XWorkerInfo)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + 40*index)) 607 } 608 func elem4(a *uint8, index uintptr) *uint8 { 609 return (*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + 1*index)) 610 } 611 func store3(p *int32, v int32) int32 { *p = v; return v } 612 613 type XWorkerInfo struct { 614 Xtid int32 615 XnWorker int32 616 XwkrFlags uint32 617 XmainDb unsafe.Pointer 618 Xdb unsafe.Pointer 619 XnErr int32 620 XnTest int32 621 XzMsg *int8 622 Xid uint32 623 XpWrMutex unsafe.Pointer 624 } // t6 struct{tid int32,nWorker int32,wkrFlags uint32,mainDb *struct{},db *struct{},nErr int32,nTest int32,zMsg *int8,id uint32,pWrMutex *struct{}} 625 func str(n int) *int8 { return (*int8)(unsafe.Pointer(&strTab[n])) } 626 func wstr(n int) *int32 { return (*int32)(unsafe.Pointer(&strTab[n])) } 627 628 var strTab = []byte("-multithread\x00-serialized\x00-wal\x00-trace\x00unknown command-line option: %s\x0a\x00minimum of 2 threads\x0a\x00extra command-line argument: \"%s\"\x0a\x00usage: %s ?OPTIONS? N\x0aN is the number of threads and must be at least 2.\x0aOptions:\x0a --serialized\x0a --multithread\x0a --wal\x0a --trace\x0a\x00requires a threadsafe build of SQLite\x0a\x00tt4-test1.db\x00tt4-test2.db\x00tt4-test3.db\x00Unable to open test database: tt4-test2.db\x0a\x00PRAGMA journal_mode=WAL\x00PRAGMA synchronous=OFF\x00CREATE TABLE IF NOT EXISTS t1(tid INTEGER, sp, a, b, c)\x00CREATE INDEX t1tid ON t1(tid)\x00CREATE INDEX t1ab ON t1(a,b)\x00ATTACH 'tt4-test2.db' AS 'test2'\x00CREATE TABLE IF NOT EXISTS test2.t2(tid INTEGER, sp, d, e, f)\x00CREATE INDEX test2.t2tid ON t2(tid)\x00CREATE INDEX test2.t2de ON t2(d,e)\x00ATTACH 'tt4-test3.db' AS 'test3'\x00CREATE TABLE IF NOT EXISTS test3.t3(tid INTEGER, sp, x, y, z)\x00CREATE INDEX test3.t3tid ON t3(tid)\x00CREATE INDEX test3.t3xy ON t3(x,y)\x00thread creation failed for thread %d\x0a\x00Joined thread %d: %d errors in %d tests\x00: %s\x0a\x00\x0a\x00Total %d errors in %d tests\x0a\x00SQL error (%d,%d): %s\x0aWhile preparing: [%s]\x0a\x00running [%s]\x00retry %d for [%s]\x00Deadlock in thread %d while running [%s]\x0a\x00SQL error (%d,%d): %s\x0aWhile running [%s]\x0a\x00out of memory\x0a\x00TRACE(%02d): %s\x0a\x00worker %d startup\x0a\x00SELECT count(a) FROM t1 WHERE tid=%d\x00query [%s]\x00Failed to step: %s\x00Wrong result: %d\x00BEGIN;\x00UPDATE t1 SET c=NULL WHERE a=55\x00UPDATE t2 SET f=NULL WHERE d=42\x00UPDATE t3 SET z=NULL WHERE x=31\x00ROLLBACK;\x00VACUUM\x00SELECT t1.rowid, t2.rowid, t3.rowid FROM t1, t2, t3 WHERE t1.tid=%d AND t2.tid=%d AND t3.tid=%d AND t1.a<>t2.d AND t2.d<>t3.x ORDER BY 1, 2, 3\x00worker %d finished\x0a\x00tt4-test%d.db\x00open %s\x00sqlite_open_v2(%s) failed on thread %d\x0a\x00PRAGMA read_uncommitted=ON;\x00PRAGMA synchronous=OFF;\x00ATTACH 'tt4-test%d.db' AS aux1\x00ATTACH 'tt4-test%d.db' AS aux2\x00t1(tid,sp,a,b,c)\x00t2(tid,sp,d,e,f)\x00t3(tid,sp,x,y,z)\x00WITH RECURSIVE\x0a c(i) AS (VALUES(%d) UNION ALL SELECT i+1 FROM c WHERE i<%d)\x0aINSERT INTO %s SELECT %d, zeroblob(3000), i, printf('%%d',i), i FROM c;\x00BEGIN\x00DELETE FROM t1 WHERE tid=%d\x00DELETE FROM t2 WHERE tid=%d\x00DELETE FROM t3 WHERE tid=%d\x00COMMIT\x00close\x00")