Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Merge 2.8. Code cleanup. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | thread-2-branch |
Files: | files | file ages | folders |
SHA3-256: |
9385cfbabde7912d9f510c5900e878bb |
User & Date: | jan.nijtmans 2020-06-05 12:34:39.274 |
Context
2020-07-03
| ||
11:08 | Merge 2.8 check-in: 581fbfdef8 user: jan.nijtmans tags: thread-2-branch | |
2020-06-05
| ||
12:36 | Merge 2.9 check-in: e3f41974d5 user: jan.nijtmans tags: trunk | |
12:34 | Merge 2.8. Code cleanup. check-in: 9385cfbabd user: jan.nijtmans tags: thread-2-branch | |
2020-05-22
| ||
07:59 | Merge 2.8 check-in: 6558572b67 user: jan.nijtmans tags: thread-2-branch | |
Changes
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 | * 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; |
︙ | ︙ | |||
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 | * 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) |
︙ | ︙ | |||
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/threadCmd.c.
︙ | ︙ | |||
75 76 77 78 79 80 81 | * core, hard-wire the necessary APIs using the "well-known" offsets into the * stubs table. */ #if defined(TCL_TIP285) && !TCL_MINIMUM_VERSION(8,6) # if defined(USE_TCL_STUBS) # define TCL_CANCEL_UNWIND 0x100000 | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | * core, hard-wire the necessary APIs using the "well-known" offsets into the * stubs table. */ #if defined(TCL_TIP285) && !TCL_MINIMUM_VERSION(8,6) # if defined(USE_TCL_STUBS) # define TCL_CANCEL_UNWIND 0x100000 # define Tcl_CancelEval ((int (*)(Tcl_Interp *, Tcl_Obj *, void *, int)) \ ((&(tclStubsPtr->tcl_PkgProvideEx))[580])) # define Tcl_Canceled ((int (*)(Tcl_Interp *, int)) \ ((&(tclStubsPtr->tcl_PkgProvideEx))[581])) # else # error "Supporting TIP #285 requires USE_TCL_STUBS before Tcl 8.6" # endif #endif |
︙ | ︙ | |||
159 160 161 162 163 164 165 | 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 */ | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | 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; | | | | | 199 200 201 202 203 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 232 233 234 235 236 237 238 | 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 | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | /* * 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 | | | | | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | 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); |
︙ | ︙ | |||
589 590 591 592 593 594 595 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCreateObjCmd( | | | 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | * 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; |
︙ | ︙ | |||
641 642 643 644 645 646 647 | /* *---------------------------------------------------------------------- * * ThreadReserveObjCmd -- * * This procedure is invoked to process the "thread::preserve" and | | | < | | 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | /* *---------------------------------------------------------------------- * * 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; (void)dummy; |
︙ | ︙ | |||
699 700 701 702 703 704 705 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadReleaseObjCmd( | | | 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | * 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; (void)dummy; |
︙ | ︙ | |||
749 750 751 752 753 754 755 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadUnwindObjCmd( | | | 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | * 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. */ ) { (void)dummy; Init(interp); |
︙ | ︙ | |||
786 787 788 789 790 791 792 | * Lots. improper clean up of resources. * *---------------------------------------------------------------------- */ static int ThreadExitObjCmd( | | | 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | * 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; (void)dummy; |
︙ | ︙ | |||
833 834 835 836 837 838 839 | * None. * *---------------------------------------------------------------------- */ static int ThreadIdObjCmd( | | | | 832 833 834 835 836 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 | * 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]; (void)dummy; 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_INDEX_NONE)); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
875 876 877 878 879 880 881 | * None. * *---------------------------------------------------------------------- */ static int ThreadNamesObjCmd( | | | 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | * 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; |
︙ | ︙ | |||
948 949 950 951 952 953 954 | threadSendObjFree(void *ptr) { Tcl_DecrRefCount((Tcl_Obj *)ptr); } static int ThreadSendObjCmd( | | | 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 | 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; |
︙ | ︙ | |||
1009 1010 1011 1012 1013 1014 1015 | } if (var && (flags & THREAD_SEND_WAIT) == 0) { if (thrId == Tcl_GetCurrentThread()) { /* * FIXME: Do something for callbacks to self */ | | | | | 1008 1009 1010 1011 1012 1013 1014 1015 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 1043 1044 1045 1046 1047 1048 1049 | } 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_INDEX_NONE)); 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 *)ckalloc(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 *)ckalloc(sizeof(ThreadSendData)); sendPtr->interp = NULL; /* Signal to use thread main interp */ sendPtr->execProc = ThreadSendEval; sendPtr->freeProc = threadSendFree; sendPtr->clientData = memcpy(ckalloc(size), script, size); ret = ThreadSend(interp, thrId, sendPtr, clbkPtr, flags); |
︙ | ︙ | |||
1085 1086 1087 1088 1089 1090 1091 | * Script is sent to all known threads except the caller thread. * *---------------------------------------------------------------------- */ static int ThreadBroadcastObjCmd( | | | 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | * 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; |
︙ | ︙ | |||
1142 1143 1144 1145 1146 1147 1148 | * 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 */ } | | | 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | * 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 *)ckalloc(sizeof(ThreadSendData)); *sendPtr = job; sendPtr->clientData = memcpy(ckalloc(size), script, size); ThreadSend(interp, thrIdArray[ii], sendPtr, NULL, THREAD_SEND_HEAD); } ckfree((char*)thrIdArray); Tcl_ResetResult(interp); |
︙ | ︙ | |||
1173 1174 1175 1176 1177 1178 1179 | * Enters the event loop. * *---------------------------------------------------------------------- */ static int ThreadWaitObjCmd( | | | 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | * 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. */ ) { (void)dummy; Init(interp); |
︙ | ︙ | |||
1211 1212 1213 1214 1215 1216 1217 | * Registers an errorproc. * *---------------------------------------------------------------------- */ static int ThreadErrorProcObjCmd( | | | | 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 | * 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; (void)dummy; 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_INDEX_NONE)); } } else { if (errorProcString) { ckfree(errorProcString); } proc = Tcl_GetString(objv[1]); len = objv[1]->length; |
︙ | ︙ | |||
1255 1256 1257 1258 1259 1260 1261 | Tcl_MutexUnlock(&threadMutex); return TCL_OK; } static void ThreadFreeError( | | | 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 | Tcl_MutexUnlock(&threadMutex); return TCL_OK; } static void ThreadFreeError( void *dummy ) { (void)dummy; Tcl_MutexLock(&threadMutex); if (errorThreadId != Tcl_GetCurrentThread()) { Tcl_MutexUnlock(&threadMutex); return; |
︙ | ︙ | |||
1289 1290 1291 1292 1293 1294 1295 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadJoinObjCmd( | | | 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | * 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; (void)dummy; |
︙ | ︙ | |||
1334 1335 1336 1337 1338 1339 1340 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadTransferObjCmd( | | | 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 | * 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. */ ) { (void)dummy; Tcl_ThreadId thrId; |
︙ | ︙ | |||
1385 1386 1387 1388 1389 1390 1391 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadDetachObjCmd( | | | 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 | * 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; (void)dummy; |
︙ | ︙ | |||
1431 1432 1433 1434 1435 1436 1437 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadAttachObjCmd( | | | 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 | * 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; (void)dummy; |
︙ | ︙ | |||
1477 1478 1479 1480 1481 1482 1483 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadExistsObjCmd( | | | 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 | * 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; (void)dummy; |
︙ | ︙ | |||
1518 1519 1520 1521 1522 1523 1524 | * * Side effects: * None. *---------------------------------------------------------------------- */ static int ThreadConfigureObjCmd( | | | 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 | * * 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. */ |
︙ | ︙ | |||
1591 1592 1593 1594 1595 1596 1597 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCancelObjCmd( | | | 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 | * 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; |
︙ | ︙ | |||
1648 1649 1650 1651 1652 1653 1654 | * *---------------------------------------------------------------------- */ static int ThreadSendEval( Tcl_Interp *interp, | | | | | 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 | * *---------------------------------------------------------------------- */ static int ThreadSendEval( Tcl_Interp *interp, void *clientData ) { ThreadSendData *sendPtr = (ThreadSendData *)clientData; char *script = (char*)sendPtr->clientData; return Tcl_EvalEx(interp, script, TCL_INDEX_NONE, TCL_EVAL_GLOBAL); } /* *---------------------------------------------------------------------- * * ThreadClbkSetVar -- * |
︙ | ︙ | |||
1676 1677 1678 1679 1680 1681 1682 | * *---------------------------------------------------------------------- */ static int ThreadClbkSetVar( Tcl_Interp *interp, | | | 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | * *---------------------------------------------------------------------- */ 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; |
︙ | ︙ | |||
1727 1728 1729 1730 1731 1732 1733 | return TCL_OK; cleanup: Tcl_DecrRefCount(valObj); return rc; } | | | 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 | 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) { |
︙ | ︙ | |||
1790 1791 1792 1793 1794 1795 1796 | ctrl.condWait = NULL; ctrl.flags = 0; Tcl_MutexLock(&threadMutex); if (Tcl_CreateThread(&thrId, NewThread, &ctrl, stacksize, flags) != TCL_OK) { Tcl_MutexUnlock(&threadMutex); | | | 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 | 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_INDEX_NONE)); return TCL_ERROR; } /* * Wait for the thread to start because it is using * the ThreadCtrl argument which is on our stack. */ |
︙ | ︙ | |||
1817 1818 1819 1820 1821 1822 1823 | tsdPtr->refCount++; } Tcl_MutexUnlock(&threadMutex); Tcl_ConditionFinalize(&ctrl.condWait); ThreadGetHandle(thrId, thrHandle); | | | 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 | tsdPtr->refCount++; } Tcl_MutexUnlock(&threadMutex); Tcl_ConditionFinalize(&ctrl.condWait); ThreadGetHandle(thrId, thrHandle); Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_INDEX_NONE)); return TCL_OK; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1853 1854 1855 1856 1857 1858 1859 | * A Tcl script is executed in a new thread. * *---------------------------------------------------------------------- */ Tcl_ThreadCreateType NewThread( | | | 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 | * 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; |
︙ | ︙ | |||
1899 1900 1901 1902 1903 1904 1905 | /* * 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); | | | | 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 | /* * 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 *)ckalloc(scriptLen+1), ctrlPtr->script); Tcl_CreateThreadExitHandler(ThreadExitProc, evalScript); /* * Notify the parent we are alive. */ ctrlPtr->script = NULL; Tcl_ConditionNotify(&ctrlPtr->condWait); |
︙ | ︙ | |||
1999 2000 2001 2002 2003 2004 2005 | Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); if (errChannel == NULL) { /* Fixes the [#634845] bug; credits to * Wojciech Kocjan <wojciech@kocjan.org> */ return; } ThreadGetHandle(Tcl_GetCurrentThread(), buf); | | | | | | 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 | Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); if (errChannel == NULL) { /* Fixes the [#634845] bug; credits to * Wojciech Kocjan <wojciech@kocjan.org> */ return; } ThreadGetHandle(Tcl_GetCurrentThread(), buf); Tcl_WriteChars(errChannel, "Error from thread ", TCL_INDEX_NONE); Tcl_WriteChars(errChannel, buf, TCL_INDEX_NONE); Tcl_WriteChars(errChannel, "\n", 1); Tcl_WriteChars(errChannel, errorInfo, TCL_INDEX_NONE); Tcl_WriteChars(errChannel, "\n", 1); #endif } else { ThreadGetHandle(Tcl_GetCurrentThread(), buf); argv[0] = errorProcString; argv[1] = buf; argv[2] = errorInfo; sendPtr = (ThreadSendData *)ckalloc(sizeof(ThreadSendData)); sendPtr->execProc = ThreadSendEval; sendPtr->freeProc = threadSendFree; sendPtr->clientData = Tcl_Merge(3, argv); sendPtr->interp = NULL; ThreadSend(interp, errorThreadId, sendPtr, NULL, 0); } |
︙ | ︙ | |||
2195 2196 2197 2198 2199 2200 2201 | return 0; } /* * Allocate storage for passing thread id's to caller */ | | | 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 | return 0; } /* * Allocate storage for passing thread id's to caller */ *thrIdArray = (Tcl_ThreadId *)ckalloc(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; |
︙ | ︙ | |||
2317 2318 2319 2320 2321 2322 2323 | if (!haveInterpCancel) { Tcl_MutexUnlock(&threadMutex); Tcl_AppendResult(interp, "not supported with this Tcl version", NULL); return TCL_ERROR; } if (result != NULL) { | | | 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 | if (!haveInterpCancel) { Tcl_MutexUnlock(&threadMutex); Tcl_AppendResult(interp, "not supported with this Tcl version", NULL); return TCL_ERROR; } if (result != NULL) { resultObj = Tcl_NewStringObj(result, TCL_INDEX_NONE); } code = Tcl_CancelEval(tsdPtr->interp, resultObj, NULL, flags); Tcl_MutexUnlock(&threadMutex); return code; } |
︙ | ︙ | |||
2416 2417 2418 2419 2420 2421 2422 | * transfer. This allows this thread then to proceed. */ TransferEvent *evPtr; TransferResult *resultPtr; if (!Tcl_IsChannelRegistered(interp, chan)) { | | | | | 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 | * 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_INDEX_NONE)); } if (Tcl_IsChannelShared(chan)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_INDEX_NONE)); return TCL_ERROR; } /* * Short circuit transfers to ourself. Nothing to do. */ if (thrId == Tcl_GetCurrentThread()) { |
︙ | ︙ | |||
2572 2573 2574 2575 2576 2577 2578 | Tcl_Interp *interp, /* The current interpreter. */ Tcl_Channel chan /* The channel to detach */ ) { TransferEvent *evPtr; TransferResult *resultPtr; if (!Tcl_IsChannelRegistered(interp, chan)) { | | | | | 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 | 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_INDEX_NONE)); } if (Tcl_IsChannelShared(chan)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_INDEX_NONE)); return TCL_ERROR; } /* * Cut the channel out of the interp/thread */ ThreadCutChannel(interp, chan); |
︙ | ︙ | |||
2749 2750 2751 2752 2753 2754 2755 | int inerror = tsdPtr && (tsdPtr->flags & THREAD_FLAGS_INERROR); Tcl_MutexUnlock(&threadMutex); ThreadFreeProc(send); if (clbk) { ThreadFreeProc(clbk); } if (inerror) { | | | 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 | 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_INDEX_NONE)); } else { ErrorNoSuchThread(interp, thrId); } return TCL_ERROR; } /* |
︙ | ︙ | |||
2779 2780 2781 2782 2783 2784 2785 | return code; } /* * Create the event for target thread event queue. */ | | | 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 | return code; } /* * Create the event for target thread event queue. */ eventPtr = (ThreadEvent *)ckalloc(sizeof(ThreadEvent)); eventPtr->sendData = send; eventPtr->clbkData = clbk; /* * Target thread about to service * another event */ |
︙ | ︙ | |||
2804 2805 2806 2807 2808 2809 2810 | if (eventPtr->clbkData) { Tcl_Preserve(eventPtr->clbkData->interp); } if ((flags & THREAD_SEND_WAIT) == 0) { resultPtr = NULL; eventPtr->resultPtr = NULL; } else { | | | 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 | if (eventPtr->clbkData) { Tcl_Preserve(eventPtr->clbkData->interp); } if ((flags & THREAD_SEND_WAIT) == 0) { resultPtr = NULL; eventPtr->resultPtr = NULL; } else { resultPtr = (ThreadEventResult *)ckalloc(sizeof(ThreadEventResult)); resultPtr->done = NULL; resultPtr->result = NULL; resultPtr->errorCode = NULL; resultPtr->errorInfo = NULL; resultPtr->dstThreadId = thrId; resultPtr->srcThreadId = Tcl_GetCurrentThread(); resultPtr->eventPtr = eventPtr; |
︙ | ︙ | |||
3121 3122 3123 3124 3125 3126 3127 | if (dowait) { while (resultPtr->result == NULL) { Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL); } SpliceOut(resultPtr, resultList); Tcl_ConditionFinalize(&resultPtr->done); Tcl_DecrRefCount(resultPtr->result); | | | 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 | if (dowait) { while (resultPtr->result == NULL) { Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL); } SpliceOut(resultPtr, resultList); Tcl_ConditionFinalize(&resultPtr->done); Tcl_DecrRefCount(resultPtr->result); ckfree((char *)resultPtr); } } } Tcl_MutexUnlock(&threadMutex); Tcl_SetIntObj(Tcl_GetObjResult(interp), (users > 0) ? users : 0); |
︙ | ︙ | |||
3593 3594 3595 3596 3597 3598 3599 | * * Called when we are exiting and memory needs to be freed. * * Results: * None. * * Side effects: | | | | | | 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 | * * 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); } ckfree((char *)anyPtr); } } /* *---------------------------------------------------------------------- * * ThreadDeleteEvent -- |
︙ | ︙ | |||
3635 3636 3637 3638 3639 3640 3641 | * It cleans up our events in the event queue for this thread. * *---------------------------------------------------------------------- */ static int ThreadDeleteEvent( Tcl_Event *eventPtr, /* Really ThreadEvent */ | | | 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 | * It cleans up our events in the event queue for this thread. * *---------------------------------------------------------------------- */ static int ThreadDeleteEvent( Tcl_Event *eventPtr, /* Really ThreadEvent */ void *dummy /* dummy */ ) { (void)dummy; if (eventPtr->proc == ThreadEventProc) { /* * Regular script event. Just dispose memory */ |
︙ | ︙ | |||
3706 3707 3708 3709 3710 3711 3712 | * 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( | | | | | 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 | * 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) { ckfree((char *)threadEvalScript); } Tcl_MutexLock(&threadMutex); /* * NaviServer/AOLserver and threadpool threads get started/stopped * out of the control of this interface so this is |
︙ | ︙ | |||
3757 3758 3759 3760 3761 3762 3763 | /* * 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); | | | 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 | /* * 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); ckfree((char *)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. |
︙ | ︙ | |||
3786 3787 3788 3789 3790 3791 3792 | * 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); | | | 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 | * 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); ckfree((char *)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. */ |
︙ | ︙ |
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; |
︙ | ︙ | |||
263 264 265 266 267 268 269 | maxw = minw; } /* * Allocate and initialize thread pool structure */ | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | maxw = minw; } /* * Allocate and initialize thread pool structure */ tpoolPtr = (ThreadPool *)ckalloc(sizeof(ThreadPool)); memset(tpoolPtr, 0, sizeof(ThreadPool)); tpoolPtr->minWorkers = minw; tpoolPtr->maxWorkers = maxw; tpoolPtr->idleTime = idle; tpoolPtr->initScript = cmd; tpoolPtr->exitScript = exs; |
︙ | ︙ | |||
296 297 298 299 300 301 302 | Tcl_MutexUnlock(&listMutex); return TCL_ERROR; } } Tcl_MutexUnlock(&tpoolPtr->mutex); sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr); | | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | Tcl_MutexUnlock(&listMutex); return TCL_ERROR; } } Tcl_MutexUnlock(&tpoolPtr->mutex); sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr); Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE)); return TCL_OK; usage: Tcl_WrongNumArgs(interp, 1, objv, "?-minworkers count? ?-maxworkers count? " "?-initcmd script? ?-exitcmd script? " |
︙ | ︙ | |||
327 328 329 330 331 332 333 | * None. * *---------------------------------------------------------------------- */ static int TpoolPostObjCmd( | | | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | * 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; |
︙ | ︙ | |||
454 455 456 457 458 459 460 | } } /* * Create new job ticket and put it on the list. */ | | | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | } } /* * Create new job ticket and put it on the list. */ rPtr = (TpoolResult *)ckalloc(sizeof(TpoolResult)); memset(rPtr, 0, sizeof(TpoolResult)); if (detached == 0) { jobId = ++tpoolPtr->jobId; rPtr->jobId = jobId; } |
︙ | ︙ | |||
500 501 502 503 504 505 506 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolWaitObjCmd( | | | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | * 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, wObjc; Tcl_WideInt jobId; char *tpoolName; |
︙ | ︙ | |||
616 617 618 619 620 621 622 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolCancelObjCmd( | | | 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | * 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, wObjc; Tcl_WideInt jobId; char *tpoolName; |
︙ | ︙ | |||
675 676 677 678 679 680 681 | if (rPtr->nextPtr != NULL) { rPtr->nextPtr->prevPtr = rPtr->prevPtr; } else { tpoolPtr->workTail = rPtr->prevPtr; } SetResult(NULL, rPtr); /* Just to free the result */ ckfree(rPtr->script); | | | 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | if (rPtr->nextPtr != NULL) { rPtr->nextPtr->prevPtr = rPtr->prevPtr; } else { tpoolPtr->workTail = rPtr->prevPtr; } SetResult(NULL, rPtr); /* Just to free the result */ ckfree(rPtr->script); ckfree((char *)rPtr); Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]); break; } } if (rPtr == NULL && listVar) { Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]); } |
︙ | ︙ | |||
713 714 715 716 717 718 719 | * Side effects: * None. * *---------------------------------------------------------------------- */ static int TpoolGetObjCmd( | | | 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | * 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; |
︙ | ︙ | |||
779 780 781 782 783 784 785 | } Tcl_DeleteHashEntry(hPtr); Tcl_MutexUnlock(&tpoolPtr->mutex); ret = rPtr->retcode; SetResult(interp, rPtr); | | | 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | } Tcl_DeleteHashEntry(hPtr); Tcl_MutexUnlock(&tpoolPtr->mutex); ret = rPtr->retcode; SetResult(interp, rPtr); ckfree((char *)rPtr); if (resVar) { Tcl_ObjSetVar2(interp, resVar, NULL, Tcl_GetObjResult(interp), 0); Tcl_SetObjResult(interp, Tcl_NewIntObj(ret)); ret = TCL_OK; } |
︙ | ︙ | |||
809 810 811 812 813 814 815 | * None. * *---------------------------------------------------------------------- */ static int TpoolReserveObjCmd( | | | 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | * 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; |
︙ | ︙ | |||
865 866 867 868 869 870 871 | * None. * *---------------------------------------------------------------------- */ static int TpoolReleaseObjCmd( | | | 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | * 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; |
︙ | ︙ | |||
921 922 923 924 925 926 927 | * None. * *---------------------------------------------------------------------- */ static int TpoolSuspendObjCmd( | | | 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | * 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; (void)dummy; |
︙ | ︙ | |||
972 973 974 975 976 977 978 | * None. * *---------------------------------------------------------------------- */ static int TpoolResumeObjCmd( | | | 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | * 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; (void)dummy; |
︙ | ︙ | |||
1023 1024 1025 1026 1027 1028 1029 | * None. * *---------------------------------------------------------------------- */ static int TpoolNamesObjCmd( | | | | 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | * 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); (void)dummy; (void)objc; (void)objv; 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_INDEX_NONE)); } Tcl_MutexUnlock(&listMutex); Tcl_SetObjResult(interp, listObj); return TCL_OK; } |
︙ | ︙ | |||
1088 1089 1090 1091 1092 1093 1094 | * 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) { | | | 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | * 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_INDEX_NONE)); Tcl_MutexUnlock(&startMutex); return TCL_ERROR; } while(result.retcode == -1) { Tcl_ConditionWait(&tpoolPtr->cond, &startMutex, NULL); } Tcl_MutexUnlock(&startMutex); |
︙ | ︙ | |||
1129 1130 1131 1132 1133 1134 1135 | * None. * *---------------------------------------------------------------------- */ static Tcl_ThreadCreateType TpoolWorker( | | | | 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | * 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; |
︙ | ︙ | |||
1262 1263 1264 1265 1266 1267 1268 | } /* * Tear down the worker */ if (tpoolPtr->exitScript) { | | | 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | } /* * Tear down the worker */ if (tpoolPtr->exitScript) { TpoolEval(interp, tpoolPtr->exitScript, TCL_INDEX_NONE, NULL); } tpoolPtr->numWorkers--; SignalWaiter(tpoolPtr); Tcl_MutexUnlock(&tpoolPtr->mutex); out: |
︙ | ︙ | |||
1579 1580 1581 1582 1583 1584 1585 | SetResult( Tcl_Interp *interp, TpoolResult *rPtr ) { if (rPtr->retcode == TCL_ERROR) { if (rPtr->errorCode) { if (interp) { | | | | 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 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | SetResult( Tcl_Interp *interp, TpoolResult *rPtr ) { if (rPtr->retcode == TCL_ERROR) { if (rPtr->errorCode) { if (interp) { Tcl_SetObjErrorCode(interp,Tcl_NewStringObj(rPtr->errorCode, TCL_INDEX_NONE)); } ckfree(rPtr->errorCode); rPtr->errorCode = NULL; } if (rPtr->errorInfo) { if (interp) { Tcl_AddErrorInfo(interp, rPtr->errorInfo); } ckfree(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_INDEX_NONE)); } ckfree(rPtr->result); rPtr->result = NULL; } } } |
︙ | ︙ | |||
1713 1714 1715 1716 1717 1718 1719 | if (rPtr->errorInfo) { ckfree(rPtr->errorInfo); } if (rPtr->errorCode) { ckfree(rPtr->errorCode); } } | | | | | 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 | if (rPtr->errorInfo) { ckfree(rPtr->errorInfo); } if (rPtr->errorCode) { ckfree(rPtr->errorCode); } } ckfree((char *)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) { ckfree(rPtr->script); ckfree((char *)rPtr); } Tcl_MutexFinalize(&tpoolPtr->mutex); Tcl_ConditionFinalize(&tpoolPtr->cond); ckfree((char *)tpoolPtr); return 0; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1813 1814 1815 1816 1817 1818 1819 | Tcl_Event *evPtr; waitPtr = PopWaiter(tpoolPtr); if (waitPtr == NULL) { return; } | | | 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 | Tcl_Event *evPtr; waitPtr = PopWaiter(tpoolPtr); if (waitPtr == NULL) { return; } evPtr = (Tcl_Event *)ckalloc(sizeof(Tcl_Event)); evPtr->proc = RunStopEvent; Tcl_ThreadQueueEvent(waitPtr->threadId,(Tcl_Event*)evPtr,TCL_QUEUE_TAIL); Tcl_ThreadAlert(waitPtr->threadId); } /* |
︙ | ︙ | |||
1841 1842 1843 1844 1845 1846 1847 | */ static void InitWaiter () { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); if (tsdPtr->waitPtr == NULL) { | | | 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 | */ static void InitWaiter () { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); if (tsdPtr->waitPtr == NULL) { tsdPtr->waitPtr = (TpoolWaiter *)ckalloc(sizeof(TpoolWaiter)); tsdPtr->waitPtr->prevPtr = NULL; tsdPtr->waitPtr->nextPtr = NULL; tsdPtr->waitPtr->threadId = Tcl_GetCurrentThread(); Tcl_CreateThreadExitHandler(ThrExitHandler, tsdPtr); } } |
︙ | ︙ | |||
1866 1867 1868 1869 1870 1871 1872 | * Side effects: * None. * *---------------------------------------------------------------------- */ static void ThrExitHandler( | | | | | 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 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 | * Side effects: * None. * *---------------------------------------------------------------------- */ static void ThrExitHandler( void *clientData ) { ThreadSpecificData *tsdPtr = (ThreadSpecificData *)clientData; ckfree((char *)tsdPtr->waitPtr); } /* *---------------------------------------------------------------------- * * AppExitHandler * * Deletes all threadpools on application exit. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */ static void AppExitHandler( void *dummy ) { ThreadPool *tpoolPtr; (void)dummy; Tcl_MutexLock(&listMutex); /* * Restart with head of list each time until empty. [Bug 1427570] |
︙ | ︙ | |||
1942 1943 1944 1945 1946 1947 1948 | 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) { | | | 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 | 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 | * 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; |
︙ | ︙ | |||
350 351 352 353 354 355 356 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadRWMutexObjCmd( | | | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | * 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; |
︙ | ︙ | |||
399 400 401 402 403 404 405 | if (opt == (int)w_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } | | | 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | if (opt == (int)w_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } mutexPtr = (SpMutex *)ckalloc(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); |
︙ | ︙ | |||
515 516 517 518 519 520 521 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadCondObjCmd( | | | 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | * 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; |
︙ | ︙ | |||
562 563 564 565 566 567 568 | if (opt == (int)c_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } | | | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | if (opt == (int)c_CREATE) { Tcl_Obj *nameObj; if (objc > 2) { Tcl_WrongNumArgs(interp, 1, objv, "create"); return TCL_ERROR; } condvPtr = (SpCondv *)ckalloc(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); |
︙ | ︙ | |||
684 685 686 687 688 689 690 | * See the user documentation. * *---------------------------------------------------------------------- */ static int ThreadEvalObjCmd( | | | 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | * 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; |
︙ | ︙ | |||
1016 1017 1018 1019 1020 1021 1022 | } if (!SpMutexFinalize(mutexPtr)) { PutMutex(mutexPtr); return 0; } PutMutex(mutexPtr); RemoveAnyItem(SP_MUTEX, name, len); | | | 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | } if (!SpMutexFinalize(mutexPtr)) { PutMutex(mutexPtr); return 0; } PutMutex(mutexPtr); RemoveAnyItem(SP_MUTEX, name, len); ckfree((char *)mutexPtr); return 1; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1052 1053 1054 1055 1056 1057 1058 | } if (!SpCondvFinalize(condvPtr)) { PutCondv(condvPtr); return 0; } PutCondv(condvPtr); RemoveAnyItem(SP_CONDV, name, len); | | | 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | } if (!SpCondvFinalize(condvPtr)) { PutCondv(condvPtr); return 0; } PutCondv(condvPtr); RemoveAnyItem(SP_CONDV, name, len); ckfree((char *)condvPtr); return 1; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1361 1362 1363 1364 1365 1366 1367 | Sp_ExclusiveMutex_ *emPtr; Tcl_ThreadId thisThread = Tcl_GetCurrentThread(); /* * Allocate the mutex structure on first access */ | | | | | 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 | 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_ *) ckalloc(sizeof(Sp_ExclusiveMutex_)); memset(*muxPtr, 0, sizeof(Sp_ExclusiveMutex_)); } Tcl_MutexUnlock(&initMutex); } /* |
︙ | ︙ | |||
1497 1498 1499 1500 1501 1502 1503 | Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)muxPtr; if (emPtr->lock) { Tcl_MutexFinalize(&emPtr->lock); } if (emPtr->mutex) { Tcl_MutexFinalize(&emPtr->mutex); } | | | 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 | Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)muxPtr; if (emPtr->lock) { Tcl_MutexFinalize(&emPtr->lock); } if (emPtr->mutex) { Tcl_MutexFinalize(&emPtr->mutex); } ckfree((char *)*muxPtr); } } /* *---------------------------------------------------------------------- * * Sp_RecursiveMutexLock -- |
︙ | ︙ | |||
1530 1531 1532 1533 1534 1535 1536 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_RecursiveMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_RecursiveMutex_*)0) { | | | 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_RecursiveMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_RecursiveMutex_*)0) { *muxPtr = (Sp_RecursiveMutex_ *) ckalloc(sizeof(Sp_RecursiveMutex_)); memset(*muxPtr, 0, sizeof(Sp_RecursiveMutex_)); } Tcl_MutexUnlock(&initMutex); } rmPtr = *(Sp_RecursiveMutex_**)muxPtr; |
︙ | ︙ | |||
1660 1661 1662 1663 1664 1665 1666 | * *---------------------------------------------------------------------- */ void Sp_RecursiveMutexFinalize(Sp_RecursiveMutex *muxPtr) { | | | | 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 | * *---------------------------------------------------------------------- */ void Sp_RecursiveMutexFinalize(Sp_RecursiveMutex *muxPtr) { if (*muxPtr != NULL) { Sp_RecursiveMutex_ *rmPtr = *(Sp_RecursiveMutex_**)muxPtr; if (rmPtr->lock) { Tcl_MutexFinalize(&rmPtr->lock); } if (rmPtr->cond) { Tcl_ConditionFinalize(&rmPtr->cond); } ckfree((char *)*muxPtr); } } /* *---------------------------------------------------------------------- * * Sp_ReadWriteMutexRLock -- |
︙ | ︙ | |||
1702 1703 1704 1705 1706 1707 1708 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { | | | 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { *muxPtr = (Sp_ReadWriteMutex_ *) ckalloc(sizeof(Sp_ReadWriteMutex_)); memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_)); } Tcl_MutexUnlock(&initMutex); } rwPtr = *(Sp_ReadWriteMutex_**)muxPtr; |
︙ | ︙ | |||
1757 1758 1759 1760 1761 1762 1763 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { | | | 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 | /* * Allocate the mutex structure on first access */ if (*muxPtr == (Sp_ReadWriteMutex_*)0) { Tcl_MutexLock(&initMutex); if (*muxPtr == (Sp_ReadWriteMutex_*)0) { *muxPtr = (Sp_ReadWriteMutex_ *) ckalloc(sizeof(Sp_ReadWriteMutex_)); memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_)); } Tcl_MutexUnlock(&initMutex); } rwPtr = *(Sp_ReadWriteMutex_**)muxPtr; |
︙ | ︙ | |||
1881 1882 1883 1884 1885 1886 1887 | } if (rwPtr->rcond) { Tcl_ConditionFinalize(&rwPtr->rcond); } if (rwPtr->wcond) { Tcl_ConditionFinalize(&rwPtr->wcond); } | | | 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 | } if (rwPtr->rcond) { Tcl_ConditionFinalize(&rwPtr->rcond); } if (rwPtr->wcond) { Tcl_ConditionFinalize(&rwPtr->wcond); } ckfree((char *)*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 *)ckalloc(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 *)ckalloc(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 *)ckalloc(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_INDEX_NONE)); return TCL_BREAK; } *offset = 2; /* Consumed two arguments: object, cmd */ } return TCL_OK; } |
︙ | ︙ | |||
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_INDEX_NONE)); 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 *)ckalloc(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); |
︙ | ︙ | |||
848 849 850 851 852 853 854 | 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; } | | | 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 | 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; } ckfree((char *)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); ckfree((char *)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 *)ckalloc(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; ckfree((char *)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 *)ckalloc((unsigned)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 | * 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; |
︙ | ︙ | |||
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_INDEX_NONE)); 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 | * 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, lobjc = 0, index, ret = TCL_OK; const char *arrayName = NULL; Array *arrayPtr = NULL; |
︙ | ︙ | |||
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); | | | 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 | } 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_INDEX_NONE)); } 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, | | | 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 | 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_INDEX_NONE)); if (index == AGET) { elObj = (Container*)Tcl_GetHashValue(hPtr); Tcl_ListObjAppendElement(interp, resObj, Sv_DuplicateObj(elObj->tclObj)); } } hPtr = Tcl_NextHashEntry(&search); |
︙ | ︙ | |||
1434 1435 1436 1437 1438 1439 1440 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvUnsetObjCmd( | | | 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 | * 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; |
︙ | ︙ | |||
1501 1502 1503 1504 1505 1506 1507 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvNamesObjCmd( | | | 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 | * 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; |
︙ | ︙ | |||
1562 1563 1564 1565 1566 1567 1568 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvGetObjCmd( | | | 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 | * 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; |
︙ | ︙ | |||
1627 1628 1629 1630 1631 1632 1633 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvExistsObjCmd( | | | 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 | * 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; |
︙ | ︙ | |||
1674 1675 1676 1677 1678 1679 1680 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvSetObjCmd( | | | 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 | * 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; |
︙ | ︙ | |||
1741 1742 1743 1744 1745 1746 1747 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvIncrObjCmd( | | | 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 | * 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; |
︙ | ︙ | |||
1814 1815 1816 1817 1818 1819 1820 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvAppendObjCmd( | | | 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 | * 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; |
︙ | ︙ | |||
1868 1869 1870 1871 1872 1873 1874 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvPopObjCmd( | | | 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 | * 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; |
︙ | ︙ | |||
1908 1909 1910 1911 1912 1913 1914 | 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_INDEX_NONE)); } ret = TCL_ERROR; goto cmd_exit; } if ((objc - off) == 0) { Tcl_SetObjResult(interp, retObj); |
︙ | ︙ | |||
1951 1952 1953 1954 1955 1956 1957 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvMoveObjCmd( | | | 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 | * 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; |
︙ | ︙ | |||
1985 1986 1987 1988 1989 1990 1991 | } 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_INDEX_NONE)); return TCL_ERROR; } } Tcl_DeleteHashEntry(svObj->entryPtr); } svObj->entryPtr = hPtr; |
︙ | ︙ | |||
2021 2022 2023 2024 2025 2026 2027 | * See the user documentation. * *---------------------------------------------------------------------- */ static int SvLockObjCmd( | | | 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 | * 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; |
︙ | ︙ | |||
2098 2099 2100 2101 2102 2103 2104 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int SvHandlersObjCmd( | | | 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 | * Side effects: * None. * *----------------------------------------------------------------------------- */ static int SvHandlersObjCmd( void *dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { PsStore *tmpPtr = NULL; (void)dummy; |
︙ | ︙ | |||
2264 2265 2266 2267 2268 2269 2270 | /* * Plug-in registered commands in current interpreter */ for (cmdPtr = svCmdInfo; cmdPtr; cmdPtr = cmdPtr->nextPtr) { Tcl_CreateObjCommand(interp, cmdPtr->cmdName, cmdPtr->objProcPtr, | | | | 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 | /* * 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 */ |
︙ | ︙ | |||
2339 2340 2341 2342 2343 2344 2345 | * Side effects * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void | | | 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 | * Side effects * Memory gets reclaimed. * *----------------------------------------------------------------------------- */ static void SvFinalize (void *dummy) { int i; SvCmdInfo *cmdPtr; RegType *regPtr; Tcl_HashEntry *hashPtr; Tcl_HashSearch search; |
︙ | ︙ | |||
2403 2404 2405 2406 2407 2408 2409 | * Reclaim memory for registered commands */ if (svCmdInfo != NULL) { cmdPtr = svCmdInfo; while (cmdPtr) { SvCmdInfo *tmpPtr = cmdPtr->nextPtr; | | | | 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 2429 2430 2431 | * Reclaim memory for registered commands */ if (svCmdInfo != NULL) { cmdPtr = svCmdInfo; while (cmdPtr) { SvCmdInfo *tmpPtr = cmdPtr->nextPtr; ckfree((char *)cmdPtr); cmdPtr = tmpPtr; } svCmdInfo = NULL; } /* * Reclaim memory for registered object types */ if (regType != NULL) { regPtr = regType; while (regPtr) { RegType *tmpPtr = regPtr->nextPtr; ckfree((char *)regPtr); regPtr = tmpPtr; } regType = NULL; } Tcl_MutexUnlock(&svMutex); |
︙ | ︙ |
Changes to generic/threadSvCmd.h.
︙ | ︙ | |||
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. */ | | | | | | | | | | | | 77 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 | #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.
︙ | ︙ | |||
146 147 148 149 150 151 152 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpopObjCmd ( | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpopObjCmd ( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int ret, off, llen, iarg = 0; tclSizeT index = 0; Tcl_Obj *elPtr = NULL; |
︙ | ︙ | |||
226 227 228 229 230 231 232 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpushObjCmd ( | | | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLpushObjCmd ( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int off, ret, flg, llen; tclSizeT index = 0; Tcl_Obj *args[1]; |
︙ | ︙ | |||
299 300 301 302 303 304 305 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLappendObjCmd( | | | 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | * 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( | | | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | * 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; |
︙ | ︙ | |||
459 460 461 462 463 464 465 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLrangeObjCmd( | | | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLrangeObjCmd( void *arg, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] ) { int ret, off, llen, nargs, j; tclSizeT first, last, i; Tcl_Obj **elPtrs, **args; |
︙ | ︙ | |||
541 542 543 544 545 546 547 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLinsertObjCmd( | | | 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | * 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; tclSizeT index = 0; Tcl_Obj **args; |
︙ | ︙ | |||
621 622 623 624 625 626 627 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLlengthObjCmd( | | | 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | * 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( | | | 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | * 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; |
︙ | ︙ | |||
776 777 778 779 780 781 782 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLindexObjCmd( | | | 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | * 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; tclSizeT index; |
︙ | ︙ | |||
837 838 839 840 841 842 843 | * See the user documentation. * *----------------------------------------------------------------------------- */ static int SvLsetObjCmd( | | | 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 | * 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; |
︙ | ︙ |
Changes to win/rules.vc.
︙ | ︙ | |||
20 21 22 23 24 25 26 | !ifndef _RULES_VC _RULES_VC = 1 # The following macros define the version of the rules.vc nmake build system # For modifications that are not backward-compatible, you *must* change # the major version. RULES_VERSION_MAJOR = 1 | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | !ifndef _RULES_VC _RULES_VC = 1 # The following macros define the version of the rules.vc nmake build system # For modifications that are not backward-compatible, you *must* change # the major version. RULES_VERSION_MAJOR = 1 RULES_VERSION_MINOR = 6 # The PROJECT macro must be defined by parent makefile. !if "$(PROJECT)" == "" !error *** Error: Macro PROJECT not defined! Please define it before including rules.vc !endif !if "$(PRJ_PACKAGE_TCLNAME)" == "" |
︙ | ︙ | |||
298 299 300 301 302 303 304 | TCLINSTALL = 1 TCLDIR = $(_INSTALLDIR)\.. # NOTE: we will be resetting _INSTALLDIR to _INSTALLDIR/lib for extensions # later so the \.. accounts for the /lib _TCLDIR = $(_INSTALLDIR)\.. _TCL_H = $(_TCLDIR)\include\tcl.h | | | | 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | TCLINSTALL = 1 TCLDIR = $(_INSTALLDIR)\.. # NOTE: we will be resetting _INSTALLDIR to _INSTALLDIR/lib for extensions # later so the \.. accounts for the /lib _TCLDIR = $(_INSTALLDIR)\.. _TCL_H = $(_TCLDIR)\include\tcl.h !else # exist(...) && !$(NEED_TCL_SOURCE) !if [echo _TCLDIR = \> nmakehlp.out] \ || [nmakehlp -L generic\tcl.h >> nmakehlp.out] !error *** Could not locate Tcl source directory. !endif !include nmakehlp.out TCLINSTALL = 0 TCLDIR = $(_TCLDIR) _TCL_H = $(_TCLDIR)\generic\tcl.h !endif # exist(...) && !$(NEED_TCL_SOURCE) !endif # TCLDIR !ifndef _TCL_H MSG =^ Failed to find tcl.h. The TCLDIR macro is set incorrectly or is not set and default path does not contain tcl.h. !error $(MSG) |
︙ | ︙ | |||
533 534 535 536 537 538 539 | NMAKEHLPC = nmakehlp.c !if !$(DOING_TCL) !if $(TCLINSTALL) !if exist("$(_TCLDIR)\lib\nmake\nmakehlp.c") NMAKEHLPC = $(_TCLDIR)\lib\nmake\nmakehlp.c !endif | | | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | NMAKEHLPC = nmakehlp.c !if !$(DOING_TCL) !if $(TCLINSTALL) !if exist("$(_TCLDIR)\lib\nmake\nmakehlp.c") NMAKEHLPC = $(_TCLDIR)\lib\nmake\nmakehlp.c !endif !else # !$(TCLINSTALL) !if exist("$(_TCLDIR)\win\nmakehlp.c") NMAKEHLPC = $(_TCLDIR)\win\nmakehlp.c !endif !endif # $(TCLINSTALL) !endif # !$(DOING_TCL) !endif # NMAKEHLPC |
︙ | ︙ | |||
681 682 683 684 685 686 687 | # 0 -> Use the non-thread allocator. # UNCHECKED - 1 -> when doing a debug build with symbols, use the release # C runtime, 0 -> use the debug C runtime. # USE_STUBS - 1 -> compile to use stubs interfaces, 0 -> direct linking # CONFIG_CHECK - 1 -> check current build configuration against Tcl # configuration (ignored for Tcl itself) # _USE_64BIT_TIME_T - forces a build using 64-bit time_t for 32-bit build | | | > | 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | # 0 -> Use the non-thread allocator. # UNCHECKED - 1 -> when doing a debug build with symbols, use the release # C runtime, 0 -> use the debug C runtime. # USE_STUBS - 1 -> compile to use stubs interfaces, 0 -> direct linking # CONFIG_CHECK - 1 -> check current build configuration against Tcl # configuration (ignored for Tcl itself) # _USE_64BIT_TIME_T - forces a build using 64-bit time_t for 32-bit build # (CRT library should support this, not needed for Tcl 9.x) # TCL_UTF_MAX=4 - forces a build allowing 4-byte UTF-8 sequences internally. # (Not needed for Tcl 9.x) # Further, LINKERFLAGS are modified based on above. # Default values for all the above STATIC_BUILD = 0 TCL_THREADS = 1 DEBUG = 0 SYMBOLS = 0 |
︙ | ︙ | |||
742 743 744 745 746 747 748 749 750 751 752 753 754 | !if [nmakehlp -f $(OPTS) "staticpkg"] && $(STATIC_BUILD) !message *** Doing staticpkg TCL_USE_STATIC_PACKAGES = 1 !else TCL_USE_STATIC_PACKAGES = 0 !endif !if [nmakehlp -f $(OPTS) "time64bit"] !message *** Force 64-bit time_t _USE_64BIT_TIME_T = 1 !endif !if [nmakehlp -f $(OPTS) "utfmax"] | > > > > > > > > > > | | > | 743 744 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 775 | !if [nmakehlp -f $(OPTS) "staticpkg"] && $(STATIC_BUILD) !message *** Doing staticpkg TCL_USE_STATIC_PACKAGES = 1 !else TCL_USE_STATIC_PACKAGES = 0 !endif !if [nmakehlp -f $(OPTS) "nothreads"] !message *** Compile explicitly for non-threaded tcl TCL_THREADS = 0 USE_THREAD_ALLOC= 0 !else TCL_THREADS = 1 USE_THREAD_ALLOC= 1 !endif !if "$(TCL_MAJOR_VERSION)" == "8" !if [nmakehlp -f $(OPTS) "time64bit"] !message *** Force 64-bit time_t _USE_64BIT_TIME_T = 1 !endif !if [nmakehlp -f $(OPTS) "utfmax"] !message *** Force allowing 4-byte UTF-8 sequences internally TCL_UTF_MAX = 4 !endif !endif # Yes, it's weird that the "symbols" option controls DEBUG and # the "pdbs" option controls SYMBOLS. That's historical. !if [nmakehlp -f $(OPTS) "symbols"] !message *** Doing symbols DEBUG = 1 |
︙ | ︙ | |||
788 789 790 791 792 793 794 795 796 797 798 799 800 801 | !else PGO = 0 !endif !if [nmakehlp -f $(OPTS) "loimpact"] !message *** Warning: ignoring option "loimpact" - deprecated on modern Windows. !endif !if [nmakehlp -f $(OPTS) "tclalloc"] USE_THREAD_ALLOC = 0 !endif !if [nmakehlp -f $(OPTS) "unchecked"] !message *** Doing unchecked | > > > > > > | 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | !else PGO = 0 !endif !if [nmakehlp -f $(OPTS) "loimpact"] !message *** Warning: ignoring option "loimpact" - deprecated on modern Windows. !endif # TBD - should get rid of this option !if [nmakehlp -f $(OPTS) "thrdalloc"] !message *** Doing thrdalloc USE_THREAD_ALLOC = 1 !endif !if [nmakehlp -f $(OPTS) "tclalloc"] USE_THREAD_ALLOC = 0 !endif !if [nmakehlp -f $(OPTS) "unchecked"] !message *** Doing unchecked |
︙ | ︙ | |||
1093 1094 1095 1096 1097 1098 1099 | TCLLIBNAME = $(PROJECT)$(VERSION)$(SUFX).$(EXT) TCLLIB = $(OUT_DIR)\$(TCLLIBNAME) TCLSTUBLIBNAME = $(STUBPREFIX)$(VERSION).lib TCLSTUBLIB = $(OUT_DIR)\$(TCLSTUBLIBNAME) TCL_INCLUDES = -I"$(WIN_DIR)" -I"$(GENERICDIR)" | | | 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | TCLLIBNAME = $(PROJECT)$(VERSION)$(SUFX).$(EXT) TCLLIB = $(OUT_DIR)\$(TCLLIBNAME) TCLSTUBLIBNAME = $(STUBPREFIX)$(VERSION).lib TCLSTUBLIB = $(OUT_DIR)\$(TCLSTUBLIBNAME) TCL_INCLUDES = -I"$(WIN_DIR)" -I"$(GENERICDIR)" !else # !$(DOING_TCL) !if $(TCLINSTALL) # Building against an installed Tcl # When building extensions, we need to locate tclsh. Depending on version # of Tcl we are building against, this may or may not have a "t" suffix. # Try various possibilities in turn. TCLSH = $(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX:t=).exe |
︙ | ︙ | |||
1199 1200 1201 1202 1203 1204 1205 | !endif # TKINSTALL tklibs = "$(TKSTUBLIB)" "$(TKIMPLIB)" !endif # $(DOING_TK) !endif # $(DOING_TK) || $(NEED_TK) # Various output paths | | | | 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 | !endif # TKINSTALL tklibs = "$(TKSTUBLIB)" "$(TKIMPLIB)" !endif # $(DOING_TK) !endif # $(DOING_TK) || $(NEED_TK) # Various output paths PRJIMPLIB = $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib PRJLIBNAME = $(PROJECT)$(VERSION)$(SUFX).$(EXT) PRJLIB = $(OUT_DIR)\$(PRJLIBNAME) PRJSTUBLIBNAME = $(STUBPREFIX)$(VERSION).lib PRJSTUBLIB = $(OUT_DIR)\$(PRJSTUBLIBNAME) # If extension parent makefile has not defined a resource definition file, # we will generate one from standard template. |
︙ | ︙ | |||
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 | !if $(DOING_TCL) || $(DOING_TK) LIB_INSTALL_DIR = $(_INSTALLDIR)\lib BIN_INSTALL_DIR = $(_INSTALLDIR)\bin DOC_INSTALL_DIR = $(_INSTALLDIR)\doc !if $(DOING_TCL) SCRIPT_INSTALL_DIR = $(_INSTALLDIR)\lib\$(PROJECT)$(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION) !else # DOING_TK SCRIPT_INSTALL_DIR = $(_INSTALLDIR)\lib\$(PROJECT)$(TK_MAJOR_VERSION).$(TK_MINOR_VERSION) !endif DEMO_INSTALL_DIR = $(SCRIPT_INSTALL_DIR)\demos INCLUDE_INSTALL_DIR = $(_INSTALLDIR)\include !else # extension other than Tk | > | 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | !if $(DOING_TCL) || $(DOING_TK) LIB_INSTALL_DIR = $(_INSTALLDIR)\lib BIN_INSTALL_DIR = $(_INSTALLDIR)\bin DOC_INSTALL_DIR = $(_INSTALLDIR)\doc !if $(DOING_TCL) SCRIPT_INSTALL_DIR = $(_INSTALLDIR)\lib\$(PROJECT)$(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION) MODULE_INSTALL_DIR = $(_INSTALLDIR)\lib\tcl$(TCL_MAJOR_VERSION) !else # DOING_TK SCRIPT_INSTALL_DIR = $(_INSTALLDIR)\lib\$(PROJECT)$(TK_MAJOR_VERSION).$(TK_MINOR_VERSION) !endif DEMO_INSTALL_DIR = $(SCRIPT_INSTALL_DIR)\demos INCLUDE_INSTALL_DIR = $(_INSTALLDIR)\include !else # extension other than Tk |
︙ | ︙ | |||
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | # dlllflags - complete linker switches to build DLLs (subsumes lflags) # conlflags - complete linker switches for console program (subsumes lflags) # guilflags - complete linker switches for GUI program (subsumes lflags) # baselibs - minimum Windows libraries required. Parent makefile can # define PRJ_LIBS before including rules.rc if additional libs are needed OPTDEFINES = /DTCL_CFGVAL_ENCODING=$(CFG_ENCODING) /DSTDC_HEADERS !if $(TCL_MEM_DEBUG) OPTDEFINES = $(OPTDEFINES) /DTCL_MEM_DEBUG !endif !if $(TCL_COMPILE_DEBUG) OPTDEFINES = $(OPTDEFINES) /DTCL_COMPILE_DEBUG /DTCL_COMPILE_STATS !endif !if $(TCL_THREADS) && $(TCL_VERSION) < 87 OPTDEFINES = $(OPTDEFINES) /DTCL_THREADS=1 !if $(USE_THREAD_ALLOC) && $(TCL_VERSION) < 87 OPTDEFINES = $(OPTDEFINES) /DUSE_THREAD_ALLOC=1 !endif !endif !if $(STATIC_BUILD) OPTDEFINES = $(OPTDEFINES) /DSTATIC_BUILD !endif !if $(TCL_NO_DEPRECATED) OPTDEFINES = $(OPTDEFINES) /DTCL_NO_DEPRECATED !endif !if $(USE_STUBS) # Note we do not define USE_TCL_STUBS even when building tk since some # test targets in tk do not use stubs | > > > > > > > > > > > > > | | > | | | > | 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 | # dlllflags - complete linker switches to build DLLs (subsumes lflags) # conlflags - complete linker switches for console program (subsumes lflags) # guilflags - complete linker switches for GUI program (subsumes lflags) # baselibs - minimum Windows libraries required. Parent makefile can # define PRJ_LIBS before including rules.rc if additional libs are needed OPTDEFINES = /DTCL_CFGVAL_ENCODING=$(CFG_ENCODING) /DSTDC_HEADERS !if $(VCVERSION) >= 1600 OPTDEFINES = $(OPTDEFINES) /DHAVE_STDINT_H=1 !else OPTDEFINES = $(OPTDEFINES) /DMP_NO_STDINT=1 !endif !if $(VCVERSION) >= 1800 OPTDEFINES = $(OPTDEFINES) /DHAVE_INTTYPES_H=1 /DHAVE_STDBOOL_H=1 !endif !if $(TCL_MEM_DEBUG) OPTDEFINES = $(OPTDEFINES) /DTCL_MEM_DEBUG !endif !if $(TCL_COMPILE_DEBUG) OPTDEFINES = $(OPTDEFINES) /DTCL_COMPILE_DEBUG /DTCL_COMPILE_STATS !endif !if $(TCL_THREADS) && $(TCL_VERSION) < 87 OPTDEFINES = $(OPTDEFINES) /DTCL_THREADS=1 !if $(USE_THREAD_ALLOC) && $(TCL_VERSION) < 87 OPTDEFINES = $(OPTDEFINES) /DUSE_THREAD_ALLOC=1 !endif !endif !if $(STATIC_BUILD) OPTDEFINES = $(OPTDEFINES) /DSTATIC_BUILD !elseif $(TCL_VERSION) > 86 OPTDEFINES = $(OPTDEFINES) /DTCL_WITH_EXTERNAL_TOMMATH !if "$(MACHINE)" == "AMD64" OPTDEFINES = $(OPTDEFINES) /DMP_64BIT !endif !endif !if $(TCL_NO_DEPRECATED) OPTDEFINES = $(OPTDEFINES) /DTCL_NO_DEPRECATED !endif !if $(USE_STUBS) # Note we do not define USE_TCL_STUBS even when building tk since some # test targets in tk do not use stubs !if !$(DOING_TCL) USE_STUBS_DEFS = /DUSE_TCL_STUBS /DUSE_TCLOO_STUBS !if $(NEED_TK) USE_STUBS_DEFS = $(USE_STUBS_DEFS) /DUSE_TK_STUBS !endif !endif !endif # USE_STUBS !if !$(DEBUG) OPTDEFINES = $(OPTDEFINES) /DNDEBUG !if $(OPTIMIZING) OPTDEFINES = $(OPTDEFINES) /DTCL_CFG_OPTIMIZED !endif !endif !if $(PROFILE) OPTDEFINES = $(OPTDEFINES) /DTCL_CFG_PROFILED !endif !if "$(MACHINE)" == "AMD64" OPTDEFINES = $(OPTDEFINES) /DTCL_CFG_DO64BIT !endif !if $(VCVERSION) < 1300 OPTDEFINES = $(OPTDEFINES) /DNO_STRTOI64=1 !endif !if "$(TCL_MAJOR_VERSION)" == "8" !if "$(_USE_64BIT_TIME_T)" == "1" OPTDEFINES = $(OPTDEFINES) /D_USE_64BIT_TIME_T=1 !endif !if "$(TCL_UTF_MAX)" == "4" OPTDEFINES = $(OPTDEFINES) /DTCL_UTF_MAX=4 !endif # _ATL_XP_TARGETING - Newer SDK's need this to build for XP COMPILERFLAGS = /D_ATL_XP_TARGETING !endif # Like the TEA system only set this non empty for non-Tk extensions # Note: some extensions use PACKAGE_NAME and others use PACKAGE_TCLNAME # so we pass both !if !$(DOING_TCL) && !$(DOING_TK) PKGNAMEFLAGS = /DPACKAGE_NAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \ /DPACKAGE_TCLNAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \ |
︙ | ︙ | |||
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 | ### Declarations common to all linker versions lflags = -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug) !if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900 lflags = $(lflags) -nodefaultlib:libucrt.lib !endif dlllflags = $(lflags) -dll conlflags = $(lflags) -subsystem:console guilflags = $(lflags) -subsystem:windows # Libraries that are required for every image. # Extensions should define any additional libraries with $(PRJ_LIBS) | > > > > > > > > > > > > | 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 | ### Declarations common to all linker versions lflags = -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug) !if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900 lflags = $(lflags) -nodefaultlib:libucrt.lib !endif # Old linkers (Visual C++ 6 in particular) will link for fast loading # on Win98. Since we do not support Win98 any more, we specify nowin98 # as recommended for NT and later. However, this is only required by # IX86 on older compilers and only needed if we are not doing a static build. !if "$(MACHINE)" == "IX86" && !$(STATIC_BUILD) !if [nmakehlp -l -opt:nowin98 $(LINKER_TESTFLAGS)] # Align sections for PE size savings. lflags = $(lflags) -opt:nowin98 !endif !endif dlllflags = $(lflags) -dll conlflags = $(lflags) -subsystem:console guilflags = $(lflags) -subsystem:windows # Libraries that are required for every image. # Extensions should define any additional libraries with $(PRJ_LIBS) |
︙ | ︙ | |||
1502 1503 1504 1505 1506 1507 1508 | GUIEXECMD = $(link32) $(guilflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs) RESCMD = $(rc32) -fo $@ -r -i "$(GENERICDIR)" -i "$(TMP_DIR)" \ $(TCL_INCLUDES) \ /DDEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \ /DCOMMAVERSION=$(RCCOMMAVERSION) \ /DDOTVERSION=\"$(DOTVERSION)\" \ /DVERSION=\"$(VERSION)\" \ | | | 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | GUIEXECMD = $(link32) $(guilflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs) RESCMD = $(rc32) -fo $@ -r -i "$(GENERICDIR)" -i "$(TMP_DIR)" \ $(TCL_INCLUDES) \ /DDEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \ /DCOMMAVERSION=$(RCCOMMAVERSION) \ /DDOTVERSION=\"$(DOTVERSION)\" \ /DVERSION=\"$(VERSION)\" \ /DSUFX=\"$(SUFX)\" \ /DPROJECT=\"$(PROJECT)\" \ /DPRJLIBNAME=\"$(PRJLIBNAME)\" !ifndef DEFAULT_BUILD_TARGET DEFAULT_BUILD_TARGET = $(PROJECT) !endif |
︙ | ︙ | |||
1722 1723 1724 1725 1726 1727 1728 | !endif ################################################################ # 14. Sanity check selected options against Tcl build options # When building an extension, certain configuration options should # match the ones used when Tcl was built. Here we check and # warn on a mismatch. | | | | 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 | !endif ################################################################ # 14. Sanity check selected options against Tcl build options # When building an extension, certain configuration options should # match the ones used when Tcl was built. Here we check and # warn on a mismatch. !if !$(DOING_TCL) !if $(TCLINSTALL) # Building against an installed Tcl !if exist("$(_TCLDIR)\lib\nmake\tcl.nmake") TCLNMAKECONFIG = "$(_TCLDIR)\lib\nmake\tcl.nmake" !endif !else # !$(TCLINSTALL) - building against Tcl source !if exist("$(OUT_DIR)\tcl.nmake") TCLNMAKECONFIG = "$(OUT_DIR)\tcl.nmake" !endif !endif # TCLINSTALL !if $(CONFIG_CHECK) !ifdef TCLNMAKECONFIG |
︙ | ︙ | |||
1751 1752 1753 1754 1755 1756 1757 | !if defined(CORE_DEBUG) && $(CORE_DEBUG) != $(DEBUG) !message WARNING: Value of DEBUG ($(DEBUG)) does not match its Tcl library configuration ($(DEBUG)). !endif !endif !endif # TCLNMAKECONFIG | | | 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 | !if defined(CORE_DEBUG) && $(CORE_DEBUG) != $(DEBUG) !message WARNING: Value of DEBUG ($(DEBUG)) does not match its Tcl library configuration ($(DEBUG)). !endif !endif !endif # TCLNMAKECONFIG !endif # !$(DOING_TCL) #---------------------------------------------------------- # Display stats being used. #---------------------------------------------------------- !if !$(DOING_TCL) |
︙ | ︙ |