Coverage Report

Created: 2024-02-25 06:34

/src/kamailio/src/core/lock_alloc.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * Copyright (C) 2001-2003 FhG Fokus
4
 *
5
 * This file is part of Kamailio, a free SIP server.
6
 *
7
 * Kamailio is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version
11
 *
12
 * For a license to use the Kamailio software under conditions
13
 * other than those described here, or to purchase support for this
14
 * software, please contact iptel.org by e-mail at the following addresses:
15
 *    info@iptel.org
16
 *
17
 * Kamailio is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25
 */
26
27
/*!
28
* \file
29
* \brief Kamailio core :: Kamailio locking library
30
* \author andrei
31
* \ingroup core
32
* Module: \ref core
33
*
34
 *   WARNING: don't include this directly include instead locking.h!
35
 *
36
Implements: (see also locking.h)
37
38
  simple locks:
39
  -------------
40
  gen_lock_t* lock_alloc();                - allocates a lock in shared mem.
41
  void    lock_dealloc(gen_lock_t* lock);  - deallocates the lock's shared m.
42
43
  lock sets: [implemented only for FL & SYSV so far]
44
  ----------
45
  gen_lock_set_t* lock_set_alloc(no)               - allocs a lock set in shm.
46
  void lock_set_dealloc(gen_lock_set_t* s);        - deallocs the lock set shm.
47
48
*/
49
50
#ifndef _lock_alloc_h
51
#define _lock_alloc_h
52
53
/*shm_{malloc, free}*/
54
#include "mem/mem.h"
55
#include "mem/shm_mem.h"
56
57
#if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
58
/* simple locks*/
59
0
#define lock_alloc() shm_malloc(sizeof(gen_lock_t))
60
0
#define lock_dealloc(lock) shm_free((void *)lock)
61
/* lock sets */
62
63
inline static gen_lock_set_t *lock_set_alloc(int n)
64
0
{
65
0
  gen_lock_set_t *ls;
66
0
  ls = (gen_lock_set_t *)shm_malloc(
67
0
      sizeof(gen_lock_set_t) + n * sizeof(gen_lock_t));
68
0
  if(ls == 0) {
69
0
    SHM_MEM_CRITICAL;
70
0
  } else {
71
0
    ls->locks = (gen_lock_t *)((char *)ls + sizeof(gen_lock_set_t));
72
0
    ls->size = n;
73
0
  }
74
0
  return ls;
75
0
}
Unexecuted instantiation: main.c:lock_set_alloc
Unexecuted instantiation: modparam.c:lock_set_alloc
Unexecuted instantiation: pt.c:lock_set_alloc
Unexecuted instantiation: receive.c:lock_set_alloc
Unexecuted instantiation: resolve.c:lock_set_alloc
Unexecuted instantiation: route.c:lock_set_alloc
Unexecuted instantiation: rpc_lookup.c:lock_set_alloc
Unexecuted instantiation: select_core.c:lock_set_alloc
Unexecuted instantiation: socket_info.c:lock_set_alloc
Unexecuted instantiation: sr_module.c:lock_set_alloc
Unexecuted instantiation: tcp_main.c:lock_set_alloc
Unexecuted instantiation: tcp_read.c:lock_set_alloc
Unexecuted instantiation: tcp_stats.c:lock_set_alloc
Unexecuted instantiation: timer.c:lock_set_alloc
Unexecuted instantiation: timer_proc.c:lock_set_alloc
Unexecuted instantiation: tls_hooks.c:lock_set_alloc
Unexecuted instantiation: udp_server.c:lock_set_alloc
Unexecuted instantiation: usr_avp.c:lock_set_alloc
Unexecuted instantiation: action.c:lock_set_alloc
Unexecuted instantiation: async_task.c:lock_set_alloc
Unexecuted instantiation: cfg.c:lock_set_alloc
Unexecuted instantiation: cfg.tab.c:lock_set_alloc
Unexecuted instantiation: cfg_core.c:lock_set_alloc
Unexecuted instantiation: cfg_ctx.c:lock_set_alloc
Unexecuted instantiation: cfg_script.c:lock_set_alloc
Unexecuted instantiation: cfg_select.c:lock_set_alloc
Unexecuted instantiation: cfg_struct.c:lock_set_alloc
Unexecuted instantiation: core_cmd.c:lock_set_alloc
Unexecuted instantiation: counters.c:lock_set_alloc
Unexecuted instantiation: dns_cache.c:lock_set_alloc
Unexecuted instantiation: dst_blocklist.c:lock_set_alloc
Unexecuted instantiation: flags.c:lock_set_alloc
Unexecuted instantiation: forward.c:lock_set_alloc
Unexecuted instantiation: io_wait.c:lock_set_alloc
Unexecuted instantiation: ip_addr.c:lock_set_alloc
Unexecuted instantiation: kemi.c:lock_set_alloc
Unexecuted instantiation: local_timer.c:lock_set_alloc
Unexecuted instantiation: locking.c:lock_set_alloc
Unexecuted instantiation: mod_fix.c:lock_set_alloc
Unexecuted instantiation: msg_translator.c:lock_set_alloc
Unexecuted instantiation: proxy.c:lock_set_alloc
76
77
#define lock_set_dealloc(lock_set) shm_free((void *)lock_set)
78
79
#elif defined USE_SYSV_SEM
80
81
/*simple locks*/
82
#define lock_alloc() shm_malloc(sizeof(gen_lock_t))
83
#define lock_dealloc(lock) shm_free((void *)lock)
84
/* lock sets */
85
86
inline static gen_lock_set_t *lock_set_alloc(int n)
87
{
88
  gen_lock_set_t *ls;
89
  ls = (gen_lock_set_t *)shm_malloc(sizeof(gen_lock_set_t));
90
  if(ls == 0) {
91
    SHM_MEM_CRITICAL;
92
  } else {
93
    ls->size = n;
94
    ls->semid = -1;
95
  }
96
  return ls;
97
}
98
99
100
#define lock_set_dealloc(lock_set) shm_free((void *)lock_set)
101
102
103
#else
104
#error "no locking method selected"
105
#endif
106
107
108
#endif