Check-in [387697ce68]
Overview
Comment:Updated to deal with locking slightly better, maybe
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 387697ce68c3def1a06ee670025fc72971ed628f
User & Date: rkeene on 2016-12-13 03:20:53
Other Links: manifest | tags
Context
2016-12-13
05:12
Merged in work for the I/O layer being updated check-in: 2f45dac5f7 user: rkeene tags: trunk
03:21
Merged in trunk check-in: e5c9bfe50f user: rkeene tags: wip-fix-io-layer
03:20
Updated to deal with locking slightly better, maybe check-in: 387697ce68 user: rkeene tags: trunk
2016-12-12
22:39
Enabled more warnings check-in: b255cfbc6b user: rkeene tags: trunk
Changes

Modified tls.c from [5a902a9319] to [96e2a45ac0].

116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
116
117
118
119
120
121
122




123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
138







-
-
-
-
+







-
+







 * Threaded operation requires locking callbacks
 * Based from /crypto/cryptlib.c of OpenSSL and NSOpenSSL.
 */

static Tcl_Mutex *locks = NULL;
static Tcl_Mutex init_mx;

static void          CryptoThreadLockCallback(int mode, int n, const char *file, int line);
static unsigned long CryptoThreadIdCallback(void);

static void CryptoThreadLockCallback(int mode, int n, const char *file, int line) {
void CryptoThreadLockCallback(int mode, int n, const char *file, int line) {
	if (mode & CRYPTO_LOCK) {
		Tcl_MutexLock(&locks[n]);
	} else {
		Tcl_MutexUnlock(&locks[n]);
	}
}

static unsigned long CryptoThreadIdCallback(void) {
unsigned long CryptoThreadIdCallback(void) {
	return (unsigned long) Tcl_GetCurrentThread();
}
#endif /* OPENSSL_THREADS */
#endif /* TCL_THREADS */


/*
1690
1691
1692
1693
1694
1695
1696

1697
1698
1699
1700
1701
1702
1703
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701







+







		if (!initialized) {
			dprintf("Asked to uninitialize, but we are not initialized");

			return(TCL_OK);
		}

		dprintf("Asked to uninitialize");

#if defined(OPENSSL_THREADS) && defined(TCL_THREADS)
		Tcl_MutexLock(&init_mx);

		CRYPTO_set_locking_callback(NULL);
		CRYPTO_set_id_callback(NULL);

		if (locks) {
1714
1715
1716
1717
1718
1719
1720



1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724


1725
1726
1727
1728
1729
1730
1731







+
+
+



-
-







		return(TCL_OK);
	}

	if (initialized) {
		return(status);
	}

#if defined(OPENSSL_THREADS) && defined(TCL_THREADS)
	Tcl_MutexLock(&init_mx);
#endif
	initialized = 1;

#if defined(OPENSSL_THREADS) && defined(TCL_THREADS)
	Tcl_MutexLock(&init_mx);

	num_locks = CRYPTO_num_locks();
	locks = malloc(sizeof(*locks) * num_locks);

	CRYPTO_set_locking_callback(CryptoThreadLockCallback);
	CRYPTO_set_id_callback(CryptoThreadIdCallback);
#endif