Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch novem Excluding Merge-Ins
This is equivalent to a diff from 399176ec08 to 7bdc74993a
2019-10-31
| ||
12:45 | Merge 2.9 check-in: 5754e66b70 user: jan.nijtmans tags: trunk | |
12:44 | Merge 2.8 check-in: 15fbc9a901 user: jan.nijtmans tags: trunk | |
2019-09-29
| ||
13:46 | Merge 2.9 Closed-Leaf check-in: 7bdc74993a user: jan.nijtmans tags: novem | |
13:45 | Merge 2.8 check-in: 399176ec08 user: jan.nijtmans tags: trunk | |
13:18 | Update to latest rules.vc check-in: 361a9314d2 user: jan.nijtmans tags: thread-2-8-branch | |
2019-09-20
| ||
09:45 | Merge 2.9 check-in: 6e8834a6a0 user: jan.nijtmans tags: novem | |
09:44 | Merge 2.8 check-in: 5495f6cad5 user: jan.nijtmans tags: trunk | |
Changes to Makefile.in.
︙ | ︙ | |||
152 153 154 155 156 157 158 | # TCL_DEFS is not strictly need here, but if you remove it, then you # must make sure that configure.ac checks for the necessary components # that your library may use. TCL_DEFS can actually be a problem if # you do not compile with a similar machine setup as the Tcl core was # compiled with. #DEFS = $(TCL_DEFS) @DEFS@ $(PKG_CFLAGS) | | | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | # TCL_DEFS is not strictly need here, but if you remove it, then you # must make sure that configure.ac checks for the necessary components # that your library may use. TCL_DEFS can actually be a problem if # you do not compile with a similar machine setup as the Tcl core was # compiled with. #DEFS = $(TCL_DEFS) @DEFS@ $(PKG_CFLAGS) DEFS = @DEFS@ $(PKG_CFLAGS) # Move pkgIndex.tcl to 'BINARIES' var if it is generated in the Makefile CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl CLEANFILES = @CLEANFILES@ CPPFLAGS = @CPPFLAGS@ LIBS = @PKG_LIBS@ @LIBS@ |
︙ | ︙ |
Changes to configure.
1 2 | #! /bin/sh # Guess values for system-dependent variables and create Makefiles. | | | 1 2 3 4 5 6 7 8 9 10 | #! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for thread 3.0a1. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. |
︙ | ︙ | |||
573 574 575 576 577 578 579 | subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='thread' PACKAGE_TARNAME='thread' | | | | 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='thread' PACKAGE_TARNAME='thread' PACKAGE_VERSION='3.0a1' PACKAGE_STRING='thread 3.0a1' PACKAGE_BUGREPORT='' PACKAGE_URL='' # Factoring default headers for most tests. ac_includes_default="\ #include <stdio.h> #ifdef HAVE_SYS_TYPES_H |
︙ | ︙ | |||
1290 1291 1292 1293 1294 1295 1296 | # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF | | | 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures thread 3.0a1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. |
︙ | ︙ | |||
1351 1352 1353 1354 1355 1356 1357 | cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in | | | 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of thread 3.0a1:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] |
︙ | ︙ | |||
1454 1455 1456 1457 1458 1459 1460 | cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF | | | 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 | cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF thread configure 3.0a1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit |
︙ | ︙ | |||
1732 1733 1734 1735 1736 1737 1738 | eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. | | | 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 | eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by thread $as_me 3.0a1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { |
︙ | ︙ | |||
3390 3391 3392 3393 3394 3395 3396 |
| | > | < < < | 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 | if test "${TCL_MAJOR_VERSION}" -eq 8 ; then if test "${TCL_MINOR_VERSION}" -lt 6 ; then as_fn_error $? "${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.6+ Found config for Tcl ${TCL_VERSION}" "$LINENO" 5 fi fi #-------------------------------------------------------------------- # Load the tkConfig.sh file if necessary (Tk extension) #-------------------------------------------------------------------- #TEA_PATH_TKCONFIG |
︙ | ︙ | |||
8763 8764 8765 8766 8767 8768 8769 | test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" | | | 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 | test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by thread $as_me 3.0a1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ |
︙ | ︙ | |||
8816 8817 8818 8819 8820 8821 8822 | Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ | | | 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 | Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ thread config.status 3.0a1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." |
︙ | ︙ |
Changes to configure.ac.
︙ | ︙ | |||
13 14 15 16 17 18 19 | # Set your package name and version numbers here. # # This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION # set as provided. These will also be added as -D defs in your Makefile # so you can encode the package version directly into the source files. #----------------------------------------------------------------------- | | | > | < < < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # Set your package name and version numbers here. # # This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION # set as provided. These will also be added as -D defs in your Makefile # so you can encode the package version directly into the source files. #----------------------------------------------------------------------- AC_INIT([thread], [3.0a1]) #-------------------------------------------------------------------- # Call TEA_INIT as the first TEA_ macro to set up initial vars. # This will define a ${TEA_PLATFORM} variable == "unix" or "windows" # as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE. #-------------------------------------------------------------------- TEA_INIT() AC_CONFIG_AUX_DIR(tclconfig) #-------------------------------------------------------------------- # Load the tclConfig.sh file #-------------------------------------------------------------------- TEA_PATH_TCLCONFIG TEA_LOAD_TCLCONFIG if test "${TCL_MAJOR_VERSION}" -eq 8 ; then if test "${TCL_MINOR_VERSION}" -lt 6 ; then AC_MSG_ERROR([${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 8.6+ Found config for Tcl ${TCL_VERSION}]) fi fi #-------------------------------------------------------------------- # Load the tkConfig.sh file if necessary (Tk extension) #-------------------------------------------------------------------- #TEA_PATH_TKCONFIG |
︙ | ︙ |
Changes to doc/html/ttrace.html.
︙ | ︙ | |||
148 149 150 151 152 153 154 | <p>The package requires Tcl threading extension but can be alternatively used stand-alone within the AOLserver, a scalable webserver from America Online.</p> <p>In a nutshell, a short sample illustrating the usage of the ttrace with the Tcl threading extension:</p> <pre class="doctools_example"> % package require Ttrace | | | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | <p>The package requires Tcl threading extension but can be alternatively used stand-alone within the AOLserver, a scalable webserver from America Online.</p> <p>In a nutshell, a short sample illustrating the usage of the ttrace with the Tcl threading extension:</p> <pre class="doctools_example"> % package require Ttrace 2.8.1 % set t1 [thread::create {package require Ttrace; thread::wait}] tid0x1802800 % ttrace::eval {proc test args {return test-[thread::id]}} % thread::send $t1 test test-tid0x1802800 % set t2 [thread::create {package require Ttrace; thread::wait}] tid0x1804000 |
︙ | ︙ |
Changes to doc/ttrace.man.
︙ | ︙ | |||
17 18 19 20 21 22 23 | [para] In a nutshell, a short sample illustrating the usage of the ttrace with the Tcl threading extension: [example { % package require Ttrace | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | [para] In a nutshell, a short sample illustrating the usage of the ttrace with the Tcl threading extension: [example { % package require Ttrace 2.8.1 % set t1 [thread::create {package require Ttrace; thread::wait}] tid0x1802800 % ttrace::eval {proc test args {return test-[thread::id]}} % thread::send $t1 test test-tid0x1802800 |
︙ | ︙ |
Changes to generic/psGdbm.c.
︙ | ︙ | |||
79 80 81 82 83 84 85 | * Opaque handle of the opened dbm storage. * * Side effects: * The gdbm file might be created if not found. * *----------------------------------------------------------------------------- */ | | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | * Opaque handle of the opened dbm storage. * * Side effects: * The gdbm file might be created if not found. * *----------------------------------------------------------------------------- */ static void * ps_gdbm_open( const char *path) { GDBM_FILE dbf; char *ext; Tcl_DString toext; |
︙ | ︙ | |||
112 113 114 115 116 117 118 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int ps_gdbm_close( | | | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int ps_gdbm_close( void *handle) { gdbm_close((GDBM_FILE)handle); return 0; } /* |
︙ | ︙ | |||
137 138 139 140 141 142 143 | * Side effects: * Data returned must be freed by the caller. * *----------------------------------------------------------------------------- */ static int ps_gdbm_get( | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | * Side effects: * Data returned must be freed by the caller. * *----------------------------------------------------------------------------- */ static int ps_gdbm_get( void *handle, const char *key, char **dataptrptr, size_t *lenptr) { GDBM_FILE dbf = (GDBM_FILE)handle; datum drec, dkey; |
︙ | ︙ | |||
177 178 179 180 181 182 183 | * Side effects: * Data returned must be freed by the caller. * *----------------------------------------------------------------------------- */ static int ps_gdbm_first( | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | * Side effects: * Data returned must be freed by the caller. * *----------------------------------------------------------------------------- */ static int ps_gdbm_first( void *handle, char **keyptrptr, char **dataptrptr, size_t *lenptr) { GDBM_FILE dbf = (GDBM_FILE)handle; datum drec, dkey; |
︙ | ︙ | |||
218 219 220 221 222 223 224 | * * Side effects: * Data returned must be freed by the caller. * *----------------------------------------------------------------------------- */ static int ps_gdbm_next( | | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | * * Side effects: * Data returned must be freed by the caller. * *----------------------------------------------------------------------------- */ static int ps_gdbm_next( void *handle, char **keyptrptr, char **dataptrptr, size_t *lenptr) { GDBM_FILE dbf = (GDBM_FILE)handle; datum drec, dkey, dnext; |
︙ | ︙ | |||
266 267 268 269 270 271 272 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_gdbm_put( | | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_gdbm_put( void *handle, const char *key, char *dataptr, size_t len) { GDBM_FILE dbf = (GDBM_FILE)handle; datum drec, dkey; int ret; |
︙ | ︙ | |||
308 309 310 311 312 313 314 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_gdbm_delete( | | | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_gdbm_delete( void *handle, const char *key) { GDBM_FILE dbf = (GDBM_FILE)handle; datum dkey; int ret; dkey.dptr = (char*)key; |
︙ | ︙ | |||
343 344 345 346 347 348 349 | * Side effects: * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void ps_gdbm_free( | | | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | * Side effects: * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void ps_gdbm_free( void *handle, void *data) { (void)handle; free(data); } /* |
︙ | ︙ | |||
368 369 370 371 372 373 374 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static const char* ps_gdbm_geterr( | | | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static const char* ps_gdbm_geterr( void *handle) { /* * The problem with gdbm interface is that it uses the global * gdbm_errno variable which is not per-thread nor mutex * protected. This variable is used to reference array of gdbm * error text strings. It is very dangeours to use this in the * MT-program without proper locking. For this kind of app |
︙ | ︙ |
Changes to generic/psLmdb.c.
︙ | ︙ | |||
146 147 148 149 150 151 152 | * Opaque handle for LmdbCtx. * * Side effects: * The lmdb file might be created if not found. * *----------------------------------------------------------------------------- */ | | | | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | * Opaque handle for LmdbCtx. * * Side effects: * The lmdb file might be created if not found. * *----------------------------------------------------------------------------- */ static void * ps_lmdb_open( const char *path) { LmdbCtx ctx; char *ext; Tcl_DString toext; ctx = Tcl_Alloc(sizeof(*ctx)); if (ctx == NULL) { return NULL; } ctx->env = NULL; ctx->txn = NULL; ctx->cur = NULL; ctx->dbi = 0; ctx->err = mdb_env_create(&ctx->env); if (ctx->err) { Tcl_Free(ctx); return NULL; } Tcl_DStringInit(&toext); ext = Tcl_UtfToExternalDString(NULL, path, strlen(path), &toext); ctx->err = mdb_env_open(ctx->env, ext, MDB_NOSUBDIR|MDB_NOLOCK, 0666); Tcl_DStringFree(&toext); if (ctx->err) { Tcl_Free(ctx); return NULL; } return ctx; } /* |
︙ | ︙ | |||
204 205 206 207 208 209 210 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int ps_lmdb_close( | | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int ps_lmdb_close( void *handle) { LmdbCtx ctx = (LmdbCtx)handle; if (ctx->cur) { mdb_cursor_close(ctx->cur); } if (ctx->txn) { LmdbTxnAbort(ctx); } mdb_env_close(ctx->env); Tcl_Free(ctx); return 0; } /* *----------------------------------------------------------------------------- * |
︙ | ︙ | |||
240 241 242 243 244 245 246 | * Side effects: * Data returned must be copied, then psFree must be called. * *----------------------------------------------------------------------------- */ static int ps_lmdb_get( | | | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | * Side effects: * Data returned must be copied, then psFree must be called. * *----------------------------------------------------------------------------- */ static int ps_lmdb_get( void *handle, const char *keyptr, char **dataptrptr, size_t *lenptr) { LmdbCtx ctx = (LmdbCtx)handle; MDB_val key, data; |
︙ | ︙ | |||
295 296 297 298 299 300 301 | * Side effects: * Data returned must be copied, then psFree must be called. * *----------------------------------------------------------------------------- */ static int ps_lmdb_first( | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | * Side effects: * Data returned must be copied, then psFree must be called. * *----------------------------------------------------------------------------- */ static int ps_lmdb_first( void *handle, char **keyptrptr, char **dataptrptr, size_t *lenptr) { LmdbCtx ctx = (LmdbCtx)handle; MDB_val key, data; |
︙ | ︙ | |||
348 349 350 351 352 353 354 | * * Side effects: * Data returned must be copied, then psFree must be called. * *----------------------------------------------------------------------------- */ static int ps_lmdb_next( | | | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | * * Side effects: * Data returned must be copied, then psFree must be called. * *----------------------------------------------------------------------------- */ static int ps_lmdb_next( void *handle, char **keyptrptr, char **dataptrptr, size_t *lenptr) { LmdbCtx ctx = (LmdbCtx)handle; MDB_val key, data; |
︙ | ︙ | |||
391 392 393 394 395 396 397 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_lmdb_put( | | | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_lmdb_put( void *handle, const char *keyptr, char *dataptr, size_t len) { LmdbCtx ctx = (LmdbCtx)handle; MDB_val key, data; |
︙ | ︙ | |||
443 444 445 446 447 448 449 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_lmdb_delete( | | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | * If the key is already associated with some user data, this will * be replaced by the new data chunk. * *----------------------------------------------------------------------------- */ static int ps_lmdb_delete( void *handle, const char *keyptr) { LmdbCtx ctx = (LmdbCtx)handle; MDB_val key; LmdbTxnGet(ctx, LmdbWrite); if (ctx->err) |
︙ | ︙ | |||
493 494 495 496 497 498 499 | * Side effects: * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void ps_lmdb_free( | | | 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | * Side effects: * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void ps_lmdb_free( void *handle, void *data) { LmdbCtx ctx = (LmdbCtx)handle; (void)data; if (ctx->cur == NULL) { |
︙ | ︙ | |||
523 524 525 526 527 528 529 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static const char* ps_lmdb_geterr( | | | 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static const char* ps_lmdb_geterr( void *handle) { LmdbCtx ctx = (LmdbCtx)handle; return mdb_strerror(ctx->err); } #endif /* HAVE_LMDB */ |
︙ | ︙ |
Changes to generic/tclThreadInt.h.
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #ifndef _TCL_THREAD_INT_H_ #define _TCL_THREAD_INT_H_ #include "tclThread.h" #include <stdlib.h> /* For strtoul */ #include <string.h> /* For memset and friends */ /* * MSVC 8.0 started to mark many standard C library functions depreciated * including the *printf family and others. Tell it to shut up. * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0) */ #if defined(_MSC_VER) | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #ifndef _TCL_THREAD_INT_H_ #define _TCL_THREAD_INT_H_ #include "tclThread.h" #include <stdlib.h> /* For strtoul */ #include <string.h> /* For memset and friends */ #include <stdarg.h> /* For va_list */ /* * MSVC 8.0 started to mark many standard C library functions depreciated * including the *printf family and others. Tell it to shut up. * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0) */ #if defined(_MSC_VER) |
︙ | ︙ | |||
52 53 54 55 56 57 58 | #ifdef NS_AOLSERVER # include <ns.h> # if !defined(NS_MAJOR_VERSION) || NS_MAJOR_VERSION < 4 # error "unsupported NaviServer/AOLserver version" # endif #endif | < < < < | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #ifdef NS_AOLSERVER # include <ns.h> # if !defined(NS_MAJOR_VERSION) || NS_MAJOR_VERSION < 4 # error "unsupported NaviServer/AOLserver version" # endif #endif /* * Allow for some command names customization. * Only thread:: and tpool:: are handled here. * Shared variable commands are more complicated. * Look into the threadSvCmd.h for more info. */ |
︙ | ︙ | |||
102 103 104 105 106 107 108 | if ((a)->prevPtr != NULL) \ (a)->prevPtr->nextPtr = (a)->nextPtr; \ else \ (b) = (a)->nextPtr; \ if ((a)->nextPtr != NULL) \ (a)->nextPtr->prevPtr = (a)->prevPtr | < < < < < < < < | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | if ((a)->prevPtr != NULL) \ (a)->prevPtr->nextPtr = (a)->nextPtr; \ else \ (b) = (a)->nextPtr; \ if ((a)->nextPtr != NULL) \ (a)->nextPtr->prevPtr = (a)->prevPtr /* * Utility macros */ #define TCL_CMD(a,b,c) \ if (Tcl_CreateObjCommand((a),(b),(c),NULL, NULL) == NULL) \ return TCL_ERROR |
︙ | ︙ | |||
136 137 138 139 140 141 142 | */ typedef struct { char *modname; char *server; } NsThreadInterpData; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | */ typedef struct { char *modname; char *server; } NsThreadInterpData; #if defined(USE_TCL_STUBS) # undef Tcl_GetUnicodeFromObj # define Tcl_GetUnicodeFromObj ((((&(tclStubsPtr->tcl_PkgProvideEx))[378]) != ((&(tclStubsPtr->tcl_PkgProvideEx))[434])) ? \ ((void (*)(Tcl_Obj *, int *))((&(tclStubsPtr->tcl_PkgProvideEx))[434])) : ((void (*)(Tcl_Obj *, int *)) NULL)) #endif #endif /* _TCL_THREAD_INT_H_ */ |
Changes to generic/tclXkeylist.c.
︙ | ︙ | |||
21 22 23 24 25 26 27 | * thread-safe and allow for this datatype to be used from within * the thread shared variables implementation. * * For any questions, contant Zoran Vasiljevic ([email protected]) *----------------------------------------------------------------------------- */ | < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | 21 22 23 24 25 26 27 28 29 30 31 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 | * thread-safe and allow for this datatype to be used from within * the thread shared variables implementation. * * For any questions, contant Zoran Vasiljevic ([email protected]) *----------------------------------------------------------------------------- */ #include "threadSvCmd.h" #include "tclXkeylist.h" #include <stdarg.h> /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* Stuff copied verbatim from the rest of TclX to avoid dependencies */ /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /* * Assert macro for use in TclX. Some GCCs libraries are missing a function * used by their macro, so we define out own. */ #ifdef TCLX_DEBUG # define TclX_Assert(expr) ((expr) ? NULL : \ panic("TclX assertion failure: %s:%d \"%s\"\n",\ __FILE__, __LINE__, "expr")) #else # define TclX_Assert(expr) #endif /* * Macro that behaves like strdup, only uses Tcl_Alloc. Also macro that does the * same with a string that might contain zero bytes, */ #define ckstrdup(sourceStr) \ (strcpy ((char *)Tcl_Alloc (strlen (sourceStr) + 1), sourceStr)) #define ckbinstrdup(sourceStr, length) \ ((char *) memcpy ((char *)Tcl_Alloc (length + 1), sourceStr, length + 1)) /* * Used to return argument messages by most commands. */ static const char *tclXWrongArgs = "wrong # args: "; static const Tcl_ObjType *listType; |
︙ | ︙ | |||
312 313 314 315 316 317 318 | Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Tcl_KeylsetObjCmd(void *clientData, Tcl_Interp *interp, | | | | | | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Tcl_KeylsetObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Tcl_KeyldelObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int Tcl_KeylkeysObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* * Type definition. */ const Tcl_ObjType keyedListType = { "keyedList", /* name */ FreeKeyedListInternalRep, /* freeIntRepProc */ DupKeyedListInternalRep, /* dupIntRepProc */ UpdateStringOfKeyedList, /* updateStringProc */ NULL /* setFromAnyProc */ }; /*----------------------------------------------------------------------------- * ValidateKeyedList -- * Validate a keyed list (only when TCLX_DEBUG is enabled). * Parameters: |
︙ | ︙ | |||
436 437 438 439 440 441 442 | *----------------------------------------------------------------------------- */ static keylIntObj_t * AllocKeyedListIntRep(void) { keylIntObj_t *keylIntPtr; | | | 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | *----------------------------------------------------------------------------- */ static keylIntObj_t * AllocKeyedListIntRep(void) { keylIntObj_t *keylIntPtr; keylIntPtr = (keylIntObj_t *)Tcl_Alloc(sizeof(keylIntObj_t)); keylIntPtr->arraySize = 0; keylIntPtr->numEntries = 0; keylIntPtr->entries = NULL; return keylIntPtr; } |
︙ | ︙ | |||
460 461 462 463 464 465 466 | static void FreeKeyedListData( keylIntObj_t *keylIntPtr ) { int idx; for (idx = 0; idx < keylIntPtr->numEntries ; idx++) { | | | | | | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | static void FreeKeyedListData( keylIntObj_t *keylIntPtr ) { int idx; for (idx = 0; idx < keylIntPtr->numEntries ; idx++) { Tcl_Free(keylIntPtr->entries[idx].key); Tcl_DecrRefCount (keylIntPtr->entries[idx].valuePtr); } if (keylIntPtr->entries != NULL) Tcl_Free(keylIntPtr->entries); Tcl_Free(keylIntPtr); } /*----------------------------------------------------------------------------- * EnsureKeyedListSpace -- * Ensure there is enough room in a keyed list array for a certain number * of entries, expanding if necessary. * |
︙ | ︙ | |||
491 492 493 494 495 496 497 | KEYL_REP_ASSERT (keylIntPtr); if ((keylIntPtr->arraySize - keylIntPtr->numEntries) < newNumEntries) { int newSize = keylIntPtr->arraySize + newNumEntries + KEYEDLIST_ARRAY_INCR_SIZE; if (keylIntPtr->entries == NULL) { keylIntPtr->entries = (keylEntry_t *) | | | | | 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | KEYL_REP_ASSERT (keylIntPtr); if ((keylIntPtr->arraySize - keylIntPtr->numEntries) < newNumEntries) { int newSize = keylIntPtr->arraySize + newNumEntries + KEYEDLIST_ARRAY_INCR_SIZE; if (keylIntPtr->entries == NULL) { keylIntPtr->entries = (keylEntry_t *) Tcl_Alloc(newSize * sizeof(keylEntry_t)); } else { keylIntPtr->entries = (keylEntry_t *) Tcl_Realloc(keylIntPtr->entries, newSize * sizeof(keylEntry_t)); } keylIntPtr->arraySize = newSize; } KEYL_REP_ASSERT (keylIntPtr); } |
︙ | ︙ | |||
519 520 521 522 523 524 525 | static void DeleteKeyedListEntry ( keylIntObj_t *keylIntPtr, int entryIdx ) { int idx; | | | 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | static void DeleteKeyedListEntry ( keylIntObj_t *keylIntPtr, int entryIdx ) { int idx; Tcl_Free(keylIntPtr->entries [entryIdx].key); Tcl_DecrRefCount (keylIntPtr->entries [entryIdx].valuePtr); for (idx = entryIdx; idx < keylIntPtr->numEntries - 1; idx++) keylIntPtr->entries [idx] = keylIntPtr->entries [idx + 1]; keylIntPtr->numEntries--; KEYL_REP_ASSERT (keylIntPtr); |
︙ | ︙ | |||
677 678 679 680 681 682 683 | keylIntObj_t *srcIntPtr = (keylIntObj_t *) srcPtr->internalRep.twoPtrValue.ptr1; keylIntObj_t *copyIntPtr; int idx; KEYL_REP_ASSERT (srcIntPtr); | | | | 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | keylIntObj_t *srcIntPtr = (keylIntObj_t *) srcPtr->internalRep.twoPtrValue.ptr1; keylIntObj_t *copyIntPtr; int idx; KEYL_REP_ASSERT (srcIntPtr); copyIntPtr = (keylIntObj_t *)Tcl_Alloc(sizeof(keylIntObj_t)); copyIntPtr->arraySize = srcIntPtr->arraySize; copyIntPtr->numEntries = srcIntPtr->numEntries; copyIntPtr->entries = (keylEntry_t *) Tcl_Alloc(copyIntPtr->arraySize * sizeof(keylEntry_t)); for (idx = 0; idx < srcIntPtr->numEntries ; idx++) { copyIntPtr->entries [idx].key = ckstrdup (srcIntPtr->entries [idx].key); copyIntPtr->entries [idx].valuePtr = srcIntPtr->entries [idx].valuePtr; Tcl_IncrRefCount (copyIntPtr->entries [idx].valuePtr); } |
︙ | ︙ | |||
719 720 721 722 723 724 725 | keylIntObj_t *srcIntPtr = (keylIntObj_t *) srcPtr->internalRep.twoPtrValue.ptr1; keylIntObj_t *copyIntPtr; int idx; KEYL_REP_ASSERT (srcIntPtr); | | | | 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | keylIntObj_t *srcIntPtr = (keylIntObj_t *) srcPtr->internalRep.twoPtrValue.ptr1; keylIntObj_t *copyIntPtr; int idx; KEYL_REP_ASSERT (srcIntPtr); copyIntPtr = (keylIntObj_t *)Tcl_Alloc(sizeof(keylIntObj_t)); copyIntPtr->arraySize = srcIntPtr->arraySize; copyIntPtr->numEntries = srcIntPtr->numEntries; copyIntPtr->entries = (keylEntry_t *) Tcl_Alloc(copyIntPtr->arraySize * sizeof(keylEntry_t)); for (idx = 0; idx < srcIntPtr->numEntries ; idx++) { copyIntPtr->entries [idx].key = ckstrdup (srcIntPtr->entries [idx].key); copyIntPtr->entries [idx].valuePtr = Sv_DuplicateObj (srcIntPtr->entries [idx].valuePtr); Tcl_IncrRefCount(copyIntPtr->entries [idx].valuePtr); |
︙ | ︙ | |||
755 756 757 758 759 760 761 | */ static int SetKeyedListFromAny( Tcl_Interp *interp, Tcl_Obj *objPtr ) { keylIntObj_t *keylIntPtr; | | > | 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | */ static int SetKeyedListFromAny( Tcl_Interp *interp, Tcl_Obj *objPtr ) { keylIntObj_t *keylIntPtr; int idx; int objc; Tcl_Obj **objv; if (Tcl_ListObjGetElements (interp, objPtr, &objc, &objv) != TCL_OK) return TCL_ERROR; keylIntPtr = AllocKeyedListIntRep (); |
︙ | ︙ | |||
811 812 813 814 815 816 817 | keylIntObj_t *keylIntPtr = (keylIntObj_t *) keylPtr->internalRep.twoPtrValue.ptr1; /* * Conversion to strings is done via list objects to support binary data. */ if (keylIntPtr->numEntries > UPDATE_STATIC_SIZE) { | | | | 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | keylIntObj_t *keylIntPtr = (keylIntObj_t *) keylPtr->internalRep.twoPtrValue.ptr1; /* * Conversion to strings is done via list objects to support binary data. */ if (keylIntPtr->numEntries > UPDATE_STATIC_SIZE) { listObjv = (Tcl_Obj **) Tcl_Alloc(keylIntPtr->numEntries * sizeof(Tcl_Obj *)); } else { listObjv = staticListObjv; } /* * Convert each keyed list entry to a two element list object. No * need to incr/decr ref counts, the list objects will take care of that. |
︙ | ︙ | |||
837 838 839 840 841 842 843 | tmpListObj = Tcl_NewListObj (keylIntPtr->numEntries, listObjv); listStr = Tcl_GetString(tmpListObj); keylPtr->bytes = ckbinstrdup(listStr, tmpListObj->length); keylPtr->length = tmpListObj->length; Tcl_DecrRefCount (tmpListObj); if (listObjv != staticListObjv) | | | 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | tmpListObj = Tcl_NewListObj (keylIntPtr->numEntries, listObjv); listStr = Tcl_GetString(tmpListObj); keylPtr->bytes = ckbinstrdup(listStr, tmpListObj->length); keylPtr->length = tmpListObj->length; Tcl_DecrRefCount (tmpListObj); if (listObjv != staticListObjv) Tcl_Free(listObjv); } /*----------------------------------------------------------------------------- * TclX_NewKeyedListObj -- * Create and initialize a new keyed list object. * * Returns: |
︙ | ︙ | |||
967 968 969 970 971 972 973 | */ if (nextSubKey == NULL) { if (findIdx < 0) { EnsureKeyedListSpace (keylIntPtr, 1); findIdx = keylIntPtr->numEntries; keylIntPtr->numEntries++; } else { | | | | | 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 | */ if (nextSubKey == NULL) { if (findIdx < 0) { EnsureKeyedListSpace (keylIntPtr, 1); findIdx = keylIntPtr->numEntries; keylIntPtr->numEntries++; } else { Tcl_Free(keylIntPtr->entries [findIdx].key); Tcl_DecrRefCount (keylIntPtr->entries [findIdx].valuePtr); } keylIntPtr->entries [findIdx].key = (char *) Tcl_Alloc(keyLen + 1); strncpy (keylIntPtr->entries [findIdx].key, key, keyLen); keylIntPtr->entries [findIdx].key [keyLen] = '\0'; keylIntPtr->entries [findIdx].valuePtr = valuePtr; Tcl_IncrRefCount (valuePtr); Tcl_InvalidateStringRep (keylPtr); KEYL_REP_ASSERT (keylIntPtr); |
︙ | ︙ | |||
1009 1010 1011 1012 1013 1014 1015 | if (TclX_KeyedListSet (interp, newKeylPtr, nextSubKey, valuePtr) != TCL_OK) { Tcl_DecrRefCount (newKeylPtr); return TCL_ERROR; } EnsureKeyedListSpace (keylIntPtr, 1); findIdx = keylIntPtr->numEntries++; | | | | 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | if (TclX_KeyedListSet (interp, newKeylPtr, nextSubKey, valuePtr) != TCL_OK) { Tcl_DecrRefCount (newKeylPtr); return TCL_ERROR; } EnsureKeyedListSpace (keylIntPtr, 1); findIdx = keylIntPtr->numEntries++; keylIntPtr->entries [findIdx].key = (char *) Tcl_Alloc(keyLen + 1); strncpy (keylIntPtr->entries [findIdx].key, key, keyLen); keylIntPtr->entries [findIdx].key [keyLen] = '\0'; keylIntPtr->entries [findIdx].valuePtr = newKeylPtr; Tcl_IncrRefCount (newKeylPtr); Tcl_InvalidateStringRep (keylPtr); KEYL_REP_ASSERT (keylIntPtr); |
︙ | ︙ | |||
1442 1443 1444 1445 1446 1447 1448 | *----------------------------------------------------------------------------- */ void TclX_KeyedListInit( Tcl_Interp *interp ) { Tcl_Obj *listobj; | < | 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 | *----------------------------------------------------------------------------- */ void TclX_KeyedListInit( Tcl_Interp *interp ) { Tcl_Obj *listobj; listobj = Tcl_NewObj(); listobj = Tcl_NewListObj(1, &listobj); listType = listobj->typePtr; Tcl_DecrRefCount(listobj); if (0) { |
︙ | ︙ |
Changes to generic/tclXkeylist.h.
︙ | ︙ | |||
36 37 38 39 40 41 42 | * to be able to plug-in our custom keyed-list * object duplicator which produces proper deep * copies of the keyed-list objects. The standard * one produces shallow copies which are not good * for usage in the thread shared variables code. */ | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | * to be able to plug-in our custom keyed-list * object duplicator which produces proper deep * copies of the keyed-list objects. The standard * one produces shallow copies which are not good * for usage in the thread shared variables code. */ MODULE_SCOPE const Tcl_ObjType keyedListType; /* * Exported for usage in Sv_DuplicateObj. This is slightly * modified version of the DupKeyedListInternalRep() function. * It does a proper deep-copy of the keyed list object. */ |
︙ | ︙ |
Changes to generic/threadCmd.c.
︙ | ︙ | |||
24 25 26 27 28 29 30 | /* * Provide package version in build contexts which do not provide * -DPACKAGE_VERSION, like building a shell with the Thread object * files built as part of that shell. Example: basekits. */ #ifndef PACKAGE_VERSION | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /* * Provide package version in build contexts which do not provide * -DPACKAGE_VERSION, like building a shell with the Thread object * files built as part of that shell. Example: basekits. */ #ifndef PACKAGE_VERSION #define PACKAGE_VERSION "3.0a1" #endif /* * Access to the list of threads and to the thread send results * (defined below) is guarded by this mutex. */ |
︙ | ︙ | |||
145 146 147 148 149 150 151 | /* * Used to represent the empty result. */ static char *threadEmptyResult = (char *)""; | < < | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | /* * Used to represent the empty result. */ static char *threadEmptyResult = (char *)""; /* * An instance of the following structure contains all information that is * passed into a new thread when the thread is created using either the * "thread create" Tcl command or the ThreadCreate() C function. */ typedef struct ThreadCtrl { char *script; /* Script to execute */ int flags; /* Initial value of the "flags" * field in ThreadSpecificData */ Tcl_Condition condWait; /* Condition variable used to * sync parent and child threads */ void *cd; /* Opaque ptr to pass to thread */ } ThreadCtrl; /* * Structure holding result of the command executed in target thread. */ typedef struct ThreadEventResult { |
︙ | ︙ | |||
199 200 201 202 203 204 205 | Tcl_Event event; /* Must be first */ struct ThreadSendData *sendData; /* See below */ struct ThreadClbkData *clbkData; /* See below */ struct ThreadEventResult *resultPtr; /* To communicate the result back. * NULL if we don't care about it */ } ThreadEvent; | | | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | Tcl_Event event; /* Must be first */ struct ThreadSendData *sendData; /* See below */ struct ThreadClbkData *clbkData; /* See below */ struct ThreadEventResult *resultPtr; /* To communicate the result back. * NULL if we don't care about it */ } ThreadEvent; typedef int (ThreadSendProc) (Tcl_Interp*, void *); typedef void (ThreadSendFree) (void *); static ThreadSendProc ThreadSendEval; /* Does a regular Tcl_Eval */ static ThreadSendProc ThreadClbkSetVar; /* Sets the named variable */ static ThreadSendProc ThreadClbkCommand; /* Sets the named variable */ /* * These structures are used to communicate commands between source and target * threads. The ThreadSendData is used for source->target command passing, * while the ThreadClbkData is used for doing asynchronous callbacks. * * Important: structures below must have first three elements identical! */ typedef struct ThreadSendData { ThreadSendProc *execProc; /* Func to exec in remote thread */ void *clientData; /* Ptr to pass to send function */ ThreadSendFree *freeProc; /* Function to free client data */ /* ---- */ Tcl_Interp *interp; /* Interp to run the command */ } ThreadSendData; typedef struct ThreadClbkData { ThreadSendProc *execProc; /* The callback function */ void *clientData; /* Ptr to pass to clbk function */ ThreadSendFree *freeProc; /* Function to free client data */ /* ---- */ Tcl_Interp *interp; /* Interp to run the command */ Tcl_ThreadId threadId; /* Thread where to post callback */ ThreadEventResult result; /* Returns result asynchronously */ } ThreadClbkData; |
︙ | ︙ | |||
284 285 286 287 288 289 290 | /* * Miscellaneous functions used within this file */ static Tcl_EventDeleteProc ThreadDeleteEvent; static Tcl_ThreadCreateType | | | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | /* * Miscellaneous functions used within this file */ static Tcl_EventDeleteProc ThreadDeleteEvent; static Tcl_ThreadCreateType NewThread(void *clientData); static ThreadSpecificData* ThreadExistsInner(Tcl_ThreadId id); static int ThreadInit(Tcl_Interp *interp); |
︙ | ︙ | |||
339 340 341 342 343 344 345 | static int ThreadList(Tcl_Interp *interp, Tcl_ThreadId **thrIdArray); static void ThreadErrorProc(Tcl_Interp *interp); static void | | | | | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | static int ThreadList(Tcl_Interp *interp, Tcl_ThreadId **thrIdArray); static void ThreadErrorProc(Tcl_Interp *interp); static void ThreadFreeProc(void *clientData); static void ThreadExitProc(void *clientData); static void ThreadFreeError(void *clientData); static void ListRemove(ThreadSpecificData *tsdPtr); static void ListRemoveInner(ThreadSpecificData *tsdPtr); |
︙ | ︙ | |||
391 392 393 394 395 396 397 | static void ErrorNoSuchThread(Tcl_Interp *interp, Tcl_ThreadId thrId); static void ThreadCutChannel(Tcl_Interp *interp, Tcl_Channel channel); | < < | 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | static void ErrorNoSuchThread(Tcl_Interp *interp, Tcl_ThreadId thrId); static void ThreadCutChannel(Tcl_Interp *interp, Tcl_Channel channel); static int ThreadCancel(Tcl_Interp *interp, Tcl_ThreadId thrId, const char *result, int flags); /* * Functions implementing Tcl commands */ static Tcl_ObjCmdProc ThreadCreateObjCmd; static Tcl_ObjCmdProc ThreadReserveObjCmd; |
︙ | ︙ | |||
420 421 422 423 424 425 426 | static Tcl_ObjCmdProc ThreadExistsObjCmd; static Tcl_ObjCmdProc ThreadConfigureObjCmd; static Tcl_ObjCmdProc ThreadErrorProcObjCmd; static Tcl_ObjCmdProc ThreadJoinObjCmd; static Tcl_ObjCmdProc ThreadTransferObjCmd; static Tcl_ObjCmdProc ThreadDetachObjCmd; static Tcl_ObjCmdProc ThreadAttachObjCmd; | < < < | > > | | < < < | < | | | < | | < < < < < < < < < < | | | | | | | | < < | < < | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | static Tcl_ObjCmdProc ThreadExistsObjCmd; static Tcl_ObjCmdProc ThreadConfigureObjCmd; static Tcl_ObjCmdProc ThreadErrorProcObjCmd; static Tcl_ObjCmdProc ThreadJoinObjCmd; static Tcl_ObjCmdProc ThreadTransferObjCmd; static Tcl_ObjCmdProc ThreadDetachObjCmd; static Tcl_ObjCmdProc ThreadAttachObjCmd; static Tcl_ObjCmdProc ThreadCancelObjCmd; static int ThreadInit( Tcl_Interp *interp /* The current Tcl interpreter */ ) { /* Tcl 8.6 interps are only supported on 32-bit machines. * Lower than that is never supported. Bye! */ const char *ver = (sizeof(size_t) == sizeof(int))? "8.6-": "9.0"; if (!((Tcl_InitStubs)(interp, ver, (TCL_MAJOR_VERSION<<8)|(TCL_MINOR_VERSION<<16), TCL_STUB_MAGIC))) { return TCL_ERROR; } if (threadMutex == NULL){ Tcl_MutexLock(&threadMutex); if (threadMutex == NULL){ /* If threadMutex==NULL here, it means that Tcl_MutexLock() is * a dummy function, which is the case in unthreaded Tcl */ const char *msg = "Tcl core wasn't compiled for threading"; Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1)); return TCL_ERROR; } Tcl_MutexUnlock(&threadMutex); } TCL_CMD(interp, THREAD_CMD_PREFIX"create", ThreadCreateObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"send", ThreadSendObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"broadcast", ThreadBroadcastObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"exit", ThreadExitObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"unwind", ThreadUnwindObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"id", ThreadIdObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"names", ThreadNamesObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"exists", ThreadExistsObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"wait", ThreadWaitObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"configure", ThreadConfigureObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"errorproc", ThreadErrorProcObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"preserve", ThreadReserveObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"release", ThreadReleaseObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"join", ThreadJoinObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"transfer", ThreadTransferObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"detach", ThreadDetachObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"attach", ThreadAttachObjCmd); TCL_CMD(interp, THREAD_CMD_PREFIX"cancel", ThreadCancelObjCmd); /* * Add shared variable commands */ Sv_Init(interp); |
︙ | ︙ | |||
589 590 591 592 593 594 595 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCreateObjCmd( | | | 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCreateObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int argc, rsrv = 0; const char *arg, *script; int flags = TCL_THREAD_NOFLAGS; |
︙ | ︙ | |||
640 641 642 643 644 645 646 | /* *---------------------------------------------------------------------- * * ThreadReserveObjCmd -- * * This procedure is invoked to process the "thread::preserve" and | | | < | | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | /* *---------------------------------------------------------------------- * * ThreadReserveObjCmd -- * * This procedure is invoked to process the "thread::preserve" and * "thread::release" Tcl commands. See the user documentation for * details on it does. * * Results: * A standard Tcl result. * * Side effects: * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadReserveObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_ThreadId thrId = NULL; Init(interp); |
︙ | ︙ | |||
697 698 699 700 701 702 703 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadReleaseObjCmd( | | | 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadReleaseObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int wait = 0; Tcl_ThreadId thrId = NULL; |
︙ | ︙ | |||
746 747 748 749 750 751 752 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadUnwindObjCmd( | | | 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadUnwindObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Init(interp); if (objc > 1) { |
︙ | ︙ | |||
781 782 783 784 785 786 787 | * Lots. improper clean up of resources. * *---------------------------------------------------------------------- */ static int ThreadExitObjCmd( | | | 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | * Lots. improper clean up of resources. * *---------------------------------------------------------------------- */ static int ThreadExitObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int status = 666; Init(interp); |
︙ | ︙ | |||
827 828 829 830 831 832 833 | * None. * *---------------------------------------------------------------------- */ static int ThreadIdObjCmd( | | | | 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | * None. * *---------------------------------------------------------------------- */ static int ThreadIdObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { char thrHandle[THREAD_HNDLMAXLEN]; Init(interp); if (objc > 1) { Tcl_WrongNumArgs(interp, 1, objv, NULL); return TCL_ERROR; } ThreadGetHandle(Tcl_GetCurrentThread(), thrHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_AUTO_LENGTH)); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
868 869 870 871 872 873 874 | * None. * *---------------------------------------------------------------------- */ static int ThreadNamesObjCmd( | | | 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | * None. * *---------------------------------------------------------------------- */ static int ThreadNamesObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ii, length; char *result, thrHandle[THREAD_HNDLMAXLEN]; Tcl_ThreadId *thrIdArray; |
︙ | ︙ | |||
904 905 906 907 908 909 910 | length = Tcl_DStringLength(&threadNames); result = Tcl_DStringValue(&threadNames); Tcl_SetObjResult(interp, Tcl_NewStringObj(result, length)); Tcl_DStringFree(&threadNames); | | | 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | length = Tcl_DStringLength(&threadNames); result = Tcl_DStringValue(&threadNames); Tcl_SetObjResult(interp, Tcl_NewStringObj(result, length)); Tcl_DStringFree(&threadNames); Tcl_Free(thrIdArray); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
929 930 931 932 933 934 935 | * *---------------------------------------------------------------------- */ static void threadSendFree(void *ptr) { | | | | 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | * *---------------------------------------------------------------------- */ static void threadSendFree(void *ptr) { Tcl_Free(ptr); } static void threadSendObjFree(void *ptr) { Tcl_DecrRefCount((Tcl_Obj *)ptr); } static int ThreadSendObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { size_t size; int cmd = 0, ret, ii = 0, flags = 0; Tcl_ThreadId thrId; |
︙ | ︙ | |||
1000 1001 1002 1003 1004 1005 1006 | } if (var && (flags & THREAD_SEND_WAIT) == 0) { if (thrId == Tcl_GetCurrentThread()) { /* * FIXME: Do something for callbacks to self */ | | | | | | 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 | } if (var && (flags & THREAD_SEND_WAIT) == 0) { if (thrId == Tcl_GetCurrentThread()) { /* * FIXME: Do something for callbacks to self */ Tcl_SetObjResult(interp, Tcl_NewStringObj("can't notify self", TCL_AUTO_LENGTH)); return TCL_ERROR; } /* * Prepare record for the callback. This is asynchronously * posted back to us when the target thread finishes processing. * We should do a vwait on the "var" to get notified. */ clbkPtr = (ThreadClbkData *)Tcl_Alloc(sizeof(ThreadClbkData)); if (cmd) { clbkPtr->execProc = ThreadClbkCommand; } else { clbkPtr->execProc = ThreadClbkSetVar; } clbkPtr->freeProc = threadSendObjFree; clbkPtr->interp = interp; clbkPtr->threadId = Tcl_GetCurrentThread(); clbkPtr->clientData = Sv_DuplicateObj(var); Tcl_IncrRefCount((Tcl_Obj *)clbkPtr->clientData); } /* * Prepare job record for the target thread */ sendPtr = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData)); sendPtr->interp = NULL; /* Signal to use thread main interp */ sendPtr->execProc = ThreadSendEval; sendPtr->freeProc = threadSendFree; sendPtr->clientData = memcpy(Tcl_Alloc(size), script, size); ret = ThreadSend(interp, thrId, sendPtr, clbkPtr, flags); if (var && (flags & THREAD_SEND_WAIT)) { /* * Leave job's result in passed variable |
︙ | ︙ | |||
1076 1077 1078 1079 1080 1081 1082 | * Script is sent to all known threads except the caller thread. * *---------------------------------------------------------------------- */ static int ThreadBroadcastObjCmd( | | | 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | * Script is sent to all known threads except the caller thread. * *---------------------------------------------------------------------- */ static int ThreadBroadcastObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ii, nthreads; size_t size; const char *script; |
︙ | ︙ | |||
1132 1133 1134 1135 1136 1137 1138 | * to the head of the event queue (as out-of-band message). */ for (ii = 0; ii < nthreads; ii++) { if (thrIdArray[ii] == Tcl_GetCurrentThread()) { continue; /* Do not broadcast self */ } | | | | | 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | * to the head of the event queue (as out-of-band message). */ for (ii = 0; ii < nthreads; ii++) { if (thrIdArray[ii] == Tcl_GetCurrentThread()) { continue; /* Do not broadcast self */ } sendPtr = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData)); *sendPtr = job; sendPtr->clientData = memcpy(Tcl_Alloc(size), script, size); ThreadSend(interp, thrIdArray[ii], sendPtr, NULL, THREAD_SEND_HEAD); } Tcl_Free(thrIdArray); Tcl_ResetResult(interp); return TCL_OK; } /* *---------------------------------------------------------------------- |
︙ | ︙ | |||
1163 1164 1165 1166 1167 1168 1169 | * Enters the event loop. * *---------------------------------------------------------------------- */ static int ThreadWaitObjCmd( | | | 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | * Enters the event loop. * *---------------------------------------------------------------------- */ static int ThreadWaitObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Init(interp); if (objc > 1) { |
︙ | ︙ | |||
1199 1200 1201 1202 1203 1204 1205 | * Registers an errorproc. * *---------------------------------------------------------------------- */ static int ThreadErrorProcObjCmd( | | | | | | | | 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | * Registers an errorproc. * *---------------------------------------------------------------------- */ static int ThreadErrorProcObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { size_t len; char *proc; Init(interp); if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "?proc?"); return TCL_ERROR; } Tcl_MutexLock(&threadMutex); if (objc == 1) { if (errorProcString) { Tcl_SetObjResult(interp, Tcl_NewStringObj(errorProcString, TCL_AUTO_LENGTH)); } } else { if (errorProcString) { Tcl_Free(errorProcString); } proc = Tcl_GetString(objv[1]); len = objv[1]->length; if (len == 0) { errorThreadId = NULL; errorProcString = NULL; } else { errorThreadId = Tcl_GetCurrentThread(); errorProcString = (char *)Tcl_Alloc(1+strlen(proc)); strcpy(errorProcString, proc); Tcl_DeleteThreadExitHandler(ThreadFreeError, NULL); Tcl_CreateThreadExitHandler(ThreadFreeError, NULL); } } Tcl_MutexUnlock(&threadMutex); return TCL_OK; } static void ThreadFreeError( void *clientData ) { Tcl_MutexLock(&threadMutex); if (errorThreadId != Tcl_GetCurrentThread()) { Tcl_MutexUnlock(&threadMutex); return; } Tcl_Free(errorProcString); errorThreadId = NULL; errorProcString = NULL; Tcl_MutexUnlock(&threadMutex); } /* *---------------------------------------------------------------------- |
︙ | ︙ | |||
1274 1275 1276 1277 1278 1279 1280 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadJoinObjCmd( | | | 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadJoinObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_ThreadId thrId; Init(interp); |
︙ | ︙ | |||
1318 1319 1320 1321 1322 1323 1324 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadTransferObjCmd( | | | 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadTransferObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_ThreadId thrId; Tcl_Channel chan; |
︙ | ︙ | |||
1368 1369 1370 1371 1372 1373 1374 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadDetachObjCmd( | | | 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadDetachObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_Channel chan; Init(interp); |
︙ | ︙ | |||
1413 1414 1415 1416 1417 1418 1419 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadAttachObjCmd( | | | 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadAttachObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { char *chanName; Init(interp); |
︙ | ︙ | |||
1458 1459 1460 1461 1462 1463 1464 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadExistsObjCmd( | | | 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadExistsObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_ThreadId thrId; Init(interp); |
︙ | ︙ | |||
1498 1499 1500 1501 1502 1503 1504 | * * Side effects: * None. *---------------------------------------------------------------------- */ static int ThreadConfigureObjCmd( | | | 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 | * * Side effects: * None. *---------------------------------------------------------------------- */ static int ThreadConfigureObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { char *option, *value; Tcl_ThreadId thrId; /* Id of the thread to configure */ int i; /* Iterate over arg-value pairs. */ |
︙ | ︙ | |||
1550 1551 1552 1553 1554 1555 1556 | return TCL_ERROR; } } return TCL_OK; } | < | | 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 | return TCL_ERROR; } } return TCL_OK; } /* *---------------------------------------------------------------------- * * ThreadCancelObjCmd -- * * This procedure is invoked to process the "thread::cancel" Tcl * command. See the user documentation for details on what it does. * * Results: * A standard Tcl result. * * Side effects: * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCancelObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_ThreadId thrId; int ii, flags; const char *result; |
︙ | ︙ | |||
1606 1607 1608 1609 1610 1611 1612 | result = Tcl_GetString(objv[ii]); } else { result = NULL; } return ThreadCancel(interp, thrId, result, flags); } | < | | | | 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 | result = Tcl_GetString(objv[ii]); } else { result = NULL; } return ThreadCancel(interp, thrId, result, flags); } /* *---------------------------------------------------------------------- * * ThreadSendEval -- * * Evaluates Tcl script passed from source to target thread. * * Results: * A standard Tcl result. * * Side effects: * *---------------------------------------------------------------------- */ static int ThreadSendEval( Tcl_Interp *interp, void *clientData ) { ThreadSendData *sendPtr = (ThreadSendData *)clientData; char *script = (char*)sendPtr->clientData; return Tcl_EvalEx(interp, script, TCL_AUTO_LENGTH, TCL_EVAL_GLOBAL); } /* *---------------------------------------------------------------------- * * ThreadClbkSetVar -- * |
︙ | ︙ | |||
1654 1655 1656 1657 1658 1659 1660 | * *---------------------------------------------------------------------- */ static int ThreadClbkSetVar( Tcl_Interp *interp, | | | 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 | * *---------------------------------------------------------------------- */ static int ThreadClbkSetVar( Tcl_Interp *interp, void *clientData ) { ThreadClbkData *clbkPtr = (ThreadClbkData*)clientData; Tcl_Obj *var = (Tcl_Obj *)clbkPtr->clientData; Tcl_Obj *valObj; ThreadEventResult *resultPtr = &clbkPtr->result; int rc = TCL_OK; |
︙ | ︙ | |||
1687 1688 1689 1690 1691 1692 1693 | * In case of error, trigger the bgerror mechansim */ if (resultPtr->code == TCL_ERROR) { if (resultPtr->errorCode) { Tcl_SetVar2Ex(interp, "errorCode", NULL, Tcl_NewStringObj(resultPtr->errorCode, -1), TCL_GLOBAL_ONLY); | | | | | 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 | * In case of error, trigger the bgerror mechansim */ if (resultPtr->code == TCL_ERROR) { if (resultPtr->errorCode) { Tcl_SetVar2Ex(interp, "errorCode", NULL, Tcl_NewStringObj(resultPtr->errorCode, -1), TCL_GLOBAL_ONLY); Tcl_Free(resultPtr->errorCode); } if (resultPtr->errorInfo) { Tcl_SetVar2Ex(interp, "errorInfo", NULL, Tcl_NewStringObj(resultPtr->errorInfo, -1), TCL_GLOBAL_ONLY); Tcl_Free(resultPtr->errorInfo); } Tcl_SetObjResult(interp, valObj); Tcl_BackgroundException(interp, TCL_ERROR); return TCL_ERROR; } return TCL_OK; cleanup: Tcl_DecrRefCount(valObj); return rc; } static int ThreadClbkCommand(Tcl_Interp *interp, void *clientData) { int status = TCL_OK; ThreadClbkData *clbkPtr = (ThreadClbkData*)clientData; Tcl_Obj *script = (Tcl_Obj *)clbkPtr->clientData; ThreadEventResult *resultPtr = &clbkPtr->result; if (resultPtr->code == TCL_ERROR) { |
︙ | ︙ | |||
1768 1769 1770 1771 1772 1773 1774 | ctrl.condWait = NULL; ctrl.flags = 0; Tcl_MutexLock(&threadMutex); if (Tcl_CreateThread(&thrId, NewThread, &ctrl, stacksize, flags) != TCL_OK) { Tcl_MutexUnlock(&threadMutex); | | | 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 | ctrl.condWait = NULL; ctrl.flags = 0; Tcl_MutexLock(&threadMutex); if (Tcl_CreateThread(&thrId, NewThread, &ctrl, stacksize, flags) != TCL_OK) { Tcl_MutexUnlock(&threadMutex); Tcl_SetObjResult(interp, Tcl_NewStringObj("can't create a new thread", TCL_AUTO_LENGTH)); return TCL_ERROR; } /* * Wait for the thread to start because it is using * the ThreadCtrl argument which is on our stack. */ |
︙ | ︙ | |||
1795 1796 1797 1798 1799 1800 1801 | tsdPtr->refCount++; } Tcl_MutexUnlock(&threadMutex); Tcl_ConditionFinalize(&ctrl.condWait); ThreadGetHandle(thrId, thrHandle); | | | 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 | tsdPtr->refCount++; } Tcl_MutexUnlock(&threadMutex); Tcl_ConditionFinalize(&ctrl.condWait); ThreadGetHandle(thrId, thrHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_AUTO_LENGTH)); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1831 1832 1833 1834 1835 1836 1837 | * A Tcl script is executed in a new thread. * *---------------------------------------------------------------------- */ Tcl_ThreadCreateType NewThread( | | | 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 | * A Tcl script is executed in a new thread. * *---------------------------------------------------------------------- */ Tcl_ThreadCreateType NewThread( void *clientData ) { ThreadCtrl *ctrlPtr = (ThreadCtrl *)clientData; ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); Tcl_Interp *interp; int result = TCL_OK; size_t scriptLen; char *evalScript; |
︙ | ︙ | |||
1877 1878 1879 1880 1881 1882 1883 | /* * We need to keep a pointer to the alloc'ed mem of the script * we are eval'ing, for the case that we exit during evaluation */ scriptLen = strlen(ctrlPtr->script); | | | | 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 | /* * We need to keep a pointer to the alloc'ed mem of the script * we are eval'ing, for the case that we exit during evaluation */ scriptLen = strlen(ctrlPtr->script); evalScript = strcpy((char *)Tcl_Alloc(scriptLen+1), ctrlPtr->script); Tcl_CreateThreadExitHandler(ThreadExitProc, evalScript); /* * Notify the parent we are alive. */ ctrlPtr->script = NULL; Tcl_ConditionNotify(&ctrlPtr->condWait); |
︙ | ︙ | |||
1977 1978 1979 1980 1981 1982 1983 | Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); if (errChannel == NULL) { /* Fixes the [#634845] bug; credits to * Wojciech Kocjan <[email protected]> */ return; } ThreadGetHandle(Tcl_GetCurrentThread(), buf); | | | | | | 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 | Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); if (errChannel == NULL) { /* Fixes the [#634845] bug; credits to * Wojciech Kocjan <[email protected]> */ return; } ThreadGetHandle(Tcl_GetCurrentThread(), buf); Tcl_WriteChars(errChannel, "Error from thread ", TCL_AUTO_LENGTH); Tcl_WriteChars(errChannel, buf, TCL_AUTO_LENGTH); Tcl_WriteChars(errChannel, "\n", 1); Tcl_WriteChars(errChannel, errorInfo, TCL_AUTO_LENGTH); Tcl_WriteChars(errChannel, "\n", 1); #endif } else { ThreadGetHandle(Tcl_GetCurrentThread(), buf); argv[0] = errorProcString; argv[1] = buf; argv[2] = errorInfo; sendPtr = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData)); sendPtr->execProc = ThreadSendEval; sendPtr->freeProc = threadSendFree; sendPtr->clientData = Tcl_Merge(3, argv); sendPtr->interp = NULL; ThreadSend(interp, errorThreadId, sendPtr, NULL, 0); } |
︙ | ︙ | |||
2172 2173 2174 2175 2176 2177 2178 | return 0; } /* * Allocate storage for passing thread id's to caller */ | | | 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 | return 0; } /* * Allocate storage for passing thread id's to caller */ *thrIdArray = (Tcl_ThreadId *)Tcl_Alloc(count * sizeof(Tcl_ThreadId)); /* * Second walk; fill-in the array with thread ID's */ for (tsdPtr = threadList, ii = 0; tsdPtr; tsdPtr = tsdPtr->nextPtr, ii++) { (*thrIdArray)[ii] = tsdPtr->threadId; |
︙ | ︙ | |||
2250 2251 2252 2253 2254 2255 2256 | return tsdPtr; } } return NULL; } | < | 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 | return tsdPtr; } } return NULL; } /* *---------------------------------------------------------------------- * * ThreadCancel -- * * Cancels a script in another thread. * |
︙ | ︙ | |||
2287 2288 2289 2290 2291 2292 2293 | tsdPtr = ThreadExistsInner(thrId); if (tsdPtr == NULL) { Tcl_MutexUnlock(&threadMutex); ErrorNoSuchThread(interp, thrId); return TCL_ERROR; } | < < < < < < | < | 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 | tsdPtr = ThreadExistsInner(thrId); if (tsdPtr == NULL) { Tcl_MutexUnlock(&threadMutex); ErrorNoSuchThread(interp, thrId); return TCL_ERROR; } if (result != NULL) { resultObj = Tcl_NewStringObj(result, TCL_AUTO_LENGTH); } code = Tcl_CancelEval(tsdPtr->interp, resultObj, NULL, flags); Tcl_MutexUnlock(&threadMutex); return code; } /* *---------------------------------------------------------------------- * * ThreadJoin -- * * Wait for the exit of a different thread. |
︙ | ︙ | |||
2393 2394 2395 2396 2397 2398 2399 | * transfer. This allows this thread then to proceed. */ TransferEvent *evPtr; TransferResult *resultPtr; if (!Tcl_IsChannelRegistered(interp, chan)) { | | | | 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 | * transfer. This allows this thread then to proceed. */ TransferEvent *evPtr; TransferResult *resultPtr; if (!Tcl_IsChannelRegistered(interp, chan)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is not registered here", TCL_AUTO_LENGTH)); } if (Tcl_IsChannelShared(chan)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_AUTO_LENGTH)); return TCL_ERROR; } /* * Short circuit transfers to ourself. Nothing to do. */ |
︙ | ︙ | |||
2430 2431 2432 2433 2434 2435 2436 | ThreadCutChannel(interp, chan); /* * Wrap it into an event. */ | | | | 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 | ThreadCutChannel(interp, chan); /* * Wrap it into an event. */ resultPtr = (TransferResult *)Tcl_Alloc(sizeof(TransferResult)); evPtr = (TransferEvent *)Tcl_Alloc(sizeof(TransferEvent)); evPtr->chan = chan; evPtr->event.proc = TransferEventProc; evPtr->resultPtr = resultPtr; /* * Initialize the result fields. |
︙ | ︙ | |||
2503 2504 2505 2506 2507 2508 2509 | Tcl_SpliceChannel(chan); Tcl_RegisterChannel(interp, chan); Tcl_UnregisterChannel((Tcl_Interp *) NULL, chan); Tcl_AppendResult(interp, "transfer failed: ", NULL); if (resultPtr->resultMsg) { Tcl_AppendResult(interp, resultPtr->resultMsg, NULL); | | | | | | 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 | Tcl_SpliceChannel(chan); Tcl_RegisterChannel(interp, chan); Tcl_UnregisterChannel((Tcl_Interp *) NULL, chan); Tcl_AppendResult(interp, "transfer failed: ", NULL); if (resultPtr->resultMsg) { Tcl_AppendResult(interp, resultPtr->resultMsg, NULL); Tcl_Free(resultPtr->resultMsg); } else { Tcl_AppendResult(interp, "for reasons unknown", NULL); } Tcl_Free(resultPtr); return TCL_ERROR; } if (resultPtr->resultMsg) { Tcl_Free(resultPtr->resultMsg); } Tcl_Free(resultPtr); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
2549 2550 2551 2552 2553 2554 2555 | Tcl_Interp *interp, /* The current interpreter. */ Tcl_Channel chan /* The channel to detach */ ) { TransferEvent *evPtr; TransferResult *resultPtr; if (!Tcl_IsChannelRegistered(interp, chan)) { | | | | | | 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 | Tcl_Interp *interp, /* The current interpreter. */ Tcl_Channel chan /* The channel to detach */ ) { TransferEvent *evPtr; TransferResult *resultPtr; if (!Tcl_IsChannelRegistered(interp, chan)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is not registered here", TCL_AUTO_LENGTH)); } if (Tcl_IsChannelShared(chan)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_AUTO_LENGTH)); return TCL_ERROR; } /* * Cut the channel out of the interp/thread */ ThreadCutChannel(interp, chan); /* * Wrap it into the list of transfered channels. We generate no * events associated with the detached channel, thus really not * needing the transfer event structure allocated here. This * is done purely to avoid having yet another wrapper. */ resultPtr = (TransferResult *)Tcl_Alloc(sizeof(TransferResult)); evPtr = (TransferEvent *)Tcl_Alloc(sizeof(TransferEvent)); evPtr->chan = chan; evPtr->event.proc = NULL; evPtr->resultPtr = resultPtr; /* * Initialize the result fields. This is not used. |
︙ | ︙ | |||
2652 2653 2654 2655 2656 2657 2658 | && !resPtr->dstThreadId) { if (Tcl_IsChannelExisting(chanName)) { Tcl_MutexUnlock(&threadMutex); Tcl_AppendResult(interp, "channel already exists", NULL); return TCL_ERROR; } SpliceOut(resPtr, transferList); | | | | 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 | && !resPtr->dstThreadId) { if (Tcl_IsChannelExisting(chanName)) { Tcl_MutexUnlock(&threadMutex); Tcl_AppendResult(interp, "channel already exists", NULL); return TCL_ERROR; } SpliceOut(resPtr, transferList); Tcl_Free(resPtr->eventPtr); Tcl_Free(resPtr); found = 1; break; } } Tcl_MutexUnlock(&threadMutex); if (found == 0) { |
︙ | ︙ | |||
2726 2727 2728 2729 2730 2731 2732 | int inerror = tsdPtr && (tsdPtr->flags & THREAD_FLAGS_INERROR); Tcl_MutexUnlock(&threadMutex); ThreadFreeProc(send); if (clbk) { ThreadFreeProc(clbk); } if (inerror) { | | | 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 | int inerror = tsdPtr && (tsdPtr->flags & THREAD_FLAGS_INERROR); Tcl_MutexUnlock(&threadMutex); ThreadFreeProc(send); if (clbk) { ThreadFreeProc(clbk); } if (inerror) { Tcl_SetObjResult(interp, Tcl_NewStringObj("thread is in error", TCL_AUTO_LENGTH)); } else { ErrorNoSuchThread(interp, thrId); } return TCL_ERROR; } /* |
︙ | ︙ | |||
2756 2757 2758 2759 2760 2761 2762 | return code; } /* * Create the event for target thread event queue. */ | | | 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 | return code; } /* * Create the event for target thread event queue. */ eventPtr = (ThreadEvent *)Tcl_Alloc(sizeof(ThreadEvent)); eventPtr->sendData = send; eventPtr->clbkData = clbk; /* * Target thread about to service * another event */ |
︙ | ︙ | |||
2781 2782 2783 2784 2785 2786 2787 | if (eventPtr->clbkData) { Tcl_Preserve(eventPtr->clbkData->interp); } if ((flags & THREAD_SEND_WAIT) == 0) { resultPtr = NULL; eventPtr->resultPtr = NULL; } else { | | | 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 | if (eventPtr->clbkData) { Tcl_Preserve(eventPtr->clbkData->interp); } if ((flags & THREAD_SEND_WAIT) == 0) { resultPtr = NULL; eventPtr->resultPtr = NULL; } else { resultPtr = (ThreadEventResult *)Tcl_Alloc(sizeof(ThreadEventResult)); resultPtr->done = NULL; resultPtr->result = NULL; resultPtr->errorCode = NULL; resultPtr->errorInfo = NULL; resultPtr->dstThreadId = thrId; resultPtr->srcThreadId = Tcl_GetCurrentThread(); resultPtr->eventPtr = eventPtr; |
︙ | ︙ | |||
2843 2844 2845 2846 2847 2848 2849 | /* * Return result to caller */ if (resultPtr->code == TCL_ERROR) { if (resultPtr->errorCode) { Tcl_SetErrorCode(interp, resultPtr->errorCode, NULL); | | | | | | 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 | /* * Return result to caller */ if (resultPtr->code == TCL_ERROR) { if (resultPtr->errorCode) { Tcl_SetErrorCode(interp, resultPtr->errorCode, NULL); Tcl_Free(resultPtr->errorCode); } if (resultPtr->errorInfo) { Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(resultPtr->errorInfo, TCL_AUTO_LENGTH)); Tcl_Free(resultPtr->errorInfo); } } code = resultPtr->code; Tcl_SetObjResult(interp, resultPtr->result); /* * Cleanup */ Tcl_ConditionFinalize(&resultPtr->done); Tcl_DecrRefCount(resultPtr->result); Tcl_Free(resultPtr); return code; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
2917 2918 2919 2920 2921 2922 2923 | * a script in progress to be canceled or exceed its limit; * therefore, check for these conditions if we are able to * (i.e. we are running in a high enough version of Tcl). */ Tcl_DoOneEvent(TCL_ALL_EVENTS); | < < < | | | | | | | | | | | | | | < < < < | | | | < < < < | 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 | * a script in progress to be canceled or exceed its limit; * therefore, check for these conditions if we are able to * (i.e. we are running in a high enough version of Tcl). */ Tcl_DoOneEvent(TCL_ALL_EVENTS); /* * If the script has been unwound, bail out immediately. This does * not follow the recommended guidelines for how extensions should * handle the script cancellation functionality because this is * not a "normal" extension. Most extensions do not have a command * that simply enters an infinite Tcl event loop. Normal extensions * should not specify the TCL_CANCEL_UNWIND when calling the * Tcl_Canceled function to check if the command has been canceled. */ if (Tcl_Canceled(tsdPtr->interp, TCL_LEAVE_ERR_MSG | TCL_CANCEL_UNWIND) == TCL_ERROR) { code = TCL_ERROR; break; } if (Tcl_LimitExceeded(tsdPtr->interp)) { code = TCL_ERROR; break; } /* * Test stop condition under mutex since * some other thread may flip our flags. */ Tcl_MutexLock(&threadMutex); canrun = (tsdPtr->flags & THREAD_FLAGS_STOPPED) == 0; Tcl_MutexUnlock(&threadMutex); } /* * If the event processing loop above was terminated due to a * script in progress being canceled or exceeding its limits, * transfer the error to the current interpreter. */ if (code != TCL_OK) { char buf[THREAD_HNDLMAXLEN]; const char *errorInfo; errorInfo = Tcl_GetVar2(tsdPtr->interp, "errorInfo", NULL, TCL_GLOBAL_ONLY); if (errorInfo == NULL) { errorInfo = Tcl_GetString(Tcl_GetObjResult(tsdPtr->interp)); } ThreadGetHandle(Tcl_GetCurrentThread(), buf); Tcl_AppendResult(interp, "Error from thread ", buf, "\n", errorInfo, NULL); } /* * Remove from the list of active threads, so nobody can post * work to this thread, since it is just about to terminate. */ ListRemove(tsdPtr); |
︙ | ︙ | |||
3071 3072 3073 3074 3075 3076 3077 | * It should immediately exit thereafter. We might get * stuck here for long time if user really wants to * be absolutely sure that the thread has exited. */ if (dowait) { resultPtr = (ThreadEventResult*) | | | | | 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 | * It should immediately exit thereafter. We might get * stuck here for long time if user really wants to * be absolutely sure that the thread has exited. */ if (dowait) { resultPtr = (ThreadEventResult*) Tcl_Alloc(sizeof(ThreadEventResult)); resultPtr->done = NULL; resultPtr->result = NULL; resultPtr->code = TCL_OK; resultPtr->errorCode = NULL; resultPtr->errorInfo = NULL; resultPtr->dstThreadId = thrId; resultPtr->srcThreadId = Tcl_GetCurrentThread(); SpliceIn(resultPtr, resultList); } evPtr = (ThreadEvent *)Tcl_Alloc(sizeof(ThreadEvent)); evPtr->event.proc = ThreadEventProc; evPtr->sendData = NULL; evPtr->clbkData = NULL; evPtr->resultPtr = resultPtr; Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL); Tcl_ThreadAlert(thrId); if (dowait) { while (resultPtr->result == NULL) { Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL); } SpliceOut(resultPtr, resultList); Tcl_ConditionFinalize(&resultPtr->done); Tcl_DecrRefCount(resultPtr->result); Tcl_Free(resultPtr); } } } Tcl_MutexUnlock(&threadMutex); Tcl_SetIntObj(Tcl_GetObjResult(interp), (users > 0) ? users : 0); |
︙ | ︙ | |||
3317 3318 3319 3320 3321 3322 3323 | } Tcl_IncrRefCount(resultPtr->result); resultPtr->code = code; if (errorCode != NULL) { size = strlen(errorCode) + 1; | | | | 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 | } Tcl_IncrRefCount(resultPtr->result); resultPtr->code = code; if (errorCode != NULL) { size = strlen(errorCode) + 1; resultPtr->errorCode = (char *)memcpy(Tcl_Alloc(size), errorCode, size); } else { resultPtr->errorCode = NULL; } if (errorInfo != NULL) { size = strlen(errorInfo) + 1; resultPtr->errorInfo = (char *)memcpy(Tcl_Alloc(size), errorInfo, size); } else { resultPtr->errorInfo = NULL; } } /* *---------------------------------------------------------------------- |
︙ | ︙ | |||
3548 3549 3550 3551 3552 3553 3554 | } } if (resultPtr) { Tcl_MutexLock(&threadMutex); resultPtr->resultCode = code; if (msg != NULL) { size_t size = strlen(msg)+1; | | | | | | | 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 | } } if (resultPtr) { Tcl_MutexLock(&threadMutex); resultPtr->resultCode = code; if (msg != NULL) { size_t size = strlen(msg)+1; resultPtr->resultMsg = (char *)memcpy(Tcl_Alloc(size), msg, size); } Tcl_ConditionNotify(&resultPtr->done); Tcl_MutexUnlock(&threadMutex); } return 1; } /* *---------------------------------------------------------------------- * * ThreadFreeProc -- * * Called when we are exiting and memory needs to be freed. * * Results: * None. * * Side effects: * Clears up mem specified in clientData * *---------------------------------------------------------------------- */ static void ThreadFreeProc( void *clientData ) { /* * This will free send and/or callback structures * since both are the same in the beginning. */ ThreadSendData *anyPtr = (ThreadSendData *)clientData; if (anyPtr) { if (anyPtr->clientData) { (*anyPtr->freeProc)(anyPtr->clientData); } Tcl_Free(anyPtr); } } /* *---------------------------------------------------------------------- * * ThreadDeleteEvent -- |
︙ | ︙ | |||
3610 3611 3612 3613 3614 3615 3616 | * It cleans up our events in the event queue for this thread. * *---------------------------------------------------------------------- */ static int ThreadDeleteEvent( Tcl_Event *eventPtr, /* Really ThreadEvent */ | | | 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 | * It cleans up our events in the event queue for this thread. * *---------------------------------------------------------------------- */ static int ThreadDeleteEvent( Tcl_Event *eventPtr, /* Really ThreadEvent */ void *clientData /* dummy */ ) { if (eventPtr->proc == ThreadEventProc) { /* * Regular script event. Just dispose memory */ ThreadEvent *evPtr = (ThreadEvent*)eventPtr; if (evPtr->sendData) { |
︙ | ︙ | |||
3679 3680 3681 3682 3683 3684 3685 | * It unblocks anyone that is waiting on a send to this thread. * It cleans up any events in the event queue for this thread. * *---------------------------------------------------------------------- */ static void ThreadExitProc( | | | | | 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 | * It unblocks anyone that is waiting on a send to this thread. * It cleans up any events in the event queue for this thread. * *---------------------------------------------------------------------- */ static void ThreadExitProc( void *clientData ) { char *threadEvalScript = (char *)clientData; const char *diemsg = "target thread died"; ThreadEventResult *resultPtr, *nextPtr; Tcl_ThreadId self = Tcl_GetCurrentThread(); ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); TransferResult *tResultPtr, *tNextPtr; if (threadEvalScript && threadEvalScript != threadEmptyResult) { Tcl_Free(threadEvalScript); } Tcl_MutexLock(&threadMutex); /* * NaviServer/AOLserver and threadpool threads get started/stopped * out of the control of this interface so this is |
︙ | ︙ | |||
3730 3731 3732 3733 3734 3735 3736 | /* * We are going away. By freeing up the result we signal * to the other thread we don't care about the result. */ SpliceOut(resultPtr, resultList); | | | 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 | /* * We are going away. By freeing up the result we signal * to the other thread we don't care about the result. */ SpliceOut(resultPtr, resultList); Tcl_Free(resultPtr); } else if (resultPtr->dstThreadId == self) { /* * Dang. The target is going away. Unblock the caller. * The result string must be dynamically allocated * because the main thread is going to call free on it. |
︙ | ︙ | |||
3759 3760 3761 3762 3763 3764 3765 | * to the other thread we don't care about the result. * * This should not happen, as this thread should be in * ThreadTransfer at location (*). */ SpliceOut(tResultPtr, transferList); | | | | 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 | * to the other thread we don't care about the result. * * This should not happen, as this thread should be in * ThreadTransfer at location (*). */ SpliceOut(tResultPtr, transferList); Tcl_Free(tResultPtr); } else if (tResultPtr->dstThreadId == self) { /* * Dang. The target is going away. Unblock the caller. * The result string must be dynamically allocated * because the main thread is going to call free on it. */ tResultPtr->resultMsg = strcpy((char *)Tcl_Alloc(1+strlen(diemsg)), diemsg); tResultPtr->resultCode = TCL_ERROR; Tcl_ConditionNotify(&tResultPtr->done); } } Tcl_MutexUnlock(&threadMutex); } |
︙ | ︙ |
Changes to generic/threadPoolCmd.c.
︙ | ︙ | |||
117 118 119 120 121 122 123 | * Miscelaneous functions used within this file */ static int CreateWorker(Tcl_Interp *interp, ThreadPool *tpoolPtr); static Tcl_ThreadCreateType | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | * Miscelaneous functions used within this file */ static int CreateWorker(Tcl_Interp *interp, ThreadPool *tpoolPtr); static Tcl_ThreadCreateType TpoolWorker(void *clientData); static int RunStopEvent(Tcl_Event *evPtr, int mask); static void PushWork(TpoolResult *rPtr, ThreadPool *tpoolPtr); |
︙ | ︙ | |||
150 151 152 153 154 155 156 | static ThreadPool* GetTpool(const char *tpoolName); static ThreadPool* GetTpoolUnl(const char *tpoolName); static void | | | | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | static ThreadPool* GetTpool(const char *tpoolName); static ThreadPool* GetTpoolUnl(const char *tpoolName); static void ThrExitHandler(void *clientData); static void AppExitHandler(void *clientData); static int TpoolReserve(ThreadPool *tpoolPtr); static size_t TpoolRelease(ThreadPool *tpoolPtr); |
︙ | ︙ | |||
190 191 192 193 194 195 196 | * None. * *---------------------------------------------------------------------- */ static int TpoolCreateObjCmd( | | | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | * None. * *---------------------------------------------------------------------- */ static int TpoolCreateObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ii, minw, maxw, idle; char buf[64], *exs = NULL, *cmd = NULL; ThreadPool *tpoolPtr; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | } } else if (OPT_CMP(opt, "-idletime")) { if (Tcl_GetIntFromObj(interp, objv[ii+1], &idle) != TCL_OK) { return TCL_ERROR; } } else if (OPT_CMP(opt, "-initcmd")) { const char *val = Tcl_GetString(objv[ii+1]); | | | | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | } } else if (OPT_CMP(opt, "-idletime")) { if (Tcl_GetIntFromObj(interp, objv[ii+1], &idle) != TCL_OK) { return TCL_ERROR; } } else if (OPT_CMP(opt, "-initcmd")) { const char *val = Tcl_GetString(objv[ii+1]); cmd = strcpy((char *)Tcl_Alloc(objv[ii+1]->length+1), val); } else if (OPT_CMP(opt, "-exitcmd")) { const char *val = Tcl_GetString(objv[ii+1]); exs = strcpy((char *)Tcl_Alloc(objv[ii+1]->length+1), val); } else { goto usage; } } /* * Do some consistency checking |
︙ | ︙ | |||
262 263 264 265 266 267 268 | maxw = minw; } /* * Allocate and initialize thread pool structure */ | | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | maxw = minw; } /* * Allocate and initialize thread pool structure */ tpoolPtr = (ThreadPool *)Tcl_Alloc(sizeof(ThreadPool)); memset(tpoolPtr, 0, sizeof(ThreadPool)); tpoolPtr->minWorkers = minw; tpoolPtr->maxWorkers = maxw; tpoolPtr->idleTime = idle; tpoolPtr->initScript = cmd; tpoolPtr->exitScript = exs; |
︙ | ︙ | |||
295 296 297 298 299 300 301 | Tcl_MutexUnlock(&listMutex); return TCL_ERROR; } } Tcl_MutexUnlock(&tpoolPtr->mutex); sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr); | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | Tcl_MutexUnlock(&listMutex); return TCL_ERROR; } } Tcl_MutexUnlock(&tpoolPtr->mutex); sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr); Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_AUTO_LENGTH)); return TCL_OK; usage: Tcl_WrongNumArgs(interp, 1, objv, "?-minworkers count? ?-maxworkers count? " "?-initcmd script? ?-exitcmd script? " |
︙ | ︙ | |||
326 327 328 329 330 331 332 | * None. * *---------------------------------------------------------------------- */ static int TpoolPostObjCmd( | | | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | * None. * *---------------------------------------------------------------------- */ static int TpoolPostObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { Tcl_WideInt jobId = 0; int ii, detached = 0, nowait = 0; size_t len; |
︙ | ︙ | |||
452 453 454 455 456 457 458 | } } /* * Create new job ticket and put it on the list. */ | | | | 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | } } /* * Create new job ticket and put it on the list. */ rPtr = (TpoolResult *)Tcl_Alloc(sizeof(TpoolResult)); memset(rPtr, 0, sizeof(TpoolResult)); if (detached == 0) { jobId = ++tpoolPtr->jobId; rPtr->jobId = jobId; } rPtr->script = strcpy((char *)Tcl_Alloc(len+1), script); rPtr->scriptLen = len; rPtr->detached = detached; rPtr->threadId = Tcl_GetCurrentThread(); PushWork(rPtr, tpoolPtr); Tcl_ConditionNotify(&tpoolPtr->cond); Tcl_MutexUnlock(&tpoolPtr->mutex); |
︙ | ︙ | |||
498 499 500 501 502 503 504 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolWaitObjCmd( | | | > | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolWaitObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ii, done; int wObjc; Tcl_WideInt jobId; char *tpoolName; Tcl_Obj *listVar = NULL; Tcl_Obj *waitList, *doneList, **wObjv; ThreadPool *tpoolPtr; TpoolResult *rPtr; Tcl_HashEntry *hPtr; |
︙ | ︙ | |||
613 614 615 616 617 618 619 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolCancelObjCmd( | | | > | 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolCancelObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ii; int wObjc; Tcl_WideInt jobId; char *tpoolName; Tcl_Obj *listVar = NULL; Tcl_Obj *doneList, *waitList, **wObjv; ThreadPool *tpoolPtr; TpoolResult *rPtr; |
︙ | ︙ | |||
670 671 672 673 674 675 676 | } if (rPtr->nextPtr != NULL) { rPtr->nextPtr->prevPtr = rPtr->prevPtr; } else { tpoolPtr->workTail = rPtr->prevPtr; } SetResult(NULL, rPtr); /* Just to free the result */ | | | | 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | } if (rPtr->nextPtr != NULL) { rPtr->nextPtr->prevPtr = rPtr->prevPtr; } else { tpoolPtr->workTail = rPtr->prevPtr; } SetResult(NULL, rPtr); /* Just to free the result */ Tcl_Free(rPtr->script); Tcl_Free(rPtr); Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]); break; } } if (rPtr == NULL && listVar) { Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]); } |
︙ | ︙ | |||
709 710 711 712 713 714 715 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolGetObjCmd( | | | 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolGetObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ret; Tcl_WideInt jobId; char *tpoolName; |
︙ | ︙ | |||
774 775 776 777 778 779 780 | } Tcl_DeleteHashEntry(hPtr); Tcl_MutexUnlock(&tpoolPtr->mutex); ret = rPtr->retcode; SetResult(interp, rPtr); | | | 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | } Tcl_DeleteHashEntry(hPtr); Tcl_MutexUnlock(&tpoolPtr->mutex); ret = rPtr->retcode; SetResult(interp, rPtr); Tcl_Free(rPtr); if (resVar) { Tcl_ObjSetVar2(interp, resVar, NULL, Tcl_GetObjResult(interp), 0); Tcl_SetObjResult(interp, Tcl_NewIntObj(ret)); ret = TCL_OK; } |
︙ | ︙ | |||
804 805 806 807 808 809 810 | * None. * *---------------------------------------------------------------------- */ static int TpoolReserveObjCmd( | | | 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 | * None. * *---------------------------------------------------------------------- */ static int TpoolReserveObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ret; char *tpoolName; ThreadPool *tpoolPtr; |
︙ | ︙ | |||
859 860 861 862 863 864 865 | * None. * *---------------------------------------------------------------------- */ static int TpoolReleaseObjCmd( | | | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | * None. * *---------------------------------------------------------------------- */ static int TpoolReleaseObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { size_t ret; char *tpoolName; ThreadPool *tpoolPtr; |
︙ | ︙ | |||
914 915 916 917 918 919 920 | * None. * *---------------------------------------------------------------------- */ static int TpoolSuspendObjCmd( | | | 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | * None. * *---------------------------------------------------------------------- */ static int TpoolSuspendObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { char *tpoolName; ThreadPool *tpoolPtr; |
︙ | ︙ | |||
964 965 966 967 968 969 970 | * None. * *---------------------------------------------------------------------- */ static int TpoolResumeObjCmd( | | | 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 | * None. * *---------------------------------------------------------------------- */ static int TpoolResumeObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { char *tpoolName; ThreadPool *tpoolPtr; |
︙ | ︙ | |||
1014 1015 1016 1017 1018 1019 1020 | * None. * *---------------------------------------------------------------------- */ static int TpoolNamesObjCmd( | | | | 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 | * None. * *---------------------------------------------------------------------- */ static int TpoolNamesObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { ThreadPool *tpoolPtr; Tcl_Obj *listObj = Tcl_NewListObj(0, NULL); Tcl_MutexLock(&listMutex); for (tpoolPtr = tpoolList; tpoolPtr; tpoolPtr = tpoolPtr->nextPtr) { char buf[32]; sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr); Tcl_ListObjAppendElement(interp, listObj, Tcl_NewStringObj(buf, TCL_AUTO_LENGTH)); } Tcl_MutexUnlock(&listMutex); Tcl_SetObjResult(interp, listObj); return TCL_OK; } |
︙ | ︙ | |||
1076 1077 1078 1079 1080 1081 1082 | * Create new worker thread here. Wait for the thread to start * because it's using the ThreadResult arg which is on our stack. */ Tcl_MutexLock(&startMutex); if (Tcl_CreateThread(&id, TpoolWorker, &result, TCL_THREAD_STACK_DEFAULT, 0) != TCL_OK) { | | | 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 | * Create new worker thread here. Wait for the thread to start * because it's using the ThreadResult arg which is on our stack. */ Tcl_MutexLock(&startMutex); if (Tcl_CreateThread(&id, TpoolWorker, &result, TCL_THREAD_STACK_DEFAULT, 0) != TCL_OK) { Tcl_SetObjResult(interp, Tcl_NewStringObj("can't create a new thread", TCL_AUTO_LENGTH)); Tcl_MutexUnlock(&startMutex); return TCL_ERROR; } while(result.retcode == -1) { Tcl_ConditionWait(&tpoolPtr->cond, &startMutex, NULL); } Tcl_MutexUnlock(&startMutex); |
︙ | ︙ | |||
1117 1118 1119 1120 1121 1122 1123 | * None. * *---------------------------------------------------------------------- */ static Tcl_ThreadCreateType TpoolWorker( | | | | 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | * None. * *---------------------------------------------------------------------- */ static Tcl_ThreadCreateType TpoolWorker( void *clientData ) { TpoolResult *rPtr = (TpoolResult *)clientData; ThreadPool *tpoolPtr = rPtr->tpoolPtr; int tout = 0; Tcl_Interp *interp; Tcl_Time waitTime, *idlePtr; const char *errMsg; |
︙ | ︙ | |||
1149 1150 1151 1152 1153 1154 1155 | } else { rPtr->retcode = 0; } #endif if (rPtr->retcode == 1) { errMsg = Tcl_GetString(Tcl_GetObjResult(interp)); | | | | | 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 | } else { rPtr->retcode = 0; } #endif if (rPtr->retcode == 1) { errMsg = Tcl_GetString(Tcl_GetObjResult(interp)); rPtr->result = strcpy((char *)Tcl_Alloc(strlen(errMsg)+1), errMsg); Tcl_ConditionNotify(&tpoolPtr->cond); Tcl_MutexUnlock(&startMutex); goto out; } /* * Initialize the interpreter */ if (tpoolPtr->initScript) { TpoolEval(interp, tpoolPtr->initScript, TCL_AUTO_LENGTH, rPtr); if (rPtr->retcode != TCL_OK) { rPtr->retcode = 1; errMsg = Tcl_GetString(Tcl_GetObjResult(interp)); rPtr->result = strcpy((char *)Tcl_Alloc(strlen(errMsg)+1), errMsg); Tcl_ConditionNotify(&tpoolPtr->cond); Tcl_MutexUnlock(&startMutex); goto out; } } /* |
︙ | ︙ | |||
1232 1233 1234 1235 1236 1237 1238 | } } else if (tpoolPtr->tearDown) { PushWork(rPtr, tpoolPtr); break; /* Kill worker because pool is going down */ } Tcl_MutexUnlock(&tpoolPtr->mutex); TpoolEval(interp, rPtr->script, rPtr->scriptLen, rPtr); | | | | | 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 | } } else if (tpoolPtr->tearDown) { PushWork(rPtr, tpoolPtr); break; /* Kill worker because pool is going down */ } Tcl_MutexUnlock(&tpoolPtr->mutex); TpoolEval(interp, rPtr->script, rPtr->scriptLen, rPtr); Tcl_Free(rPtr->script); Tcl_MutexLock(&tpoolPtr->mutex); if (!rPtr->detached) { int isNew; Tcl_SetHashValue(Tcl_CreateHashEntry(&tpoolPtr->jobsDone, (void *)(size_t)rPtr->jobId, &isNew), rPtr); SignalWaiter(tpoolPtr); } else { Tcl_Free(rPtr); } } /* * Tear down the worker */ if (tpoolPtr->exitScript) { TpoolEval(interp, tpoolPtr->exitScript, TCL_AUTO_LENGTH, NULL); } tpoolPtr->numWorkers--; SignalWaiter(tpoolPtr); Tcl_MutexUnlock(&tpoolPtr->mutex); out: |
︙ | ︙ | |||
1521 1522 1523 1524 1525 1526 1527 | return ret; } rPtr->retcode = ret; if (ret == TCL_ERROR) { errorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY); errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY); if (errorCode != NULL) { | | | | | 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 | return ret; } rPtr->retcode = ret; if (ret == TCL_ERROR) { errorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY); errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY); if (errorCode != NULL) { rPtr->errorCode = (char *)Tcl_Alloc(1 + strlen(errorCode)); strcpy(rPtr->errorCode, errorCode); } if (errorInfo != NULL) { rPtr->errorInfo = (char *)Tcl_Alloc(1 + strlen(errorInfo)); strcpy(rPtr->errorInfo, errorInfo); } } result = Tcl_GetString(Tcl_GetObjResult(interp)); reslen = Tcl_GetObjResult(interp)->length; if (reslen == 0) { rPtr->result = threadEmptyResult; } else { rPtr->result = strcpy((char *)Tcl_Alloc(1 + reslen), result); } return ret; } /* *---------------------------------------------------------------------- |
︙ | ︙ | |||
1565 1566 1567 1568 1569 1570 1571 | SetResult( Tcl_Interp *interp, TpoolResult *rPtr ) { if (rPtr->retcode == TCL_ERROR) { if (rPtr->errorCode) { if (interp) { | | | | | | | | 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 | SetResult( Tcl_Interp *interp, TpoolResult *rPtr ) { if (rPtr->retcode == TCL_ERROR) { if (rPtr->errorCode) { if (interp) { Tcl_SetObjErrorCode(interp,Tcl_NewStringObj(rPtr->errorCode, TCL_AUTO_LENGTH)); } Tcl_Free(rPtr->errorCode); rPtr->errorCode = NULL; } if (rPtr->errorInfo) { if (interp) { Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(rPtr->errorInfo, TCL_AUTO_LENGTH)); } Tcl_Free(rPtr->errorInfo); rPtr->errorInfo = NULL; } } if (rPtr->result) { if (rPtr->result == threadEmptyResult) { if (interp) { Tcl_ResetResult(interp); } } else { if (interp) { Tcl_SetObjResult(interp, Tcl_NewStringObj(rPtr->result, TCL_AUTO_LENGTH)); } Tcl_Free(rPtr->result); rPtr->result = NULL; } } } /* *---------------------------------------------------------------------- |
︙ | ︙ | |||
1675 1676 1677 1678 1679 1680 1681 | Tcl_MutexUnlock(&tpoolPtr->mutex); /* * Tear down the pool structure */ if (tpoolPtr->initScript) { | | | | | | | | | | | 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 | Tcl_MutexUnlock(&tpoolPtr->mutex); /* * Tear down the pool structure */ if (tpoolPtr->initScript) { Tcl_Free(tpoolPtr->initScript); } if (tpoolPtr->exitScript) { Tcl_Free(tpoolPtr->exitScript); } /* * Cleanup completed but not collected jobs */ hPtr = Tcl_FirstHashEntry(&tpoolPtr->jobsDone, &search); while (hPtr != NULL) { rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr); if (rPtr->result && rPtr->result != threadEmptyResult) { Tcl_Free(rPtr->result); } if (rPtr->retcode == TCL_ERROR) { if (rPtr->errorInfo) { Tcl_Free(rPtr->errorInfo); } if (rPtr->errorCode) { Tcl_Free(rPtr->errorCode); } } Tcl_Free(rPtr); Tcl_DeleteHashEntry(hPtr); hPtr = Tcl_NextHashEntry(&search); } Tcl_DeleteHashTable(&tpoolPtr->jobsDone); /* * Cleanup jobs posted but never completed. */ for (rPtr = tpoolPtr->workHead; rPtr; rPtr = rPtr->nextPtr) { Tcl_Free(rPtr->script); Tcl_Free(rPtr); } Tcl_MutexFinalize(&tpoolPtr->mutex); Tcl_ConditionFinalize(&tpoolPtr->cond); Tcl_Free(tpoolPtr); return 0; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1799 1800 1801 1802 1803 1804 1805 | Tcl_Event *evPtr; waitPtr = PopWaiter(tpoolPtr); if (waitPtr == NULL) { return; } | | | 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 | Tcl_Event *evPtr; waitPtr = PopWaiter(tpoolPtr); if (waitPtr == NULL) { return; } evPtr = (Tcl_Event *)Tcl_Alloc(sizeof(Tcl_Event)); evPtr->proc = RunStopEvent; Tcl_ThreadQueueEvent(waitPtr->threadId,(Tcl_Event*)evPtr,TCL_QUEUE_TAIL); Tcl_ThreadAlert(waitPtr->threadId); } /* |
︙ | ︙ | |||
1827 1828 1829 1830 1831 1832 1833 | */ static void InitWaiter () { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); if (tsdPtr->waitPtr == NULL) { | | | 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 | */ static void InitWaiter () { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); if (tsdPtr->waitPtr == NULL) { tsdPtr->waitPtr = (TpoolWaiter *)Tcl_Alloc(sizeof(TpoolWaiter)); tsdPtr->waitPtr->prevPtr = NULL; tsdPtr->waitPtr->nextPtr = NULL; tsdPtr->waitPtr->threadId = Tcl_GetCurrentThread(); Tcl_CreateThreadExitHandler(ThrExitHandler, tsdPtr); } } |
︙ | ︙ | |||
1852 1853 1854 1855 1856 1857 1858 | * Side effects: * None. * *---------------------------------------------------------------------- */ static void ThrExitHandler( | | | | | 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 | * Side effects: * None. * *---------------------------------------------------------------------- */ static void ThrExitHandler( void *clientData ) { ThreadSpecificData *tsdPtr = (ThreadSpecificData *)clientData; Tcl_Free(tsdPtr->waitPtr); } /* *---------------------------------------------------------------------- * * AppExitHandler * * Deletes all threadpools on application exit. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */ static void AppExitHandler( void *clientData ) { ThreadPool *tpoolPtr; Tcl_MutexLock(&listMutex); /* * Restart with head of list each time until empty. [Bug 1427570] */ |
︙ | ︙ | |||
1927 1928 1929 1930 1931 1932 1933 | TCL_CMD(interp, TPOOL_CMD_PREFIX"release", TpoolReleaseObjCmd); TCL_CMD(interp, TPOOL_CMD_PREFIX"suspend", TpoolSuspendObjCmd); TCL_CMD(interp, TPOOL_CMD_PREFIX"resume", TpoolResumeObjCmd); if (initialized == 0) { Tcl_MutexLock(&listMutex); if (initialized == 0) { | | | 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 | TCL_CMD(interp, TPOOL_CMD_PREFIX"release", TpoolReleaseObjCmd); TCL_CMD(interp, TPOOL_CMD_PREFIX"suspend", TpoolSuspendObjCmd); TCL_CMD(interp, TPOOL_CMD_PREFIX"resume", TpoolResumeObjCmd); if (initialized == 0) { Tcl_MutexLock(&listMutex); if (initialized == 0) { Tcl_CreateExitHandler(AppExitHandler, (void *)-1); initialized = 1; } Tcl_MutexUnlock(&listMutex); } return TCL_OK; } |
︙ | ︙ |
Changes to generic/threadSpCmd.c.
︙ | ︙ | |||
173 174 175 176 177 178 179 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadMutexObjCmd( | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadMutexObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int opt, ret; size_t nameLen; const char *mutexName; char type; SpMutex *mutexPtr; static const char *const cmdOpts[] = { "create", "destroy", "lock", "unlock", NULL }; enum options { m_CREATE, m_DESTROY, m_LOCK, m_UNLOCK }; /* |
︙ | ︙ | |||
240 241 242 243 244 245 246 | } } /* * Create the requested mutex */ | | | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | } } /* * Create the requested mutex */ mutexPtr = (SpMutex *)Tcl_Alloc(sizeof(SpMutex)); mutexPtr->type = type; mutexPtr->bucket = NULL; mutexPtr->hentry = NULL; mutexPtr->lock = NULL; /* Will be auto-initialized */ /* * Generate Tcl name for this mutex |
︙ | ︙ | |||
349 350 351 352 353 354 355 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadRWMutexObjCmd( | | | | 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadRWMutexObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int opt, ret; size_t nameLen; const char *mutexName; SpMutex *mutexPtr; Sp_ReadWriteMutex *rwPtr; Sp_AnyMutex **lockPtr; static const char *const cmdOpts[] = { "create", "destroy", "rlock", "wlock", "unlock", NULL }; enum options { w_CREATE, w_DESTROY, w_RLOCK, w_WLOCK, w_UNLOCK }; /* |
︙ | ︙ | |||
397 398 399 400 401 402 403 | if (opt == (int)w_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | if (opt == (int)w_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } mutexPtr = (SpMutex *)Tcl_Alloc(sizeof(SpMutex)); mutexPtr->type = WMUTEXID; mutexPtr->refcnt = 0; mutexPtr->bucket = NULL; mutexPtr->hentry = NULL; mutexPtr->lock = NULL; /* Will be auto-initialized */ nameObj = GetName(mutexPtr->type, (void*)mutexPtr); |
︙ | ︙ | |||
513 514 515 516 517 518 519 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCondObjCmd( | | | | 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCondObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int opt, ret, timeMsec = 0; size_t nameLen; const char *condvName, *mutexName; SpMutex *mutexPtr; SpCondv *condvPtr; static const char *const cmdOpts[] = { "create", "destroy", "notify", "wait", NULL }; enum options { c_CREATE, c_DESTROY, c_NOTIFY, c_WAIT }; /* |
︙ | ︙ | |||
559 560 561 562 563 564 565 | if (opt == (int)c_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } | | | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | if (opt == (int)c_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } condvPtr = (SpCondv *)Tcl_Alloc(sizeof(SpCondv)); condvPtr->refcnt = 0; condvPtr->bucket = NULL; condvPtr->hentry = NULL; condvPtr->mutex = NULL; condvPtr->cond = NULL; /* Will be auto-initialized */ nameObj = GetName(CONDVID, (void*)condvPtr); |
︙ | ︙ | |||
681 682 683 684 685 686 687 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadEvalObjCmd( | | | 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadEvalObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[] /* Argument objects. */ ) { int ret, optx, internal; const char *mutexName; Tcl_Obj *scriptObj; |
︙ | ︙ | |||
768 769 770 771 772 773 774 | Tcl_DecrRefCount(scriptObj); if (ret == TCL_ERROR) { char msg[32 + TCL_INTEGER_SPACE]; /* Next line generates a Deprecation warning when compiled with Tcl 8.6. * See Tcl bug #3562640 */ sprintf(msg, "\n (\"eval\" body line %d)", Tcl_GetErrorLine(interp)); | | | 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | Tcl_DecrRefCount(scriptObj); if (ret == TCL_ERROR) { char msg[32 + TCL_INTEGER_SPACE]; /* Next line generates a Deprecation warning when compiled with Tcl 8.6. * See Tcl bug #3562640 */ sprintf(msg, "\n (\"eval\" body line %d)", Tcl_GetErrorLine(interp)); Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(msg, TCL_AUTO_LENGTH)); } /* * Unlock the mutex. */ if (internal) { |
︙ | ︙ | |||
1011 1012 1013 1014 1015 1016 1017 | } if (!SpMutexFinalize(mutexPtr)) { PutMutex(mutexPtr); return 0; } PutMutex(mutexPtr); RemoveAnyItem(SP_MUTEX, name, len); | | | 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | } if (!SpMutexFinalize(mutexPtr)) { PutMutex(mutexPtr); return 0; } PutMutex(mutexPtr); RemoveAnyItem(SP_MUTEX, name, len); Tcl_Free(mutexPtr); return 1; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1047 1048 1049 1050 1051 1052 1053 | } if (!SpCondvFinalize(condvPtr)) { PutCondv(condvPtr); return 0; } PutCondv(condvPtr); RemoveAnyItem(SP_CONDV, name, len); | | | 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 | } if (!SpCondvFinalize(condvPtr)) { PutCondv(condvPtr); return 0; } PutCondv(condvPtr); RemoveAnyItem(SP_CONDV, name, len); Tcl_Free(condvPtr); return 1; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1356 1357 1358 1359 1360 1361 1362 | Sp_ExclusiveMutex_ *emPtr; Tcl_ThreadId thisThread = Tcl_GetCurrentThread(); /* * Allocate the mutex structure on first access */ | | | | < | 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 | Sp_ExclusiveMutex_ *emPtr; Tcl_ThreadId thisThread = Tcl_GetCurrentThread(); /* * Allocate the mutex structure on first access */ if (*muxPtr == NULL) { Tcl_MutexLock(&initMutex); if (*muxPtr == NULL) { *muxPtr = (Sp_ExclusiveMutex_ *)Tcl_Alloc(sizeof(Sp_ExclusiveMutex_)); memset(*muxPtr, 0, sizeof(Sp_ExclusiveMutex_)); } Tcl_MutexUnlock(&initMutex); } /* * Try locking if not currently locked by anybody. |
︙ | ︙ | |||
1492 1493 1494 1495 1496 1497 1498 | Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)muxPtr; if (emPtr->lock) { Tcl_MutexFinalize(&emPtr->lock); } if (emPtr->mutex) { Tcl_MutexFinalize(&emPtr->mutex); } | | | 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 | Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)muxPtr; if (emPtr->lock) { Tcl_MutexFinalize(&emPtr->lock); } if (emPtr->mutex) { Tcl_MutexFinalize(&emPtr->mutex); } Tcl_Free(*muxPtr); } } /* *---------------------------------------------------------------------- * * Sp_RecursiveMutexLock -- |
︙ | ︙ | |||
1525 1526 1527 1528 1529 1530 1531 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_RecursiveMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_RecursiveMutex_*)0) { | | | | 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_RecursiveMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_RecursiveMutex_*)0) { *muxPtr = (Sp_RecursiveMutex_ *) Tcl_Alloc(sizeof(Sp_RecursiveMutex_)); memset(*muxPtr, 0, sizeof(Sp_RecursiveMutex_)); } Tcl_MutexUnlock(&initMutex); } rmPtr = *(Sp_RecursiveMutex_**)muxPtr; Tcl_MutexLock(&rmPtr->lock); |
︙ | ︙ | |||
1663 1664 1665 1666 1667 1668 1669 | Sp_RecursiveMutex_ *rmPtr = *(Sp_RecursiveMutex_**)muxPtr; if (rmPtr->lock) { Tcl_MutexFinalize(&rmPtr->lock); } if (rmPtr->cond) { Tcl_ConditionFinalize(&rmPtr->cond); } | | | 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 | Sp_RecursiveMutex_ *rmPtr = *(Sp_RecursiveMutex_**)muxPtr; if (rmPtr->lock) { Tcl_MutexFinalize(&rmPtr->lock); } if (rmPtr->cond) { Tcl_ConditionFinalize(&rmPtr->cond); } Tcl_Free(*muxPtr); } } /* *---------------------------------------------------------------------- * * Sp_ReadWriteMutexRLock -- |
︙ | ︙ | |||
1697 1698 1699 1700 1701 1702 1703 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { | | | | 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { *muxPtr = (Sp_ReadWriteMutex_ *) Tcl_Alloc(sizeof(Sp_ReadWriteMutex_)); memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_)); } Tcl_MutexUnlock(&initMutex); } rwPtr = *(Sp_ReadWriteMutex_**)muxPtr; Tcl_MutexLock(&rwPtr->lock); |
︙ | ︙ | |||
1752 1753 1754 1755 1756 1757 1758 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { | | | | 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { *muxPtr = (Sp_ReadWriteMutex_ *) Tcl_Alloc(sizeof(Sp_ReadWriteMutex_)); memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_)); } Tcl_MutexUnlock(&initMutex); } rwPtr = *(Sp_ReadWriteMutex_**)muxPtr; Tcl_MutexLock(&rwPtr->lock); |
︙ | ︙ | |||
1876 1877 1878 1879 1880 1881 1882 | } if (rwPtr->rcond) { Tcl_ConditionFinalize(&rwPtr->rcond); } if (rwPtr->wcond) { Tcl_ConditionFinalize(&rwPtr->wcond); } | | | 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 | } if (rwPtr->rcond) { Tcl_ConditionFinalize(&rwPtr->rcond); } if (rwPtr->wcond) { Tcl_ConditionFinalize(&rwPtr->wcond); } Tcl_Free(*muxPtr); } } /* *---------------------------------------------------------------------- * * AnyMutexIsLocked -- |
︙ | ︙ |
Changes to generic/threadSvCmd.c.
︙ | ︙ | |||
120 121 122 123 124 125 126 | static int DeleteArray(Tcl_Interp *, Array*); static void SvAllocateContainers(Bucket*); static void SvRegisterStdCommands(void); #ifdef SV_FINALIZE static void SvFinalizeContainers(Bucket*); | | | | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | static int DeleteArray(Tcl_Interp *, Array*); static void SvAllocateContainers(Bucket*); static void SvRegisterStdCommands(void); #ifdef SV_FINALIZE static void SvFinalizeContainers(Bucket*); static void SvFinalize(void *); #endif /* SV_FINALIZE */ static PsStore* GetPsStore(const char *handle); static int SvObjDispatchObjCmd(void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); /* *----------------------------------------------------------------------------- * * Sv_RegisterCommand -- * |
︙ | ︙ | |||
153 154 155 156 157 158 159 | const char *cmdName, /* Name of command to register */ Tcl_ObjCmdProc *objProc, /* Object-based command procedure */ Tcl_CmdDeleteProc *delProc, /* Command delete procedure */ int aolSpecial) { size_t len = strlen(cmdName) + strlen(TSV_CMD_PREFIX) + 1; size_t len2 = strlen(cmdName) + strlen(TSV_CMD2_PREFIX) + 1; | | | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | const char *cmdName, /* Name of command to register */ Tcl_ObjCmdProc *objProc, /* Object-based command procedure */ Tcl_CmdDeleteProc *delProc, /* Command delete procedure */ int aolSpecial) { size_t len = strlen(cmdName) + strlen(TSV_CMD_PREFIX) + 1; size_t len2 = strlen(cmdName) + strlen(TSV_CMD2_PREFIX) + 1; SvCmdInfo *newCmd = (SvCmdInfo *)Tcl_Alloc(sizeof(SvCmdInfo) + len + len2); /* * Setup new command structure */ newCmd->cmdName = (char*)((char*)newCmd + sizeof(SvCmdInfo)); newCmd->cmdName2 = newCmd->cmdName + len; |
︙ | ︙ | |||
220 221 222 223 224 225 226 | */ void Sv_RegisterObjType( const Tcl_ObjType *typePtr, /* Type of object to register */ Tcl_DupInternalRepProc *dupProc) /* Custom object duplicator */ { | | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | */ void Sv_RegisterObjType( const Tcl_ObjType *typePtr, /* Type of object to register */ Tcl_DupInternalRepProc *dupProc) /* Custom object duplicator */ { RegType *newType = (RegType *)Tcl_Alloc(sizeof(RegType)); /* * Setup new type structure */ newType->typePtr = typePtr; newType->dupIntRepProc = dupProc; |
︙ | ︙ | |||
259 260 261 262 263 264 265 | *----------------------------------------------------------------------------- */ void Sv_RegisterPsStore(const PsStore *psStorePtr) { | | | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | *----------------------------------------------------------------------------- */ void Sv_RegisterPsStore(const PsStore *psStorePtr) { PsStore *psPtr = (PsStore *)Tcl_Alloc(sizeof(PsStore)); *psPtr = *psStorePtr; /* * Plug-in in shared list */ |
︙ | ︙ | |||
346 347 348 349 350 351 352 | return TCL_BREAK; } } else { Tcl_HashTable *handles = &((*retObj)->bucketPtr->handles); LOCK_CONTAINER(*retObj); if (Tcl_FindHashEntry(handles, (char*)(*retObj)) == NULL) { UNLOCK_CONTAINER(*retObj); | | | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | return TCL_BREAK; } } else { Tcl_HashTable *handles = &((*retObj)->bucketPtr->handles); LOCK_CONTAINER(*retObj); if (Tcl_FindHashEntry(handles, (char*)(*retObj)) == NULL) { UNLOCK_CONTAINER(*retObj); Tcl_SetObjResult(interp, Tcl_NewStringObj("key has been deleted", TCL_AUTO_LENGTH)); return TCL_BREAK; } *offset = 2; /* Consumed two arguments: object, cmd */ } return TCL_OK; } |
︙ | ︙ | |||
400 401 402 403 404 405 406 | * * Results: * Pointer to the newly allocated persistent storage handler. Caller * must free this block when done with it. If none found, returns NULL, * * Side effects; * Memory gets allocated. Caller should free the return value of this | | | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | * * Results: * Pointer to the newly allocated persistent storage handler. Caller * must free this block when done with it. If none found, returns NULL, * * Side effects; * Memory gets allocated. Caller should free the return value of this * function using Tcl_Free(). * *----------------------------------------------------------------------------- */ static PsStore* GetPsStore(const char *handle) { |
︙ | ︙ | |||
467 468 469 470 471 472 473 | */ Tcl_MutexLock(&svMutex); for (tmpPtr = psStore; tmpPtr; tmpPtr = tmpPtr->nextPtr) { if (strcmp(tmpPtr->type, type) == 0) { tmpPtr->psHandle = tmpPtr->psOpen(addr); if (tmpPtr->psHandle) { | | | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | */ Tcl_MutexLock(&svMutex); for (tmpPtr = psStore; tmpPtr; tmpPtr = tmpPtr->nextPtr) { if (strcmp(tmpPtr->type, type) == 0) { tmpPtr->psHandle = tmpPtr->psOpen(addr); if (tmpPtr->psHandle) { psPtr = (PsStore *)Tcl_Alloc(sizeof(PsStore)); *psPtr = *tmpPtr; psPtr->nextPtr = NULL; } break; } } Tcl_MutexUnlock(&svMutex); |
︙ | ︙ | |||
571 572 573 574 575 576 577 | case SV_CHANGED: if (psPtr) { key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr); val = Tcl_GetString(svObj->tclObj); len = svObj->tclObj->length; if (psPtr->psPut(psPtr->psHandle, key, val, len) == -1) { const char *err = psPtr->psError(psPtr->psHandle); | | | 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | case SV_CHANGED: if (psPtr) { key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr); val = Tcl_GetString(svObj->tclObj); len = svObj->tclObj->length; if (psPtr->psPut(psPtr->psHandle, key, val, len) == -1) { const char *err = psPtr->psError(psPtr->psHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH)); return TCL_ERROR; } } return TCL_OK; } return TCL_ERROR; /* Should never be reached */ |
︙ | ︙ | |||
804 805 806 807 808 809 810 | Tcl_HashEntry *hPtr; hPtr = Tcl_CreateHashEntry(&bucketPtr->arrays, arrayName, &isNew); if (!isNew) { return (Array*)Tcl_GetHashValue(hPtr); } | | | 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | Tcl_HashEntry *hPtr; hPtr = Tcl_CreateHashEntry(&bucketPtr->arrays, arrayName, &isNew); if (!isNew) { return (Array*)Tcl_GetHashValue(hPtr); } arrayPtr = (Array *)Tcl_Alloc(sizeof(Array)); arrayPtr->bucketPtr = bucketPtr; arrayPtr->entryPtr = hPtr; arrayPtr->psPtr = NULL; arrayPtr->bindAddr = NULL; Tcl_InitHashTable(&arrayPtr->vars, TCL_STRING_KEYS); Tcl_SetHashValue(hPtr, arrayPtr); |
︙ | ︙ | |||
837 838 839 840 841 842 843 | */ static int UnbindArray(Tcl_Interp *interp, Array *arrayPtr) { PsStore *psPtr = arrayPtr->psPtr; if (arrayPtr->bindAddr) { | | | | 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 | */ static int UnbindArray(Tcl_Interp *interp, Array *arrayPtr) { PsStore *psPtr = arrayPtr->psPtr; if (arrayPtr->bindAddr) { Tcl_Free(arrayPtr->bindAddr); arrayPtr->bindAddr = NULL; } if (psPtr) { if (psPtr->psClose(psPtr->psHandle) == -1) { if (interp) { const char *err = psPtr->psError(psPtr->psHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(err, -1)); } return TCL_ERROR; } Tcl_Free(arrayPtr->psPtr), arrayPtr->psPtr = NULL; arrayPtr->psPtr = NULL; } return TCL_OK; } static int DeleteArray(Tcl_Interp *interp, Array *arrayPtr) |
︙ | ︙ | |||
870 871 872 873 874 875 876 | }; } if (arrayPtr->entryPtr) { Tcl_DeleteHashEntry(arrayPtr->entryPtr); } Tcl_DeleteHashTable(&arrayPtr->vars); | | | 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 | }; } if (arrayPtr->entryPtr) { Tcl_DeleteHashEntry(arrayPtr->entryPtr); } Tcl_DeleteHashTable(&arrayPtr->vars); Tcl_Free(arrayPtr); return TCL_OK; } /* *----------------------------------------------------------------------------- * |
︙ | ︙ | |||
902 903 904 905 906 907 908 | Container tmp[2]; size_t objSizePlusPadding = (size_t)(((char*)(tmp+1))-(char*)tmp); size_t bytesToAlloc = (OBJS_TO_ALLOC_EACH_TIME * objSizePlusPadding); char *basePtr; Container *prevPtr = NULL, *objPtr = NULL; int i; | | | 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | Container tmp[2]; size_t objSizePlusPadding = (size_t)(((char*)(tmp+1))-(char*)tmp); size_t bytesToAlloc = (OBJS_TO_ALLOC_EACH_TIME * objSizePlusPadding); char *basePtr; Container *prevPtr = NULL, *objPtr = NULL; int i; basePtr = (char *)Tcl_Alloc(bytesToAlloc); memset(basePtr, 0, bytesToAlloc); objPtr = (Container*)basePtr; objPtr->chunkAddr = basePtr; /* Mark chunk address for reclaim */ for (i = 0; i < OBJS_TO_ALLOC_EACH_TIME; i++) { objPtr->nextPtr = prevPtr; |
︙ | ︙ | |||
941 942 943 944 945 946 947 | SvFinalizeContainers(Bucket *bucketPtr) { Container *tmpPtr, *objPtr = bucketPtr->freeCt; while (objPtr) { if (objPtr->chunkAddr == (char*)objPtr) { tmpPtr = objPtr->nextPtr; | | | 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | SvFinalizeContainers(Bucket *bucketPtr) { Container *tmpPtr, *objPtr = bucketPtr->freeCt; while (objPtr) { if (objPtr->chunkAddr == (char*)objPtr) { tmpPtr = objPtr->nextPtr; Tcl_Free(objPtr); objPtr = tmpPtr; } else { objPtr = objPtr->nextPtr; } } } #endif /* SV_FINALIZE */ |
︙ | ︙ | |||
1053 1054 1055 1056 1057 1058 1059 | * Handle the string rep */ if (objPtr->bytes == NULL) { dupPtr->bytes = NULL; } else if (objPtr->bytes != Sv_tclEmptyStringRep) { /* A copy of TclInitStringRep macro */ | | | 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | * Handle the string rep */ if (objPtr->bytes == NULL) { dupPtr->bytes = NULL; } else if (objPtr->bytes != Sv_tclEmptyStringRep) { /* A copy of TclInitStringRep macro */ dupPtr->bytes = (char *)Tcl_Alloc(objPtr->length + 1); if (objPtr->length > 0) { memcpy((void*)dupPtr->bytes,(void*)objPtr->bytes, (unsigned)objPtr->length); } dupPtr->length = objPtr->length; dupPtr->bytes[objPtr->length] = '\0'; } |
︙ | ︙ | |||
1084 1085 1086 1087 1088 1089 1090 | * Depends on the dispatched command * *----------------------------------------------------------------------------- */ static int SvObjDispatchObjCmd( | | | 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | * Depends on the dispatched command * *----------------------------------------------------------------------------- */ static int SvObjDispatchObjCmd( void *arg, /* Pointer to object container. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { const char *cmdName; SvCmdInfo *cmdPtr; |
︙ | ︙ | |||
1134 1135 1136 1137 1138 1139 1140 | * New Tcl command gets created. * *----------------------------------------------------------------------------- */ static int SvObjObjCmd( | | | | 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | * New Tcl command gets created. * *----------------------------------------------------------------------------- */ static int SvObjObjCmd( void *arg, /* != NULL if aolSpecial */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int isNew, off, ret, flg; char buf[128]; Tcl_Obj *val = NULL; Container *svObj = NULL; |
︙ | ︙ | |||
1181 1182 1183 1184 1185 1186 1187 | * Format the command name */ sprintf(buf, "::%p", (int*)svObj); svObj->aolSpecial = (arg != NULL); Tcl_CreateObjCommand(interp, buf, SvObjDispatchObjCmd, svObj, NULL); Tcl_ResetResult(interp); | | | 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 | * Format the command name */ sprintf(buf, "::%p", (int*)svObj); svObj->aolSpecial = (arg != NULL); Tcl_CreateObjCommand(interp, buf, SvObjDispatchObjCmd, svObj, NULL); Tcl_ResetResult(interp); Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_AUTO_LENGTH)); return Sv_PutContainer(interp, svObj, SV_UNCHANGED); } /* *----------------------------------------------------------------------------- * |
︙ | ︙ | |||
1205 1206 1207 1208 1209 1210 1211 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvArrayObjCmd( | | | | > | | 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvArrayObjCmd( void *arg, /* Pointer to object container. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int i, argx = 0, index, ret = TCL_OK; int lobjc = 0; const char *arrayName = NULL; Array *arrayPtr = NULL; Tcl_Obj **lobjv = NULL; Container *svObj, *elObj = NULL; static const char *const opts[] = { "set", "reset", "get", "names", "size", "exists", "isbound", "bind", "unbind", NULL }; enum options { ASET, ARESET, AGET, ANAMES, ASIZE, AEXISTS, AISBOUND, ABIND, AUNBIND }; |
︙ | ︙ | |||
1287 1288 1289 1290 1291 1292 1293 | } if (index == ARESET) { ret = FlushArray(arrayPtr); if (ret != TCL_OK) { if (arrayPtr->psPtr) { PsStore *psPtr = arrayPtr->psPtr; const char *err = psPtr->psError(psPtr->psHandle); | | | 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | } if (index == ARESET) { ret = FlushArray(arrayPtr); if (ret != TCL_OK) { if (arrayPtr->psPtr) { PsStore *psPtr = arrayPtr->psPtr; const char *err = psPtr->psError(psPtr->psHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH)); } goto cmdExit; } } for (i = 0; i < lobjc; i += 2) { const char *key = Tcl_GetString(lobjv[i]); elObj = AcquireContainer(arrayPtr, key, FLAGS_CREATEVAR); |
︙ | ︙ | |||
1314 1315 1316 1317 1318 1319 1320 | Tcl_Obj *resObj = Tcl_NewListObj(0, NULL); const char *pattern = (argx == 0) ? NULL : Tcl_GetString(objv[argx]); Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search); while (hPtr) { char *key = (char *)Tcl_GetHashKey(&arrayPtr->vars, hPtr); if (pattern == NULL || Tcl_StringCaseMatch(key, pattern, 0)) { Tcl_ListObjAppendElement(interp, resObj, | | | 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 | Tcl_Obj *resObj = Tcl_NewListObj(0, NULL); const char *pattern = (argx == 0) ? NULL : Tcl_GetString(objv[argx]); Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search); while (hPtr) { char *key = (char *)Tcl_GetHashKey(&arrayPtr->vars, hPtr); if (pattern == NULL || Tcl_StringCaseMatch(key, pattern, 0)) { Tcl_ListObjAppendElement(interp, resObj, Tcl_NewStringObj(key, TCL_AUTO_LENGTH)); if (index == AGET) { elObj = (Container*)Tcl_GetHashValue(hPtr); Tcl_ListObjAppendElement(interp, resObj, Sv_DuplicateObj(elObj->tclObj)); } } hPtr = Tcl_NextHashEntry(&search); |
︙ | ︙ | |||
1372 1373 1374 1375 1376 1377 1378 | ret = TCL_ERROR; goto cmdExit; } if (arrayPtr) { Tcl_HashSearch search; hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search); arrayPtr->psPtr = psPtr; | | | | 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | ret = TCL_ERROR; goto cmdExit; } if (arrayPtr) { Tcl_HashSearch search; hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search); arrayPtr->psPtr = psPtr; arrayPtr->bindAddr = strcpy((char *)Tcl_Alloc(len+1), psurl); while (hPtr) { svObj = (Container *)Tcl_GetHashValue(hPtr); if (ReleaseContainer(interp, svObj, SV_CHANGED) != TCL_OK) { ret = TCL_ERROR; goto cmdExit; } hPtr = Tcl_NextHashEntry(&search); } } else { arrayPtr = LockArray(interp, arrayName, FLAGS_CREATEARRAY); arrayPtr->psPtr = psPtr; arrayPtr->bindAddr = strcpy((char *)Tcl_Alloc(len+1), psurl); } if (!psPtr->psFirst(psPtr->psHandle, &key, &val, &len)) { do { Tcl_Obj * tclObj = Tcl_NewStringObj(val, len); hPtr = Tcl_CreateHashEntry(&arrayPtr->vars, key, &isNew); Tcl_SetHashValue(hPtr, CreateContainer(arrayPtr, hPtr, tclObj)); psPtr->psFree(psPtr->psHandle, val); |
︙ | ︙ | |||
1434 1435 1436 1437 1438 1439 1440 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvUnsetObjCmd( | | | | 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvUnsetObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int ii; const char *arrayName; Array *arrayPtr; if (objc < 2) { |
︙ | ︙ | |||
1500 1501 1502 1503 1504 1505 1506 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvNamesObjCmd( | | | | 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvNamesObjCmd( void *arg, /* != NULL if aolSpecial */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int i; const char *pattern = NULL; Tcl_HashEntry *hPtr; Tcl_HashSearch search; Tcl_Obj *resObj; |
︙ | ︙ | |||
1561 1562 1563 1564 1565 1566 1567 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvGetObjCmd( | | | | 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvGetObjCmd( void *arg, /* Pointer to object container. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int off, ret; Tcl_Obj *res; Container *svObj = (Container*)arg; /* |
︙ | ︙ | |||
1626 1627 1628 1629 1630 1631 1632 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvExistsObjCmd( | | | | 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvExistsObjCmd( void *arg, /* Pointer to object container. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int off, ret; Container *svObj = (Container*)arg; /* * Syntax: |
︙ | ︙ | |||
1673 1674 1675 1676 1677 1678 1679 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvSetObjCmd( | | | | 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvSetObjCmd( void *arg, /* Pointer to object container */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int ret, off, flg, mode; Tcl_Obj *val; Container *svObj = (Container*)arg; /* |
︙ | ︙ | |||
1740 1741 1742 1743 1744 1745 1746 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvIncrObjCmd( | | | | 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvIncrObjCmd( void *arg, /* Pointer to object container */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int off, ret, flg, isNew = 0; Tcl_WideInt incrValue = 1, currValue = 0; Container *svObj = (Container*)arg; /* |
︙ | ︙ | |||
1813 1814 1815 1816 1817 1818 1819 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvAppendObjCmd( | | | | 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvAppendObjCmd( void *arg, /* Pointer to object container */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int i, off, flg, ret; Container *svObj = (Container*)arg; /* * Syntax: |
︙ | ︙ | |||
1867 1868 1869 1870 1871 1872 1873 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvPopObjCmd( | | | | 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvPopObjCmd( void *arg, /* Pointer to object container */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int ret, off; Tcl_Obj *retObj; Array *arrayPtr = NULL; Container *svObj = (Container*)arg; |
︙ | ︙ | |||
1907 1908 1909 1910 1911 1912 1913 | retObj = svObj->tclObj; svObj->tclObj = NULL; if (DeleteContainer(svObj) != TCL_OK) { if (svObj->arrayPtr->psPtr) { PsStore *psPtr = svObj->arrayPtr->psPtr; const char *err = psPtr->psError(psPtr->psHandle); | | | 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 | retObj = svObj->tclObj; svObj->tclObj = NULL; if (DeleteContainer(svObj) != TCL_OK) { if (svObj->arrayPtr->psPtr) { PsStore *psPtr = svObj->arrayPtr->psPtr; const char *err = psPtr->psError(psPtr->psHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH)); } ret = TCL_ERROR; goto cmd_exit; } if ((objc - off) == 0) { Tcl_SetObjResult(interp, retObj); |
︙ | ︙ | |||
1950 1951 1952 1953 1954 1955 1956 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvMoveObjCmd( | | | | 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvMoveObjCmd( void *arg, /* Pointer to object container. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int ret, off, isNew; const char *toKey; Tcl_HashEntry *hPtr; Container *svObj = (Container*)arg; |
︙ | ︙ | |||
1984 1985 1986 1987 1988 1989 1990 | } if (svObj->entryPtr) { char *key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr); if (svObj->arrayPtr->psPtr) { PsStore *psPtr = svObj->arrayPtr->psPtr; if (psPtr->psDelete(psPtr->psHandle, key) == -1) { const char *err = psPtr->psError(psPtr->psHandle); | | | 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 | } if (svObj->entryPtr) { char *key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr); if (svObj->arrayPtr->psPtr) { PsStore *psPtr = svObj->arrayPtr->psPtr; if (psPtr->psDelete(psPtr->psHandle, key) == -1) { const char *err = psPtr->psError(psPtr->psHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH)); return TCL_ERROR; } } Tcl_DeleteHashEntry(svObj->entryPtr); } svObj->entryPtr = hPtr; |
︙ | ︙ | |||
2020 2021 2022 2023 2024 2025 2026 | * See the user documentation. * *---------------------------------------------------------------------- */ static int SvLockObjCmd( | | | | 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 | * See the user documentation. * *---------------------------------------------------------------------- */ static int SvLockObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { int ret; Tcl_Obj *scriptObj; Bucket *bucketPtr; Array *arrayPtr = NULL; |
︙ | ︙ | |||
2065 2066 2067 2068 2069 2070 2071 | ret = Tcl_EvalObjEx(interp, scriptObj, TCL_EVAL_DIRECT); if (ret == TCL_ERROR) { char msg[32 + TCL_INTEGER_SPACE]; /* Next line generates a Deprecation warning when compiled with Tcl 8.6. * See Tcl bug #3562640 */ sprintf(msg, "\n (\"eval\" body line %d)", Tcl_GetErrorLine(interp)); | | | 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 | ret = Tcl_EvalObjEx(interp, scriptObj, TCL_EVAL_DIRECT); if (ret == TCL_ERROR) { char msg[32 + TCL_INTEGER_SPACE]; /* Next line generates a Deprecation warning when compiled with Tcl 8.6. * See Tcl bug #3562640 */ sprintf(msg, "\n (\"eval\" body line %d)", Tcl_GetErrorLine(interp)); Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(msg, TCL_AUTO_LENGTH)); } /* * We unlock the bucket directly, w/o going to Sv_Unlock() * since it needs the array which may be unset by the script. */ |
︙ | ︙ | |||
2096 2097 2098 2099 2100 2101 2102 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int SvHandlersObjCmd( | | | 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int SvHandlersObjCmd( void *arg, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { PsStore *tmpPtr = NULL; /* |
︙ | ︙ | |||
2261 2262 2263 2264 2265 2266 2267 | /* * Plug-in registered commands in current interpreter */ for (cmdPtr = svCmdInfo; cmdPtr; cmdPtr = cmdPtr->nextPtr) { Tcl_CreateObjCommand(interp, cmdPtr->cmdName, cmdPtr->objProcPtr, | | | | | 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 | /* * Plug-in registered commands in current interpreter */ for (cmdPtr = svCmdInfo; cmdPtr; cmdPtr = cmdPtr->nextPtr) { Tcl_CreateObjCommand(interp, cmdPtr->cmdName, cmdPtr->objProcPtr, NULL, NULL); #ifdef NS_AOLSERVER Tcl_CreateObjCommand(interp, cmdPtr->cmdName2, cmdPtr->objProcPtr, (void *)(size_t)cmdPtr->aolSpecial, NULL); #endif } /* * Create array of buckets and initialize each bucket */ if (buckets == NULL) { Tcl_MutexLock(&bucketsMutex); if (buckets == NULL) { buckets = (Bucket *)Tcl_Alloc(sizeof(Bucket) * NUMBUCKETS); for (i = 0; i < NUMBUCKETS; ++i) { bucketPtr = &buckets[i]; memset(bucketPtr, 0, sizeof(Bucket)); Tcl_InitHashTable(&bucketPtr->arrays, TCL_STRING_KEYS); Tcl_InitHashTable(&bucketPtr->handles, TCL_ONE_WORD_KEYS); } |
︙ | ︙ | |||
2336 2337 2338 2339 2340 2341 2342 | * Side effects * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void | | | 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 | * Side effects * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void SvFinalize (void *clientData) { int i; SvCmdInfo *cmdPtr; RegType *regPtr; Tcl_HashEntry *hashPtr; Tcl_HashSearch search; |
︙ | ︙ | |||
2383 2384 2385 2386 2387 2388 2389 | if (bucketPtr->lock) { Sp_RecursiveMutexFinalize(&bucketPtr->lock); } SvFinalizeContainers(bucketPtr); Tcl_DeleteHashTable(&bucketPtr->handles); Tcl_DeleteHashTable(&bucketPtr->arrays); } | | | | | 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 | if (bucketPtr->lock) { Sp_RecursiveMutexFinalize(&bucketPtr->lock); } SvFinalizeContainers(bucketPtr); Tcl_DeleteHashTable(&bucketPtr->handles); Tcl_DeleteHashTable(&bucketPtr->arrays); } Tcl_Free(buckets), buckets = NULL; } buckets = NULL; Tcl_MutexUnlock(&bucketsMutex); } Tcl_MutexLock(&svMutex); /* * Reclaim memory for registered commands */ if (svCmdInfo != NULL) { cmdPtr = svCmdInfo; while (cmdPtr) { SvCmdInfo *tmpPtr = cmdPtr->nextPtr; Tcl_Free(cmdPtr); cmdPtr = tmpPtr; } svCmdInfo = NULL; } /* * Reclaim memory for registered object types */ if (regType != NULL) { regPtr = regType; while (regPtr) { RegType *tmpPtr = regPtr->nextPtr; Tcl_Free(regPtr); regPtr = tmpPtr; } regType = NULL; } Tcl_MutexUnlock(&svMutex); |
︙ | ︙ |
Changes to generic/threadSvCmd.h.
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #ifndef _SV_H_ #define _SV_H_ #include <tcl.h> #include <ctype.h> #include <string.h> #include "threadSpCmd.h" /* For recursive locks */ /* * Uncomment following line to get command-line * compatibility with AOLserver nsv_* commands */ | > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #ifndef _SV_H_ #define _SV_H_ #include <tcl.h> #include <ctype.h> #include <string.h> #include "tclThreadInt.h" #include "threadSpCmd.h" /* For recursive locks */ /* * Uncomment following line to get command-line * compatibility with AOLserver nsv_* commands */ |
︙ | ︙ | |||
77 78 79 80 81 82 83 | #define SV_ERROR -1 /* Object may be in incosistent state */ /* * Definitions of functions implementing simple key/value * persistent storage for shared variable arrays. */ | | | | | | | | | | | | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #define SV_ERROR -1 /* Object may be in incosistent state */ /* * Definitions of functions implementing simple key/value * persistent storage for shared variable arrays. */ typedef void *(ps_open_proc)(const char*); typedef int (ps_get_proc) (void *, const char*, char**, size_t*); typedef int (ps_put_proc) (void *, const char*, char*, size_t); typedef int (ps_first_proc) (void *, char**, char**, size_t*); typedef int (ps_next_proc) (void *, char**, char**, size_t*); typedef int (ps_delete_proc)(void *, const char*); typedef int (ps_close_proc) (void *); typedef void(ps_free_proc) (void *, void*); typedef const char* (ps_geterr_proc)(void *); /* * This structure maintains a bunch of pointers to functions implementing * the simple persistence layer for the shared variable arrays. */ typedef struct PsStore { const char *type; /* Type identifier of the persistent storage */ void *psHandle; /* Handle to the opened storage */ ps_open_proc *psOpen; /* Function to open the persistent key store */ ps_get_proc *psGet; /* Function to retrieve value bound to key */ ps_put_proc *psPut; /* Function to store user key and value */ ps_first_proc *psFirst; /* Function to retrieve the first key/value */ ps_next_proc *psNext; /* Function to retrieve the next key/value */ ps_delete_proc *psDelete; /* Function to delete user key and value */ ps_close_proc *psClose; /* Function to close the persistent store */ |
︙ | ︙ |
Changes to generic/threadSvListCmd.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* * Implementation of most standard Tcl list processing commands * suitable for operation on thread shared (list) variables. * * Copyright (c) 2002 by Zoran Vasiljevic. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * ---------------------------------------------------------------------------- */ #include "threadSvCmd.h" #include "threadSvListCmd.h" | > < < < < < < < < < < < < < < < < < < < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* * Implementation of most standard Tcl list processing commands * suitable for operation on thread shared (list) variables. * * Copyright (c) 2002 by Zoran Vasiljevic. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * ---------------------------------------------------------------------------- */ #include "tclThreadInt.h" #include "threadSvCmd.h" #include "threadSvListCmd.h" /* * Implementation of list commands for shared variables. * Most of the standard Tcl list commands are implemented. * There are also two new commands: "lpop" and "lpush". * Those are very convenient for simple stack operations. * |
︙ | ︙ | |||
146 147 148 149 150 151 152 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpopObjCmd ( | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpopObjCmd ( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int ret, off, llen, iarg = 0; size_t index = 0; Tcl_Obj *elPtr = NULL; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lpop array key ?index? * $list lpop ?index? |
︙ | ︙ | |||
183 184 185 186 187 188 189 | } if (iarg) { ret = Tcl_GetIntForIndex(interp, objv[iarg], llen-1, &index); if (ret != TCL_OK) { goto cmd_err; } } | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | } if (iarg) { ret = Tcl_GetIntForIndex(interp, objv[iarg], llen-1, &index); if (ret != TCL_OK) { goto cmd_err; } } if (index >= (size_t)llen) { goto cmd_ok; /* Ignore out-of bounds, like Tcl does */ } ret = Tcl_ListObjIndex(interp, svObj->tclObj, index, &elPtr); if (ret != TCL_OK) { goto cmd_err; } |
︙ | ︙ | |||
226 227 228 229 230 231 232 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpushObjCmd ( | | | | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpushObjCmd ( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int off, ret, flg, llen; size_t index = 0; Tcl_Obj *args[1]; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lpush array key element ?index? * $list lpush element ?index? |
︙ | ︙ | |||
260 261 262 263 264 265 266 | goto cmd_err; } if ((objc - off) == 2) { ret = Tcl_GetIntForIndex(interp, objv[off+1], llen, &index); if (ret != TCL_OK) { goto cmd_err; } | | | | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | goto cmd_err; } if ((objc - off) == 2) { ret = Tcl_GetIntForIndex(interp, objv[off+1], llen, &index); if (ret != TCL_OK) { goto cmd_err; } if (index == TCL_INDEX_NONE) { index = 0; } else if (index > (size_t)llen) { index = llen; } } args[0] = Sv_DuplicateObj(objv[off]); ret = Tcl_ListObjReplace(interp, svObj->tclObj, index, 0, 1, args); if (ret != TCL_OK) { |
︙ | ︙ | |||
299 300 301 302 303 304 305 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLappendObjCmd( | | | 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLappendObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int i, ret, flg, off; Tcl_Obj *dup; Container *svObj = (Container*)arg; |
︙ | ︙ | |||
359 360 361 362 363 364 365 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLreplaceObjCmd( | | | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLreplaceObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { const char *firstArg; size_t argLen; int ret, off, llen, ndel, nargs, i, j; size_t first, last; Tcl_Obj **args = NULL; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lreplace array key first last ?element ...? * $list lreplace first last ?element ...? |
︙ | ︙ | |||
400 401 402 403 404 405 406 | ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last); if (ret != TCL_OK) { goto cmd_err; } firstArg = Tcl_GetString(objv[off]); argLen = objv[off]->length; | | | | | | | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last); if (ret != TCL_OK) { goto cmd_err; } firstArg = Tcl_GetString(objv[off]); argLen = objv[off]->length; if (first == TCL_INDEX_NONE) { first = 0; } if (llen && first >= (size_t)llen && strncmp(firstArg, "end", argLen)) { Tcl_AppendResult(interp, "list doesn't have element ", firstArg, NULL); goto cmd_err; } if (last + 1 >= (size_t)llen + 1) { last = llen - 1; } if (first + 1 <= last + 1) { ndel = last - first + 1; } else { ndel = 0; } nargs = objc - (off + 2); if (nargs) { args = (Tcl_Obj**)Tcl_Alloc(nargs * sizeof(Tcl_Obj*)); for(i = off + 2, j = 0; i < objc; i++, j++) { args[j] = Sv_DuplicateObj(objv[i]); } } ret = Tcl_ListObjReplace(interp, svObj->tclObj, first, ndel, nargs, args); if (args) { if (ret != TCL_OK) { for(i = off + 2, j = 0; i < objc; i++, j++) { Tcl_DecrRefCount(args[j]); } } Tcl_Free(args); } return Sv_PutContainer(interp, svObj, SV_CHANGED); cmd_err: return Sv_PutContainer(interp, svObj, SV_ERROR); } |
︙ | ︙ | |||
459 460 461 462 463 464 465 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLrangeObjCmd( | | | | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLrangeObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int ret, off, llen, nargs, j; size_t first, last, i; Tcl_Obj **elPtrs, **args; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lrange array key first last * $list lrange first last |
︙ | ︙ | |||
495 496 497 498 499 500 501 | if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last); if (ret != TCL_OK) { goto cmd_err; } | | | | | | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last); if (ret != TCL_OK) { goto cmd_err; } if (first == TCL_INDEX_NONE) { first = 0; } if (last + 1 >= (size_t)llen + 1) { last = llen - 1; } if (first + 1 > last + 1) { goto cmd_ok; } nargs = last - first + 1; args = (Tcl_Obj **)Tcl_Alloc(nargs * sizeof(Tcl_Obj *)); for (i = first, j = 0; i <= last; i++, j++) { args[j] = Sv_DuplicateObj(elPtrs[i]); } Tcl_ResetResult(interp); Tcl_SetListObj(Tcl_GetObjResult(interp), nargs, args); Tcl_Free(args); cmd_ok: return Sv_PutContainer(interp, svObj, SV_UNCHANGED); cmd_err: return Sv_PutContainer(interp, svObj, SV_ERROR); } |
︙ | ︙ | |||
541 542 543 544 545 546 547 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLinsertObjCmd( | | | | 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLinsertObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int off, ret, flg, llen, nargs, i, j; size_t index = 0; Tcl_Obj **args; Container *svObj = (Container*)arg; /* * Syntax: * tsv::linsert array key index element ?element ...? * $list linsert element ?element ...? |
︙ | ︙ | |||
574 575 576 577 578 579 580 | if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen, &index); if (ret != TCL_OK) { goto cmd_err; } | | | | | | | 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen, &index); if (ret != TCL_OK) { goto cmd_err; } if (index == TCL_INDEX_NONE) { index = 0; } else if (index > (size_t)llen) { index = llen; } nargs = objc - (off + 1); args = (Tcl_Obj **)Tcl_Alloc(nargs * sizeof(Tcl_Obj *)); for (i = off + 1, j = 0; i < objc; i++, j++) { args[j] = Sv_DuplicateObj(objv[i]); } ret = Tcl_ListObjReplace(interp, svObj->tclObj, index, 0, nargs, args); if (ret != TCL_OK) { for (i = off + 1, j = 0; i < objc; i++, j++) { Tcl_DecrRefCount(args[j]); } Tcl_Free(args); goto cmd_err; } Tcl_Free(args); return Sv_PutContainer(interp, svObj, SV_CHANGED); cmd_err: return Sv_PutContainer(interp, svObj, SV_ERROR); } |
︙ | ︙ | |||
621 622 623 624 625 626 627 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLlengthObjCmd( | | | 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLlengthObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int llen, off, ret; Container *svObj = (Container*)arg; |
︙ | ︙ | |||
670 671 672 673 674 675 676 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLsearchObjCmd( | | | | 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLsearchObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { size_t length; int ret, off, listc, mode, imode, ipatt, index, match, i; const char *patBytes; Tcl_Obj **listv; Container *svObj = (Container*)arg; static const char *const modes[] = {"-exact", "-glob", "-regexp", NULL}; enum {LS_EXACT, LS_GLOB, LS_REGEXP}; mode = LS_GLOB; /* * Syntax: * tsv::lsearch array key ?mode? pattern |
︙ | ︙ | |||
776 777 778 779 780 781 782 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLindexObjCmd( | | | | 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLindexObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { Tcl_Obj **elPtrs; int ret, off, llen; size_t index; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lindex array key index * $list lindex index */ |
︙ | ︙ | |||
808 809 810 811 812 813 814 | if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &index); if (ret != TCL_OK) { goto cmd_err; } | | | 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &index); if (ret != TCL_OK) { goto cmd_err; } if (index < (size_t)llen) { Tcl_SetObjResult(interp, Sv_DuplicateObj(elPtrs[index])); } return Sv_PutContainer(interp, svObj, SV_UNCHANGED); cmd_err: return Sv_PutContainer(interp, svObj, SV_ERROR); |
︙ | ︙ | |||
837 838 839 840 841 842 843 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLsetObjCmd( | | | 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLsetObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { Tcl_Obj *lPtr; int ret, argc, off; Container *svObj = (Container*)arg; |
︙ | ︙ | |||
904 905 906 907 908 909 910 | */ static void DupListObjShared( Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ Tcl_Obj *copyPtr /* Object with internal rep to set. */ ) { | > | | | | 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 | */ static void DupListObjShared( Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ Tcl_Obj *copyPtr /* Object with internal rep to set. */ ) { int i; int llen; Tcl_Obj *elObj, **newObjList; Tcl_ListObjLength(NULL, srcPtr, &llen); if (llen == 0) { (*srcPtr->typePtr->dupIntRepProc)(srcPtr, copyPtr); copyPtr->refCount = 0; return; } newObjList = (Tcl_Obj **)Tcl_Alloc(llen*sizeof(Tcl_Obj *)); for (i = 0; i < llen; i++) { Tcl_ListObjIndex(NULL, srcPtr, i, &elObj); newObjList[i] = Sv_DuplicateObj(elObj); } Tcl_SetListObj(copyPtr, llen, newObjList); Tcl_Free(newObjList); } /* *---------------------------------------------------------------------- * * SvLsetFlat -- * |
︙ | ︙ | |||
950 951 952 953 954 955 956 | Tcl_Interp *interp, /* Tcl interpreter */ Tcl_Obj *listPtr, /* Pointer to the list being modified */ int indexCount, /* Number of index args */ Tcl_Obj **indexArray, Tcl_Obj *valuePtr /* Value arg to 'lset' */ ) { int elemCount, result, i; | | | 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | Tcl_Interp *interp, /* Tcl interpreter */ Tcl_Obj *listPtr, /* Pointer to the list being modified */ int indexCount, /* Number of index args */ Tcl_Obj **indexArray, Tcl_Obj *valuePtr /* Value arg to 'lset' */ ) { int elemCount, result, i; size_t index; Tcl_Obj **elemPtrs, *chainPtr, *subListPtr; /* * Determine whether the index arg designates a list * or a single index. */ |
︙ | ︙ | |||
1015 1016 1017 1018 1019 1020 1021 | break; } /* * Check that the index is in range. */ | | | 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | break; } /* * Check that the index is in range. */ if (index >= (size_t)elemCount) { Tcl_SetObjResult(interp, Tcl_NewStringObj("list index out of range", -1)); result = TCL_ERROR; break; } /* |
︙ | ︙ |
Changes to lib/ttrace.tcl.
︙ | ︙ | |||
69 70 71 72 73 74 75 | interp alias {} [namespace current]::_set {} tsv::set interp alias {} [namespace current]::_unset {} tsv::unset } else { error "requires NaviServer/AOLserver or Tcl threading extension" } # Keep in sync with the Thread package | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | interp alias {} [namespace current]::_set {} tsv::set interp alias {} [namespace current]::_unset {} tsv::unset } else { error "requires NaviServer/AOLserver or Tcl threading extension" } # Keep in sync with the Thread package package provide Ttrace 3.0a1 # Package variables variable resolvers "" ; # List of registered resolvers variable tracers "" ; # List of registered cmd tracers variable scripts "" ; # List of registered script makers variable enables "" ; # List of trace-enable callbacks variable disables "" ; # List of trace-disable callbacks |
︙ | ︙ |
Changes to pkgIndex.tcl.in.
1 2 3 4 | # -*- tcl -*- # Tcl package index file, version 1.1 # | < < | > | > | | | | < | < < < < < < < < < < < < < < < < < < < < < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # -*- tcl -*- # Tcl package index file, version 1.1 # # Tcl 8.6 interps are only supported on 32-bit platforms. # Lower than that is never supported. Bye! if {![package vsatisfies [package provide Tcl] 9.0] && ((![package vsatisfies [package provide Tcl] 8.6]) || ($::tcl_platform(pointerSize)!=4))} { return } # All Tcl 8.6+ interps can [load] Thread @PACKAGE_VERSION@ # # For interps that are not thread-enabled, we still call [package ifneeded]. # This is contrary to the usual convention, but is a good idea because we # cannot imagine any other version of Thread that might succeed in a # thread-disabled interp. There's nothing to gain by yielding to other # competing callers of [package ifneeded Thread]. On the other hand, # deferring the error has the advantage that a script calling # [package require Thread] in a thread-disabled interp gets an error message # about a thread-disabled interp, instead of the message # "can't find package Thread". package ifneeded Thread @PACKAGE_VERSION@ [list load [file join $dir @PKG_LIB_FILE@]] # package Ttrace uses some support machinery. # In Tcl 8.6+ interps; use [::apply] package ifneeded Ttrace @PACKAGE_VERSION@ [list ::apply {{dir} { if {[info exists ::env(TCL_THREAD_LIBRARY)] && [file readable $::env(TCL_THREAD_LIBRARY)/ttrace.tcl]} { source $::env(TCL_THREAD_LIBRARY)/ttrace.tcl } elseif {[file readable [file join $dir .. lib ttrace.tcl]]} { source [file join $dir .. lib ttrace.tcl] |
︙ | ︙ |
Changes to tcl/cmdsrv/cmdsrv.tcl.
︙ | ︙ | |||
23 24 25 26 27 28 29 | # # Copyright (c) 2002 by Zoran Vasiljevic. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ----------------------------------------------------------------------------- | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # # Copyright (c) 2002 by Zoran Vasiljevic. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ----------------------------------------------------------------------------- package require Tcl 8.5- package require Thread 2.5- namespace eval cmdsrv { variable data; # Stores global configuration options } # # cmdsrv::create -- |
︙ | ︙ |
Changes to tcl/phttpd/phttpd.tcl.
︙ | ︙ | |||
28 29 30 31 32 33 34 | # # Copyright (c) 2002 by Zoran Vasiljevic. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ----------------------------------------------------------------------------- | | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # # Copyright (c) 2002 by Zoran Vasiljevic. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ----------------------------------------------------------------------------- package require Tcl 8.5- package require Thread 2.5- # # Modify the following in order to load the # example Tcl implementation of threadpools. # Per default, the C-level threadpool is used. # |
︙ | ︙ |
Changes to tcl/tpool/tpool.tcl.
︙ | ︙ | |||
19 20 21 22 23 24 25 | # # Copyright (c) 2002 by Zoran Vasiljevic. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ----------------------------------------------------------------------------- | > | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # # Copyright (c) 2002 by Zoran Vasiljevic. # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ----------------------------------------------------------------------------- package require Tcl 8.5- package require Thread 2.5- set thisScript [info script] namespace eval tpool { variable afterevent "" ; # Idle timer event for worker threads variable result ; # Stores result from the worker thread variable waiter ; # Waits for an idle worker thread |
︙ | ︙ |
Changes to win/pkg.vc.
1 2 3 | # remember to change configure.ac as well when these change # (then re-autoconf) | | | | | 1 2 3 4 5 6 | # remember to change configure.ac as well when these change # (then re-autoconf) PACKAGE_MAJOR = 3 PACKAGE_MINOR = 0 PACKAGE_VERSION = "3.0a1" |