Coverage Report

Created: 2023-03-26 07:33

/src/gnutls/lib/system/threads.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010-2016 Free Software Foundation, Inc.
3
 * Copyright (C) 2015-2016 Red Hat, Inc.
4
 *
5
 * Author: Nikos Mavrogiannopoulos
6
 *
7
 * This file is part of GnuTLS.
8
 *
9
 * The GnuTLS is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public License
11
 * as published by the Free Software Foundation; either version 2.1 of
12
 * the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful, but
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
21
 *
22
 */
23
24
#include <config.h>
25
#include <system.h>
26
#include "gnutls_int.h"
27
#include "errors.h"
28
29
#include <sys/socket.h>
30
#include <errno.h>
31
#include <sys/stat.h>
32
#include <sys/types.h>
33
34
#include "glthread/lock.h"
35
36
/* System specific lock function wrappers.
37
 */
38
39
/* Thread stuff */
40
41
static int gnutls_system_mutex_init(void **priv)
42
0
{
43
0
  gl_lock_t *lock = malloc(sizeof(gl_lock_t));
44
45
0
  if (!lock) {
46
0
    return GNUTLS_E_MEMORY_ERROR;
47
0
  }
48
49
0
  if (glthread_lock_init(lock)) {
50
0
    free(lock);
51
0
    return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR);
52
0
  }
53
54
0
  *priv = lock;
55
0
  return 0;
56
0
}
57
58
static int gnutls_system_mutex_deinit(void **priv)
59
0
{
60
0
  if (glthread_lock_destroy((gl_lock_t *) * priv)) {
61
0
    return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR);
62
0
  }
63
0
  free(*priv);
64
0
  return 0;
65
0
}
66
67
static int gnutls_system_mutex_lock(void **priv)
68
0
{
69
0
  if (glthread_lock_lock((gl_lock_t *) * priv)) {
70
0
    return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR);
71
0
  }
72
0
  return 0;
73
0
}
74
75
static int gnutls_system_mutex_unlock(void **priv)
76
0
{
77
0
  if (glthread_lock_unlock((gl_lock_t *) * priv)) {
78
0
    return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR);
79
0
  }
80
0
  return 0;
81
0
}
82
83
mutex_init_func gnutls_mutex_init = gnutls_system_mutex_init;
84
mutex_deinit_func gnutls_mutex_deinit = gnutls_system_mutex_deinit;
85
mutex_lock_func gnutls_mutex_lock = gnutls_system_mutex_lock;
86
mutex_unlock_func gnutls_mutex_unlock = gnutls_system_mutex_unlock;