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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*******************************************************************************
OpenAirInterface
Copyright(c) 1999 - 2014 Eurecom
OpenAirInterface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenAirInterface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenAirInterface.The full GNU General Public License is
included in this distribution in the file called "COPYING". If not,
see <http://www.gnu.org/licenses/>.
Contact Information
OpenAirInterface Admin: openair_admin@eurecom.fr
OpenAirInterface Tech : openair_tech@eurecom.fr
OpenAirInterface Dev : openair4g-devel@eurecom.fr
Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
*******************************************************************************/
/*! \file pdcp_thread.c
* \brief
* \author F. Kaltenberger
* \date 2013
* \version 0.1
* \company Eurecom
* \email: florian.kaltenberger@eurecom.fr
* \note
* \warning
*/
#include <pthread.h>
//#include <inttypes.h>
#include "pdcp.h"
#include "PHY/extern.h" //for PHY_vars
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#define OPENAIR_THREAD_STACK_SIZE 8192
#define OPENAIR_THREAD_PRIORITY 255
extern int oai_exit;
extern char UE_flag;
pthread_t pdcp_thread;
pthread_attr_t pdcp_thread_attr;
pthread_mutex_t pdcp_mutex;
pthread_cond_t pdcp_cond;
int pdcp_instance_cnt;
static void *pdcp_thread_main(void* param);
static void *pdcp_thread_main(void* param) {
uint8_t eNB_flag = !UE_flag;
LOG_I(PDCP,"This is pdcp_thread eNB_flag = %d\n",eNB_flag);
while (!oai_exit) {
if (pthread_mutex_lock(&pdcp_mutex) != 0) {
LOG_E(PDCP,"Error locking mutex.\n");
}
else {
while (pdcp_instance_cnt < 0) {
pthread_cond_wait(&pdcp_cond,&pdcp_mutex);
}
if (pthread_mutex_unlock(&pdcp_mutex) != 0) {
LOG_E(PDCP,"Error unlocking mutex.\n");
}
}
if (oai_exit) break;
if (eNB_flag) {
pdcp_run(PHY_vars_eNB_g[0]->frame, eNB_flag, PHY_vars_eNB_g[0]->Mod_id, 0);
LOG_D(PDCP,"Calling pdcp_run (eNB) for frame %d\n",PHY_vars_eNB_g[0]->frame);
}
else {
pdcp_run(PHY_vars_UE_g[0]->frame, eNB_flag, 0, PHY_vars_UE_g[0]->Mod_id);
LOG_D(PDCP,"Calling pdcp_run (UE) for frame %d\n",PHY_vars_UE_g[0]->frame);
}
if (pthread_mutex_lock(&pdcp_mutex) != 0) {
LOG_E(PDCP,"Error locking mutex.\n");
}
else {
pdcp_instance_cnt--;
if (pthread_mutex_unlock(&pdcp_mutex) != 0) {
LOG_E(PDCP,"Error unlocking mutex.\n");
}
}
}
return(NULL);
}
int init_pdcp_thread(void) {
int error_code;
struct sched_param p;
pthread_attr_init (&pdcp_thread_attr);
pthread_attr_setstacksize(&pdcp_thread_attr,OPENAIR_THREAD_STACK_SIZE);
//attr_dlsch_threads.priority = 1;
p.sched_priority = OPENAIR_THREAD_PRIORITY;
pthread_attr_setschedparam (&pdcp_thread_attr, &p);
#ifndef RTAI_ISNT_POSIX
pthread_attr_setschedpolicy (&pdcp_thread_attr, SCHED_FIFO);
#endif
pthread_mutex_init(&pdcp_mutex,NULL);
pthread_cond_init(&pdcp_cond,NULL);
pdcp_instance_cnt = -1;
LOG_I(PDCP,"Allocating PDCP thread\n");
error_code = pthread_create(&pdcp_thread,
&pdcp_thread_attr,
pdcp_thread_main,
(void*)NULL);
if (error_code!= 0) {
LOG_I(PDCP,"Could not allocate PDCP thread, error %d\n",error_code);
return(error_code);
}
else {
LOG_I(PDCP,"Allocate PDCP thread successful\n");
pthread_setname_np( pdcp_thread, "PDCP" );
}
return(0);
}
void cleanup_pdcp_thread(void) {
void *status_p = NULL;
LOG_I(PDCP,"Scheduling PDCP thread to exit\n");
pdcp_instance_cnt = 0;
if (pthread_cond_signal(&pdcp_cond) != 0)
LOG_I(PDCP,"ERROR pthread_cond_signal\n");
else
LOG_I(PDCP,"Signalled PDCP thread to exit\n");
pthread_join(pdcp_thread,&status_p);
LOG_I(PDCP,"PDCP thread exited\n");
pthread_cond_destroy(&pdcp_cond);
pthread_mutex_destroy(&pdcp_mutex);
}