瀏覽代碼

Remove leftovers of the old-style locks.

At this point, none of these functions or macros are used so they can
just be deleted.

Change-Id: I8ed1aae7a252e886864bf43e3096eff2228183cd
Reviewed-on: https://boringssl-review.googlesource.com/4777
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
Adam Langley 9 年之前
committed by Adam Langley
父節點
當前提交
552df47dc0
共有 2 個文件被更改,包括 12 次插入149 次删除
  1. +4
    -44
      crypto/thread.c
  2. +8
    -105
      include/openssl/thread.h

+ 4
- 44
crypto/thread.c 查看文件

@@ -69,40 +69,16 @@
#include <openssl/mem.h>


#define CRYPTO_LOCK_ITEM(x) #x

/* lock_names contains the names of all the locks defined in thread.h. */
static const char *const lock_names[] = {
CRYPTO_LOCK_LIST
};

#undef CRYPTO_LOCK_ITEM

#define CRYPTO_NUM_LOCKS (sizeof(lock_names) / sizeof(lock_names[0]))

static void (*locking_callback)(int mode, int lock_num, const char *file,
int line) = 0;
static int (*add_lock_callback)(int *pointer, int amount, int lock_num,
const char *file, int line) = 0;

int CRYPTO_num_locks(void) { return CRYPTO_NUM_LOCKS; }
int CRYPTO_num_locks(void) { return 1; }

void CRYPTO_set_locking_callback(void (*func)(int mode, int lock_num,
const char *file, int line)) {
locking_callback = func;
}
const char *file, int line)) {}

void CRYPTO_set_add_lock_callback(int (*func)(int *num, int mount, int lock_num,
const char *file, int line)) {
add_lock_callback = func;
}
const char *file, int line)) {}

const char *CRYPTO_get_lock_name(int lock_num) {
if (lock_num >= 0 && lock_num < CRYPTO_NUM_LOCKS) {
return lock_names[lock_num];
} else {
return "ERROR";
}
return "No old-style OpenSSL locks anymore";
}

int CRYPTO_THREADID_set_callback(void (*func)(CRYPTO_THREADID *)) { return 1; }
@@ -113,22 +89,6 @@ void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr) {}

void CRYPTO_THREADID_current(CRYPTO_THREADID *id) {}

void (*CRYPTO_get_locking_callback(void))(int mode, int lock_num,
const char *file, int line) {
return locking_callback;
}

int (*CRYPTO_get_add_lock_callback(void))(int *num, int mount, int lock_num,
const char *file, int line) {
return add_lock_callback;
}

void CRYPTO_lock(int mode, int lock_num, const char *file, int line) {
if (locking_callback != NULL) {
locking_callback(mode, lock_num, file, line);
}
}

void CRYPTO_set_id_callback(unsigned long (*func)(void)) {}

void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(


+ 8
- 105
include/openssl/thread.h 查看文件

@@ -100,55 +100,25 @@ typedef union crypto_mutex_st {
typedef uint32_t CRYPTO_refcount_t;


/* Functions to support multithreading.
*
* OpenSSL can safely be used in multi-threaded applications provided that at
* least |CRYPTO_set_locking_callback| is set.
*
* The locking callback performs mutual exclusion. Rather than using a single
* lock for all, shared data-structures, OpenSSL requires that the locking
* callback support a fixed (at run-time) number of different locks, given by
* |CRYPTO_num_locks|. */

/* Deprecated functions */

/* CRYPTO_num_locks returns the number of static locks that the callback
* function passed to |CRYPTO_set_locking_callback| must be able to handle. */
/* CRYPTO_num_locks returns one. (This is non-zero that callers who allocate
* sizeof(lock) times this value don't get zero and then fail because malloc(0)
* returned NULL.) */
OPENSSL_EXPORT int CRYPTO_num_locks(void);

/* CRYPTO_set_locking_callback sets a callback function that implements locking
* on behalf of OpenSSL. The callback is called whenever OpenSSL needs to lock
* or unlock a lock, and locks are specified as a number between zero and
* |CRYPTO_num_locks()-1|.
*
* The mode argument to the callback is a bitwise-OR of either CRYPTO_LOCK or
* CRYPTO_UNLOCK, to denote the action, and CRYPTO_READ or CRYPTO_WRITE, to
* indicate the type of lock. The |file| and |line| arguments give the location
* in the OpenSSL source where the locking action originated. */
/* CRYPTO_set_locking_callback does nothing. */
OPENSSL_EXPORT void CRYPTO_set_locking_callback(
void (*func)(int mode, int lock_num, const char *file, int line));

/* CRYPTO_set_add_lock_callback sets an optional callback which is used when
* OpenSSL needs to add a fixed amount to an integer. For example, this is used
* when maintaining reference counts. Normally the reference counts are
* maintained by performing the addition under a lock but, if this callback
* has been set, the application is free to implement the operation using
* faster methods (i.e. atomic operations).
*
* The callback is given a pointer to the integer to be altered (|num|), the
* amount to add to the integer (|amount|, which may be negative), the number
* of the lock which would have been taken to protect the operation and the
* position in the OpenSSL code where the operation originated. */
/* CRYPTO_set_add_lock_callback does nothing. */
OPENSSL_EXPORT void CRYPTO_set_add_lock_callback(int (*func)(
int *num, int amount, int lock_num, const char *file, int line));

/* CRYPTO_get_lock_name returns the name of the lock given by |lock_num|. This
* can be used in a locking callback for debugging purposes. */
/* CRYPTO_get_lock_name returns a fixed, dummy string. */
OPENSSL_EXPORT const char *CRYPTO_get_lock_name(int lock_num);


/* Deprecated functions */

/* CRYPTO_THREADID_set_callback does nothing. */
/* CRYPTO_THREADID_set_callback returns one. */
OPENSSL_EXPORT int CRYPTO_THREADID_set_callback(
void (*threadid_func)(CRYPTO_THREADID *threadid));

@@ -163,73 +133,6 @@ OPENSSL_EXPORT void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
OPENSSL_EXPORT void CRYPTO_THREADID_current(CRYPTO_THREADID *id);


/* Private functions: */

/* CRYPTO_get_locking_callback returns the callback, if any, that was most
* recently set using |CRYPTO_set_locking_callback|. */
void (*CRYPTO_get_locking_callback(void))(int mode, int lock_num,
const char *file, int line);

/* CRYPTO_get_add_lock_callback returns the callback, if any, that was most
* recently set using |CRYPTO_set_add_lock_callback|. */
int (*CRYPTO_get_add_lock_callback(void))(int *num, int amount, int lock_num,
const char *file, int line);

/* CRYPTO_lock locks or unlocks the lock specified by |lock_num| (one of
* |CRYPTO_LOCK_*|). Don't call this directly, rather use one of the
* CRYPTO_[rw]_(un)lock macros. */
OPENSSL_EXPORT void CRYPTO_lock(int mode, int lock_num, const char *file,
int line);

/* Lock IDs start from 1. CRYPTO_LOCK_INVALID_LOCK is an unused placeholder
* used to ensure no lock has ID 0. */
#define CRYPTO_LOCK_LIST \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_INVALID_LOCK), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_BIO), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_DH), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_DSA), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EC), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EC_PRE_COMP), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_ERR), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EVP_PKEY), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EX_DATA), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_OBJ), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RAND), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_READDIR), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RSA), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RSA_BLINDING), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_SSL_CTX), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_SSL_SESSION), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_INFO), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_PKEY), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_CRL), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_REQ), \
CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_STORE), \

#define CRYPTO_LOCK_ITEM(x) x

enum {
CRYPTO_LOCK_LIST
};

#undef CRYPTO_LOCK_ITEM

#define CRYPTO_LOCK 1
#define CRYPTO_UNLOCK 2
#define CRYPTO_READ 4
#define CRYPTO_WRITE 8

#define CRYPTO_w_lock(lock_num) \
CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, lock_num, __FILE__, __LINE__)
#define CRYPTO_w_unlock(lock_num) \
CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, lock_num, __FILE__, __LINE__)
#define CRYPTO_r_lock(lock_num) \
CRYPTO_lock(CRYPTO_LOCK | CRYPTO_READ, lock_num, __FILE__, __LINE__)
#define CRYPTO_r_unlock(lock_num) \
CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_READ, lock_num, __FILE__, __LINE__)


/* Private functions.
*
* Some old code calls these functions and so no-op implementations are


Loading…
取消
儲存