Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
canghaiwuhen
OpenXG-RAN
Commits
946fcad6
Commit
946fcad6
authored
Dec 05, 2016
by
Xiwen JIANG
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add thread_pool files
parent
c57a990f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
0 deletions
+121
-0
openair1/PHY/TOOLS/thread_pool.c
openair1/PHY/TOOLS/thread_pool.c
+92
-0
openair1/PHY/TOOLS/thread_pool.h
openair1/PHY/TOOLS/thread_pool.h
+29
-0
No files found.
openair1/PHY/TOOLS/thread_pool.c
0 → 100644
View file @
946fcad6
#include "thread_pool.h"
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include "PHY/defs.h"
thread_pool
*
new_thread_pool
(
void
*
(
*
thread_fun
)(
PHY_VARS_eNB
*
arg
),
PHY_VARS_eNB
*
eNB
)
{
int
i
;
pthread_t
thread_id
;
pthread_attr_t
th_att
;
thread_pool
*
ret
;
eNB
->
pool
=
calloc
(
1
,
sizeof
(
thread_pool
));
ret
=
eNB
->
pool
;
if
(
ret
==
NULL
)
abort
();
ret
->
mutex
=
calloc
(
1
,
sizeof
(
pthread_mutex_t
));
if
(
ret
->
mutex
==
NULL
)
abort
();
if
(
pthread_mutex_init
(
ret
->
mutex
,
NULL
)
!=
0
)
abort
();
ret
->
cond
=
calloc
(
1
,
sizeof
(
pthread_cond_t
));
if
(
ret
->
cond
==
NULL
)
abort
();
if
(
pthread_cond_init
(
ret
->
cond
,
NULL
)
!=
0
)
abort
();
ret
->
mutex_join
=
calloc
(
1
,
sizeof
(
pthread_mutex_t
));
if
(
ret
->
mutex_join
==
NULL
)
abort
();
if
(
pthread_mutex_init
(
ret
->
mutex_join
,
NULL
)
!=
0
)
abort
();
ret
->
cond_join
=
calloc
(
1
,
sizeof
(
pthread_cond_t
));
if
(
ret
->
cond_join
==
NULL
)
abort
();
if
(
pthread_cond_init
(
ret
->
cond_join
,
NULL
)
!=
0
)
abort
();
ret
->
number_of_threads
=
eNB
->
frame_parms
.
nb_antennas_tx
;
ret
->
running
=
0
;
ret
->
done
=
ret
->
number_of_threads
;
for
(
i
=
0
;
i
<
ret
->
number_of_threads
;
i
++
)
{
// struct sched_param th_params;
if
(
pthread_attr_init
(
&
th_att
)
!=
0
)
abort
();
// if (pthread_attr_setschedpolicy(&th_att, SCHED_FIFO) != 0) abort();
// th_params.sched_priority = 99; /* max priority */
// if (pthread_attr_setschedparam(&th_att, &th_params) != 0) abort();
// if (pthread_attr_setinheritsched(&th_att, PTHREAD_EXPLICIT_SCHED) != 0) abort();
if
(
pthread_create
(
&
thread_id
,
&
th_att
,
thread_fun
,
eNB
)
!=
0
)
abort
();
if
(
pthread_attr_destroy
(
&
th_att
))
abort
();
}
return
ret
;
}
void
thread_pool_start
(
thread_pool
*
pool
)
{
if
(
pool
->
done
!=
pool
->
number_of_threads
)
{
fprintf
(
stderr
,
"thread_pool: ERROR: thread_pool_start called "
"with some threads still running
\n
"
);
abort
();
}
pool
->
done
=
0
;
pool
->
running
=
pool
->
number_of_threads
;
if
(
pthread_cond_broadcast
(
pool
->
cond
))
abort
();
}
void
thread_pool_done
(
thread_pool
*
pool
)
{
if
(
pthread_mutex_lock
(
pool
->
mutex_join
))
abort
();
pool
->
done
++
;
if
(
pthread_cond_signal
(
pool
->
cond_join
))
abort
();
if
(
pthread_mutex_unlock
(
pool
->
mutex_join
))
abort
();
}
int
thread_pool_wait
(
thread_pool
*
pool
)
{
int
ret
;
if
(
pthread_mutex_lock
(
pool
->
mutex
))
abort
();
while
(
pool
->
running
==
0
)
{
if
(
pthread_cond_wait
(
pool
->
cond
,
pool
->
mutex
))
abort
();
}
pool
->
running
--
;
ret
=
pool
->
running
;
if
(
pthread_mutex_unlock
(
pool
->
mutex
))
abort
();
return
ret
;
}
void
thread_pool_join
(
thread_pool
*
pool
)
{
if
(
pthread_mutex_lock
(
pool
->
mutex_join
))
abort
();
while
(
pool
->
done
!=
pool
->
number_of_threads
)
{
if
(
pthread_cond_wait
(
pool
->
cond_join
,
pool
->
mutex_join
))
abort
();
}
if
(
pthread_mutex_unlock
(
pool
->
mutex_join
))
abort
();
}
openair1/PHY/TOOLS/thread_pool.h
0 → 100644
View file @
946fcad6
#ifndef _THREAD_POOL_H_
#define _THREAD_POOL_H_
#include <pthread.h>
struct
PHY_VARS_eNB_s
;
typedef
struct
thread_pool
{
pthread_mutex_t
*
mutex
;
pthread_cond_t
*
cond
;
pthread_mutex_t
*
mutex_join
;
pthread_cond_t
*
cond_join
;
int
number_of_threads
;
volatile
int
running
;
volatile
int
done
;
/* processing data */
volatile
int
subframe
;
}
thread_pool
;
thread_pool
*
new_thread_pool
(
void
*
(
*
thread_fun
)(
struct
PHY_VARS_eNB_s
*
eNB
),
struct
PHY_VARS_eNB_s
*
eNB
);
void
thread_pool_start
(
thread_pool
*
pool
);
void
thread_pool_done
(
thread_pool
*
pool
);
int
thread_pool_wait
(
thread_pool
*
pool
);
void
thread_pool_join
(
thread_pool
*
pool
);
#endif
/* _THREAD_POOL_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment