Browse code

usrloc: renamed main files to match module name

Daniel-Constantin Mierla authored on 21/12/2016 20:40:24
Showing 1 changed files
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,115 @@
1
+/*
2
+ * Copyright (C) 2001-2003 FhG Fokus
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License 
17
+ * along with this program; if not, write to the Free Software 
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ */
20
+
21
+/*! \file
22
+ *  \brief USRLOC - Hash table collision slot related functions
23
+ *  \ingroup usrloc
24
+ *
25
+ * - Module: \ref usrloc
26
+ */
27
+
28
+
29
+
30
+#include "hslot.h"
31
+
32
+/*!
33
+ * \brief Initialize cache slot structure
34
+ * \param _d domain for the hash slot
35
+ * \param _s hash slot
36
+ * \param n used to get the slot number (modulo number or locks)
37
+ */
38
+int init_slot(struct udomain* _d, hslot_t* _s, int n)
39
+{
40
+	_s->n = 0;
41
+	_s->first = 0;
42
+	_s->last = 0;
43
+	_s->d = _d;
44
+	if(rec_lock_init(&_s->rlock)==NULL) {
45
+		LM_ERR("failed to initialize the slock (%d)\n", n);
46
+		return -1;
47
+	}
48
+	return 0;
49
+}
50
+
51
+
52
+/*!
53
+ * \brief Deinitialize given slot structure
54
+ * \param _s hash slot
55
+ */
56
+void deinit_slot(hslot_t* _s)
57
+{
58
+	struct urecord* ptr;
59
+
60
+	/* Remove all elements */
61
+	while(_s->first) {
62
+		ptr = _s->first;
63
+		_s->first = _s->first->next;
64
+		free_urecord(ptr);
65
+	}
66
+	rec_lock_destroy(&_s->rlock);
67
+
68
+	_s->n = 0;
69
+	_s->last = 0;
70
+    _s->d = 0;
71
+}
72
+
73
+
74
+/*!
75
+ * \brief Add an element to an slot's linked list
76
+ * \param _s hash slot
77
+ * \param _r added record
78
+ */
79
+void slot_add(hslot_t* _s, struct urecord* _r)
80
+{
81
+	if (_s->n == 0) {
82
+		_s->first = _s->last = _r;
83
+	} else {
84
+		_r->prev = _s->last;
85
+		_s->last->next = _r;
86
+		_s->last = _r;
87
+	}
88
+	_s->n++;
89
+	_r->slot = _s;
90
+}
91
+
92
+
93
+/*!
94
+ * \brief Remove an element from slot linked list
95
+ * \param _s hash slot
96
+ * \param _r removed record
97
+ */
98
+void slot_rem(hslot_t* _s, struct urecord* _r)
99
+{
100
+	if (_r->prev) {
101
+		_r->prev->next = _r->next;
102
+	} else {
103
+		_s->first = _r->next;
104
+	}
105
+
106
+	if (_r->next) {
107
+		_r->next->prev = _r->prev;
108
+	} else {
109
+		_s->last = _r->prev;
110
+	}
111
+
112
+	_r->prev = _r->next = 0;
113
+	_r->slot = 0;
114
+	_s->n--;
115
+}