Blame lib/locks.c

Packit aea12f
/*
Packit aea12f
 * Copyright (C) 2010-2012 Free Software Foundation, Inc.
Packit aea12f
 *
Packit aea12f
 * Author: Nikos Mavrogiannopoulos
Packit aea12f
 *
Packit aea12f
 * This file is part of GnuTLS.
Packit aea12f
 *
Packit aea12f
 * The GnuTLS is free software; you can redistribute it and/or
Packit aea12f
 * modify it under the terms of the GNU Lesser General Public License
Packit aea12f
 * as published by the Free Software Foundation; either version 2.1 of
Packit aea12f
 * the License, or (at your option) any later version.
Packit aea12f
 *
Packit aea12f
 * This library is distributed in the hope that it will be useful, but
Packit aea12f
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
 * Lesser General Public License for more details.
Packit aea12f
 *
Packit aea12f
 * You should have received a copy of the GNU Lesser General Public License
Packit aea12f
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
Packit aea12f
 *
Packit aea12f
 */
Packit aea12f
Packit aea12f
#include "gnutls_int.h"
Packit aea12f
#include "errors.h"
Packit aea12f
#include <libtasn1.h>
Packit aea12f
#include <dh.h>
Packit aea12f
#include <random.h>
Packit aea12f
Packit aea12f
#include <locks.h>
Packit aea12f
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_global_set_mutex:
Packit aea12f
 * @init: mutex initialization function
Packit aea12f
 * @deinit: mutex deinitialization function
Packit aea12f
 * @lock: mutex locking function
Packit aea12f
 * @unlock: mutex unlocking function
Packit aea12f
 *
Packit aea12f
 * With this function you are allowed to override the default mutex
Packit aea12f
 * locks used in some parts of gnutls and dependent libraries. This function
Packit aea12f
 * should be used if you have complete control of your program and libraries.
Packit aea12f
 * Do not call this function from a library, or preferably from any application
Packit aea12f
 * unless really needed to. GnuTLS will use the appropriate locks for the running
Packit aea12f
 * system.
Packit aea12f
 *
Packit aea12f
 * Note that since the move to implicit initialization of GnuTLS on library
Packit aea12f
 * load, calling this function will deinitialize the library, and re-initialize
Packit aea12f
 * it after the new locking functions are set.
Packit aea12f
 *
Packit aea12f
 * This function must be called prior to any other gnutls function.
Packit aea12f
 * 
Packit aea12f
 * Since: 2.12.0
Packit aea12f
 **/
Packit aea12f
void
Packit aea12f
gnutls_global_set_mutex(mutex_init_func init, mutex_deinit_func deinit,
Packit aea12f
			mutex_lock_func lock, mutex_unlock_func unlock)
Packit aea12f
{
Packit aea12f
int ret;
Packit aea12f
Packit aea12f
	if (init == NULL || deinit == NULL || lock == NULL
Packit aea12f
	    || unlock == NULL)
Packit aea12f
		return;
Packit aea12f
Packit aea12f
	gnutls_global_deinit();
Packit aea12f
Packit aea12f
	gnutls_mutex_init = init;
Packit aea12f
	gnutls_mutex_deinit = deinit;
Packit aea12f
	gnutls_mutex_lock = lock;
Packit aea12f
	gnutls_mutex_unlock = unlock;
Packit aea12f
Packit aea12f
	ret = gnutls_global_init();
Packit aea12f
	if (ret < 0)
Packit aea12f
		_gnutls_debug_log("error in gnutls_global_init(): %s\n", gnutls_strerror(ret));
Packit aea12f
}