Overview
| Artifact ID: | 3ef661d051a7d221129d996747c7df46a0836f24 |
|---|---|
| Ticket: | 652530ffffffffffffffffffffffffffffffffff
Invalidated Tk_Uids |
| User & Date: | nobody on 2002-12-12 14:58:54 |
Changes
- icomment:
Logged In: NO --- generic/tkOldConfig.c.ORIG Wed Aug 7 19:45:38 2002 +++ generic/tkOldConfig.c Thu Dec 12 00:21:46 2002 @@ -18,17 +18,6 @@ #include "tk.h" /* - * Values for "flags" field of Tk_ConfigSpec structures. Be sure - * to coordinate these values with those defined in tk.h - * (TK_CONFIG_COLOR_ONLY, etc.). There must not be overlap! - * - * INIT - Non-zero means (char *) things have been - * converted to Tk_Uid's. - */ - -#define INIT 0x20 - -/* * Forward declarations for procedures defined later in this file: */ @@ -89,6 +78,11 @@ * or else they are not considered. */ int hateFlags; /* If a spec contains any bits here, it's * not considered. */ + int result = TCL_ERROR; /* Return value. */ +#ifdef TCL_THREADS + int nOpts; /* Number of entries in specs. */ + Tk_ConfigSpec *specCopy = NULL; /* Copy of specs, malloc'ed. */ +#endif if (tkwin == NULL) { /* @@ -96,7 +90,7 @@ * we're on our way out of the application */ Tcl_AppendResult(interp, "NULL main window", (char *)NULL); - return TCL_ERROR; + goto done; } needFlags = flags & ~(TK_CONFIG_USER_BIT - 1); @@ -106,26 +100,28 @@ hateFlags = TK_CONFIG_MONO_ONLY; } +#ifdef TCL_THREADS /* - * Pass one: scan through all the option specs, replacing strings - * with Tk_Uid structs (if this hasn't been done already) and + * When threads are used, work on a copy of specs. + */ + + nOpts = 1; + for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) { + nOpts++; + } + nOpts *= sizeof(Tk_ConfigSpec); + specCopy = (Tk_ConfigSpec *)ckalloc(nOpts); + memcpy((VOID *)specCopy, (VOID *)specs, nOpts); + specs = specCopy; +#endif + + /* + * Pass one: scan through all the option specs, * clearing the TK_CONFIG_OPTION_SPECIFIED flags. */ for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) { - if (!(specPtr->specFlags & INIT) && (specPtr->argvName != NULL)) { - if (specPtr->dbName != NULL) { - specPtr->dbName = Tk_GetUid(specPtr->dbName); - } - if (specPtr->dbClass != NULL) { - specPtr->dbClass = Tk_GetUid(specPtr->dbClass); - } - if (specPtr->defValue != NULL) { - specPtr->defValue = Tk_GetUid(specPtr->defValue); - } - } - specPtr->specFlags = (specPtr->specFlags & ~TK_CONFIG_OPTION_SPECIFIED) - | INIT; + specPtr->specFlags = specPtr->specFlags & ~TK_CONFIG_OPTION_SPECIFIED; } /* @@ -143,7 +139,7 @@ } specPtr = FindConfigSpec(interp, specs, arg, needFlags, hateFlags); if (specPtr == NULL) { - return TCL_ERROR; + goto done; } /* @@ -153,7 +149,7 @@ if (argc < 2) { Tcl_AppendResult(interp, "value for \"", arg, "\" missing", (char *) NULL); - return TCL_ERROR; + goto done; } if (flags & TK_CONFIG_OBJS) { arg = Tcl_GetString((Tcl_Obj *) argv[1]); @@ -166,7 +162,7 @@ sprintf(msg, "\n (processing \"%.40s\" option)", specPtr->argvName); Tcl_AddErrorInfo(interp, msg); - return TCL_ERROR; + goto done; } specPtr->specFlags |= TK_CONFIG_OPTION_SPECIFIED; } @@ -202,7 +198,7 @@ "database entry for", specPtr->dbName, Tk_PathName(tkwin)); Tcl_AddErrorInfo(interp, msg); - return TCL_ERROR; + goto done; } } else { if (specPtr->defValue != NULL) { @@ -221,14 +217,21 @@ "default value for", specPtr->dbName, Tk_PathName(tkwin)); Tcl_AddErrorInfo(interp, msg); - return TCL_ERROR; + goto done; } } } } } - return TCL_OK; + result = TCL_OK; +done: +#ifdef TCL_THREADS + if (specCopy != NULL) { + ckfree((char *) specCopy); + } +#endif + return result; } /* @@ -315,7 +318,7 @@ argvName, "\"", (char *) NULL); return (Tk_ConfigSpec *) NULL; } - if ((specPtr->dbName == matchPtr->dbName) + if (!strcmp(specPtr->dbName, matchPtr->dbName) && (specPtr->type != TK_CONFIG_SYNONYM) && ((specPtr->specFlags & needFlags) == needFlags) && !(specPtr->specFlags & hateFlags)) { --- generic/tk.h.ORIG Thu Oct 10 02:31:14 2002 +++ generic/tk.h Wed Dec 11 12:52:14 2002 @@ -366,9 +366,9 @@ * table must have type TK_CONFIG_END. */ char *argvName; /* Switch used to specify option in argv. * NULL means this spec is part of a group. */ - Tk_Uid dbName; /* Name for option in option database. */ - Tk_Uid dbClass; /* Class for option in database. */ - Tk_Uid defValue; /* Default value for option if not + char *dbName; /* Name for option in option database. */ + char *dbClass; /* Class for option in database. */ + char *defValue; /* Default value for option if not * specified in command line or database. */ int offset; /* Where in widget record to store value; * use Tk_Offset macro to generate values --- generic/tkGet.c.ORIG Wed Aug 7 19:45:36 2002 +++ generic/tkGet.c Wed Dec 11 10:25:28 2002 @@ -20,19 +20,17 @@ #include "tkPort.h" /* - * One of these structures is created per thread to store - * thread-specific data. In this case, it is used to house the - * Tk_Uid structs used by each thread. The "dataKey" below is - * used to locate the ThreadSpecificData for the current thread. + * The Mutex below is used to lock access to the Uid table. */ -typedef struct ThreadSpecificData { - int initialized; - Tcl_HashTable uidTable; -} ThreadSpecificData; -static Tcl_ThreadDataKey dataKey; +TCL_DECLARE_MUTEX(uidMutex) -static void FreeUidThreadExitProc _ANSI_ARGS_((ClientData clientData)); +/* + * Hash table for Tk_Uid structs. + */ + +static int uidInitialized = 0; +static Tcl_HashTable uidTable; /* * The following tables defines the string values for reliefs, which are @@ -486,32 +484,6 @@ /* *---------------------------------------------------------------------- * - * FreeUidThreadExitProc -- - * - * Cleans up memory used for Tk_Uids in the thread. - * - * Results: - * None. - * - * Side effects: - * All information in the identifier table is deleted. - * - *---------------------------------------------------------------------- - */ - -static void -FreeUidThreadExitProc(clientData) - ClientData clientData; /* Not used. */ -{ - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - Tcl_DeleteHashTable(&tsdPtr->uidTable); - tsdPtr->initialized = 0; -} - -/* - *---------------------------------------------------------------------- - * * Tk_GetUid -- * * Given a string, this procedure returns a unique identifier @@ -537,17 +509,21 @@ CONST char *string; /* String to convert. */ { int dummy; - ThreadSpecificData *tsdPtr = (ThreadSpecificData *) - Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - Tcl_HashTable *tablePtr = &tsdPtr->uidTable; - - if (!tsdPtr->initialized) { - Tcl_InitHashTable(tablePtr, TCL_STRING_KEYS); - Tcl_CreateThreadExitHandler(FreeUidThreadExitProc, NULL); - tsdPtr->initialized = 1; - } - return (Tk_Uid) Tcl_GetHashKey(tablePtr, - Tcl_CreateHashEntry(tablePtr, string, &dummy)); + Tk_Uid uid; + + if (!uidInitialized) { + Tcl_MutexLock(&uidMutex); + if (!uidInitialized) { + Tcl_InitHashTable(&uidTable, TCL_STRING_KEYS); + uidInitialized = 1; + } + Tcl_MutexUnlock(&uidMutex); + } + Tcl_MutexLock(&uidMutex); + uid = (Tk_Uid) Tcl_GetHashKey(&uidTable, + Tcl_CreateHashEntry(&uidTable, string, &dummy)); + Tcl_MutexUnlock(&uidMutex); + return uid; } /* - login: "nobody"
- mimetype: "text/plain"
- username: "nobody"