int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
                    int line)
{
    int ret = 0;

    if (add_lock_callback != NULL) {
#ifdef LOCK_DEBUG
        int before = *pointer;
#endif

        ret = add_lock_callback(pointer, amount, type, file, line);
#ifdef LOCK_DEBUG
        {
            CRYPTO_THREADID id;
            CRYPTO_THREADID_current(&id);
            fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
                    CRYPTO_THREADID_hash(&id), before, amount, ret,
                    CRYPTO_get_lock_name(type), file, line);
        }
#endif
    } else {
        CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);

        ret = *pointer + amount;
#ifdef LOCK_DEBUG
        {
            CRYPTO_THREADID id;
            CRYPTO_THREADID_current(&id);
            fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
                    CRYPTO_THREADID_hash(&id),
                    *pointer, amount, ret,
                    CRYPTO_get_lock_name(type), file, line);
        }
#endif
        *pointer = ret;
        CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);
    }
    return (ret);
}