38 XInitThreads being invoked. As a result, the display contained an |
38 XInitThreads being invoked. As a result, the display contained an |
39 opaque pointer to this context structure, which still contained an |
39 opaque pointer to this context structure, which still contained an |
40 uninitialized lock structure. |
40 uninitialized lock structure. |
41 |
41 |
42 The solution was to explicitly set the lock structure pointer to NULL |
42 The solution was to explicitly set the lock structure pointer to NULL |
43 (as a flag) when creating the context, then check for NULL before |
43 (as a flag) when creating the context, then check for NULL when |
44 locking. If NULL is found and threads are now enabled, then the |
44 locking. If NULL is found and threads are now enabled, then the |
45 structure gets reinitialized to the correct mutex lock structure |
45 structure gets reinitialized to the correct mutex lock structure |
46 before the lock call. |
46 in the lock call. |
47 |
47 |
48 Another area besides the functions in Context.c are the functions in |
48 Another area besides the functions in Context.c are the functions in |
49 Xrm.c. A similar fix was added to them as well. |
49 Xrm.c. A similar fix was added to them as well. |
50 |
50 |
51 |
51 |
52 diff -urp -x '*~' -x '*.orig' src/Context.c src/Context.c |
52 diff -urp -x '*~' -x '*.orig' src/Context.c src/Context.c |
53 --- src/Context.c 2007-05-16 08:34:44.000000000 -0700 |
53 --- src/Context.c 2009-01-28 21:09:42.000000000 -0800 |
54 +++ src/Context.c 2008-02-12 21:00:44.588363000 -0800 |
54 +++ src/Context.c 2009-04-08 00:17:42.988516000 -0700 |
55 @@ -192,6 +192,7 @@ int XSaveContext( |
55 @@ -192,6 +192,9 @@ int XSaveContext( |
56 return XCNOMEM; |
56 return XCNOMEM; |
57 } |
57 } |
58 db->numentries = 0; |
58 db->numentries = 0; |
|
59 +#ifdef SUNSOFT |
59 + db->linfo.lock = (xmutex_t) NULL; |
60 + db->linfo.lock = (xmutex_t) NULL; |
|
61 +#endif |
60 _XCreateMutex(&db->linfo); |
62 _XCreateMutex(&db->linfo); |
61 #ifdef MOTIFBC |
63 #ifdef MOTIFBC |
62 if (!display) *pdb = db; else |
64 if (!display) *pdb = db; else |
63 @@ -203,6 +204,8 @@ int XSaveContext( |
|
64 UnlockDisplay(display); |
|
65 } |
|
66 } |
|
67 + if (!db->linfo.lock) |
|
68 + _XCreateMutex(&db->linfo); |
|
69 _XLockMutex(&db->linfo); |
|
70 head = &Hash(db, rid, context); |
|
71 _XUnlockMutex(&db->linfo); |
|
72 @@ -254,6 +257,8 @@ int XFindContext(display, rid, context, |
|
73 } |
|
74 if (!db) |
|
75 return XCNOENT; |
|
76 + if (!db->linfo.lock) |
|
77 + _XCreateMutex(&db->linfo); |
|
78 _XLockMutex(&db->linfo); |
|
79 for (entry = Hash(db, rid, context); entry; entry = entry->next) |
|
80 { |
|
81 @@ -292,6 +297,8 @@ int XDeleteContext(display, rid, context |
|
82 } |
|
83 if (!db) |
|
84 return XCNOENT; |
|
85 + if (!db->linfo.lock) |
|
86 + _XCreateMutex(&db->linfo); |
|
87 _XLockMutex(&db->linfo); |
|
88 for (prev = &Hash(db, rid, context); |
|
89 (entry = *prev); |
|
90 diff -urp -x '*~' -x '*.orig' src/Xrm.c src/Xrm.c |
65 diff -urp -x '*~' -x '*.orig' src/Xrm.c src/Xrm.c |
91 --- src/Xrm.c 2007-05-16 08:34:44.000000000 -0700 |
66 --- src/Xrm.c 2009-03-25 17:52:09.000000000 -0700 |
92 +++ src/Xrm.c 2008-02-12 21:00:44.594920000 -0800 |
67 +++ src/Xrm.c 2009-04-08 00:17:43.008271000 -0700 |
93 @@ -500,6 +500,7 @@ static XrmDatabase NewDatabase(void) |
68 @@ -498,6 +498,9 @@ static XrmDatabase NewDatabase(void) |
94 |
69 |
95 db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec)); |
70 db = (XrmDatabase) Xmalloc(sizeof(XrmHashBucketRec)); |
96 if (db) { |
71 if (db) { |
|
72 +#ifdef SUNSOFT |
97 + db->linfo.lock = (xmutex_t) NULL; |
73 + db->linfo.lock = (xmutex_t) NULL; |
|
74 +#endif |
98 _XCreateMutex(&db->linfo); |
75 _XCreateMutex(&db->linfo); |
99 db->table = (NTable)NULL; |
76 db->table = (NTable)NULL; |
100 db->mbstate = (XPointer)NULL; |
77 db->mbstate = (XPointer)NULL; |
101 @@ -775,7 +776,11 @@ void XrmCombineDatabase( |
78 diff -urp -x '*~' -x '*.orig' src/locking.c src/locking.c |
102 if (!*into) { |
79 --- src/locking.c 2009-04-08 00:17:31.819992000 -0700 |
103 *into = from; |
80 +++ src/locking.c 2009-04-08 00:17:43.009128000 -0700 |
104 } else if (from) { |
81 @@ -105,6 +105,16 @@ static void _XLockMutex( |
105 + if (!(&from->linfo.lock)) |
82 XTHREADS_FILE_LINE_ARGS |
106 + _XCreateMutex(&from->linfo); |
83 ) |
107 _XLockMutex(&from->linfo); |
|
108 + if (!(&(*into)->linfo.lock)) |
|
109 + _XCreateMutex(&(*into)->linfo); |
|
110 _XLockMutex(&(*into)->linfo); |
|
111 if ((ftable = from->table)) { |
|
112 prev = &(*into)->table; |
|
113 @@ -1022,6 +1027,8 @@ void XrmQPutResource( |
|
114 XrmValuePtr value) |
|
115 { |
84 { |
116 if (!*pdb) *pdb = NewDatabase(); |
85 +#ifdef SUNSOFT |
117 + if (!(*pdb)->linfo.lock) |
86 + /* Make sure any locks in structures that were created before calling |
118 + _XCreateMutex(&(*pdb)->linfo); |
87 + * XInitThreads are initialized before locking, now that we allow calls |
119 _XLockMutex(&(*pdb)->linfo); |
88 + * to XInitThreads after other Xlib calls (Sun bugs 1234757 & 4010755) |
120 PutEntry(*pdb, bindings, quarks, type, value); |
89 + */ |
121 _XUnlockMutex(&(*pdb)->linfo); |
90 + if (lip->lock == NULL) { |
122 @@ -1038,6 +1045,8 @@ XrmPutResource( |
91 + static void _XCreateMutex(LockInfoPtr lip); /* Forward declaration */ |
123 XrmQuark quarks[MAXDBDEPTH+1]; |
92 + _XCreateMutex(lip); |
|
93 + } |
|
94 +#endif /* SUNSOFT */ |
|
95 xmutex_lock(lip->lock); |
|
96 } |
124 |
97 |
125 if (!*pdb) *pdb = NewDatabase(); |
|
126 + if (!(*pdb)->linfo.lock) |
|
127 + _XCreateMutex(&(*pdb)->linfo); |
|
128 _XLockMutex(&(*pdb)->linfo); |
|
129 XrmStringToBindingQuarkList(specifier, bindings, quarks); |
|
130 PutEntry(*pdb, bindings, quarks, XrmStringToQuark(type), value); |
|
131 @@ -1056,6 +1065,8 @@ XrmQPutStringResource( |
|
132 if (!*pdb) *pdb = NewDatabase(); |
|
133 value.addr = (XPointer) str; |
|
134 value.size = strlen(str)+1; |
|
135 + if (!(*pdb)->linfo.lock) |
|
136 + _XCreateMutex(&(*pdb)->linfo); |
|
137 _XLockMutex(&(*pdb)->linfo); |
|
138 PutEntry(*pdb, bindings, quarks, XrmQString, &value); |
|
139 _XUnlockMutex(&(*pdb)->linfo); |
|
140 @@ -1538,6 +1549,8 @@ XrmPutStringResource( |
|
141 XrmStringToBindingQuarkList(specifier, bindings, quarks); |
|
142 value.addr = (XPointer) str; |
|
143 value.size = strlen(str)+1; |
|
144 + if (!(*pdb)->linfo.lock) |
|
145 + _XCreateMutex(&(*pdb)->linfo); |
|
146 _XLockMutex(&(*pdb)->linfo); |
|
147 PutEntry(*pdb, bindings, quarks, XrmQString, &value); |
|
148 _XUnlockMutex(&(*pdb)->linfo); |
|
149 @@ -1550,6 +1563,8 @@ XrmPutLineResource( |
|
150 _Xconst char*line) |
|
151 { |
|
152 if (!*pdb) *pdb = NewDatabase(); |
|
153 + if (!(*pdb)->linfo.lock) |
|
154 + _XCreateMutex(&(*pdb)->linfo); |
|
155 _XLockMutex(&(*pdb)->linfo); |
|
156 GetDatabase(*pdb, line, (char *)NULL, False); |
|
157 _XUnlockMutex(&(*pdb)->linfo); |
|
158 @@ -1562,6 +1577,8 @@ XrmGetStringDatabase( |
|
159 XrmDatabase db; |
|
160 |
|
161 db = NewDatabase(); |
|
162 + if (!db->linfo.lock) |
|
163 + _XCreateMutex(&db->linfo); |
|
164 _XLockMutex(&db->linfo); |
|
165 GetDatabase(db, data, (char *)NULL, True); |
|
166 _XUnlockMutex(&db->linfo); |
|
167 @@ -1670,6 +1687,8 @@ XrmGetFileDatabase( |
|
168 return (XrmDatabase)NULL; |
|
169 |
|
170 db = NewDatabase(); |
|
171 + if (!db->linfo.lock) |
|
172 + _XCreateMutex(&db->linfo); |
|
173 _XLockMutex(&db->linfo); |
|
174 GetDatabase(db, str, filename, True); |
|
175 _XUnlockMutex(&db->linfo); |
|
176 @@ -1694,6 +1713,8 @@ XrmCombineFileDatabase( |
|
177 *target = db = NewDatabase(); |
|
178 } else |
|
179 db = NewDatabase(); |
|
180 + if (!db->linfo.lock) |
|
181 + _XCreateMutex(&db->linfo); |
|
182 _XLockMutex(&db->linfo); |
|
183 GetDatabase(db, str, filename, True); |
|
184 _XUnlockMutex(&db->linfo); |
|
185 @@ -1966,6 +1987,8 @@ Bool XrmEnumerateDatabase( |
|
186 |
|
187 if (!db) |
|
188 return False; |
|
189 + if (!db->linfo.lock) |
|
190 + _XCreateMutex(&db->linfo); |
|
191 _XLockMutex(&db->linfo); |
|
192 eclosure.db = db; |
|
193 eclosure.proc = proc; |
|
194 @@ -2262,6 +2285,8 @@ Bool XrmQGetSearchList( |
|
195 closure.idx = -1; |
|
196 closure.limit = listLength - 2; |
|
197 if (db) { |
|
198 + if (!db->linfo.lock) |
|
199 + _XCreateMutex(&db->linfo); |
|
200 _XLockMutex(&db->linfo); |
|
201 table = db->table; |
|
202 if (*names) { |
|
203 @@ -2540,6 +2565,8 @@ Bool XrmQGetResource( |
|
204 VClosureRec closure; |
|
205 |
|
206 if (db && *names) { |
|
207 + if (!db->linfo.lock) |
|
208 + _XCreateMutex(&db->linfo); |
|
209 _XLockMutex(&db->linfo); |
|
210 closure.type = pType; |
|
211 closure.value = pValue; |
|
212 @@ -2636,6 +2663,8 @@ XrmLocaleOfDatabase( |
|
213 XrmDatabase db) |
|
214 { |
|
215 const char* retval; |
|
216 + if (!db->linfo.lock) |
|
217 + _XCreateMutex(&db->linfo); |
|
218 _XLockMutex(&db->linfo); |
|
219 retval = (*db->methods->lcname)(db->mbstate); |
|
220 _XUnlockMutex(&db->linfo); |
|
221 @@ -2648,6 +2677,8 @@ void XrmDestroyDatabase( |
|
222 register NTable table, next; |
|
223 |
|
224 if (db) { |
|
225 + if (!db->linfo.lock) |
|
226 + _XCreateMutex(&db->linfo); |
|
227 _XLockMutex(&db->linfo); |
|
228 for (next = db->table; (table = next); ) { |
|
229 next = table->next; |
|