summaryrefslogtreecommitdiffhomepage
path: root/src/core/lt_core.c
blob: b0c395286c914b931752796d8c2e7783379e1435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*******************************************************************/
/*  sltdl: a surrogate ltdl implementation                         */
/*  Copyright (C) 2019 Z. Gilboa                                   */
/*  Released under the Standard MIT License; see COPYING.SLTDL.    */
/*******************************************************************/

#include <limits.h>
#include <pthread.h>
#include <sltdl/sltdl.h>

static int             lt_refs = 0;
static pthread_mutex_t lt_lock = PTHREAD_MUTEX_INITIALIZER;

int lt_dlinit(void)
{
	if (pthread_mutex_lock(&lt_lock))
		return 1;

	lt_refs++;
	pthread_mutex_unlock(&lt_lock);

	return 0;
}

int lt_dlexit(void)
{
	if (pthread_mutex_lock(&lt_lock))
		return 1;

	if (!lt_refs) {
		pthread_mutex_unlock(&lt_lock);
		return 1;
	}

	lt_refs--;

	pthread_mutex_unlock(&lt_lock);

	return 0;
}