Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
unix
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
tu-wien
unix
Commits
8c423aaa
Commit
8c423aaa
authored
Jan 13, 2019
by
Ivaylo Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add clean_up function, add num_nodes logic to generator, change docs
parent
4d9c62cb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
13 deletions
+42
-13
fb_arc_set/generator.c
fb_arc_set/generator.c
+15
-4
fb_arc_set/shared/structs.c
fb_arc_set/shared/structs.c
+6
-6
fb_arc_set/supervisor.c
fb_arc_set/supervisor.c
+21
-3
No files found.
fb_arc_set/generator.c
View file @
8c423aaa
...
@@ -47,12 +47,14 @@ int main(int argc, char *argv[]) {
...
@@ -47,12 +47,14 @@ int main(int argc, char *argv[]) {
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
edge_t
edges
[
argc
-
2
];
///< Array to hold the edges
int
num_edges
=
argc
-
1
;
edge_t
edges
[
num_edges
];
///< Array to hold all edges
char
edge
[
128
];
///< Variable to hold a single edge later on
char
edge
[
128
];
///< Variable to hold a single edge later on
edge
[
127
]
=
0
;
edge
[
127
]
=
0
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
int
num_nodes
=
0
;
for
(
int
i
=
1
;
i
<=
num_edges
;
i
++
)
{
/// Check the input and terminate if incorrect
/// Check the input and terminate if incorrect
if
(
regexec
(
&
regex
,
argv
[
i
],
0
,
NULL
,
0
)
==
REG_NOMATCH
)
{
if
(
regexec
(
&
regex
,
argv
[
i
],
0
,
NULL
,
0
)
==
REG_NOMATCH
)
{
fprintf
(
stderr
,
"ERROR: Incorrect input found
\n
"
);
fprintf
(
stderr
,
"ERROR: Incorrect input found
\n
"
);
...
@@ -65,13 +67,22 @@ int main(int argc, char *argv[]) {
...
@@ -65,13 +67,22 @@ int main(int argc, char *argv[]) {
char
*
v
=
strtok
(
NULL
,
""
);
char
*
v
=
strtok
(
NULL
,
""
);
edges
[
i
-
1
].
u
=
strtol
(
u
,
NULL
,
10
);
edges
[
i
-
1
].
u
=
strtol
(
u
,
NULL
,
10
);
edges
[
i
-
1
].
v
=
strtol
(
v
,
NULL
,
10
);
edges
[
i
-
1
].
v
=
strtol
(
v
,
NULL
,
10
);
if
(
num_nodes
<
edges
[
i
-
1
].
u
)
num_nodes
=
edges
[
i
-
1
].
u
;
if
(
num_nodes
<
edges
[
i
-
1
].
v
)
num_nodes
=
edges
[
i
-
1
].
u
;
}
}
}
}
num_nodes
++
;
///< Our first node is labeled 0, so we need to add 1 more
printf
(
"%d"
,
num_nodes
);
int
buffer_shmfd
=
create_shmfd
(
BUFF_SHM_NAME
);
/// Allocate resources for circular buffer
buffer_shmfd
=
create_shmfd
(
BUFF_SHM_NAME
);
circ_buffer
=
(
buffer_t
*
)
open_shm
(
buffer_shmfd
,
sizeof
(
buffer_t
));
circ_buffer
=
(
buffer_t
*
)
open_shm
(
buffer_shmfd
,
sizeof
(
buffer_t
));
int
wr_pos
=
0
;
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
fb_arc_set/shared/structs.c
View file @
8c423aaa
...
@@ -24,20 +24,22 @@ typedef struct buffer {
...
@@ -24,20 +24,22 @@ typedef struct buffer {
}
buffer_t
;
}
buffer_t
;
static
bool
terminate
=
false
;
static
bool
terminate
=
false
;
static
int
buffer_shmfd
;
static
buffer_t
*
circ_buffer
;
/**
/**
* @brief Function to execute when the program gets a signal
* @brief Function to execute when the program gets a signal
* @details
f
lips the terminate variable to true
* @details
F
lips the terminate variable to true
* @param
none
* @param
signo
* @return none
* @return none
**/
**/
static
void
signal_handler
()
{
static
void
signal_handler
(
int
signo
)
{
terminate
=
true
;
terminate
=
true
;
}
}
/**
/**
* @brief Function to process the signals passed by the user
* @brief Function to process the signals passed by the user
* @details
c
reates a new sigaction structure
* @details
C
reates a new sigaction structure
* and changes the behaviour of the SIGINT and SIGTERM signals
* and changes the behaviour of the SIGINT and SIGTERM signals
* @param none
* @param none
* @return none
* @return none
...
@@ -49,5 +51,3 @@ static void process_signal(void){
...
@@ -49,5 +51,3 @@ static void process_signal(void){
sigaction
(
SIGINT
,
&
sa
,
NULL
);
sigaction
(
SIGINT
,
&
sa
,
NULL
);
sigaction
(
SIGTERM
,
&
sa
,
NULL
);
sigaction
(
SIGTERM
,
&
sa
,
NULL
);
}
}
static
buffer_t
*
circ_buffer
;
fb_arc_set/supervisor.c
View file @
8c423aaa
...
@@ -25,16 +25,23 @@
...
@@ -25,16 +25,23 @@
#include "shared/sem.c"
#include "shared/sem.c"
#include "shared/structs.c"
#include "shared/structs.c"
void
clean_up
(
void
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
>
1
)
{
if
(
argc
>
1
)
{
fprintf
(
stderr
,
"ERROR: Command takes no arguments"
);
fprintf
(
stderr
,
"ERROR: Command takes no arguments"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
atexit
(
clean_up
)
!=
0
)
{
fprintf
(
stderr
,
"ERROR: Cannot set exit function
\n
"
);
exit
(
EXIT_FAILURE
);
}
process_signal
();
process_signal
();
/// Open shared memory objects
/// Open shared memory objects
int
buffer_shmfd
=
create_shmfd
(
BUFF_SHM_NAME
);
buffer_shmfd
=
create_shmfd
(
BUFF_SHM_NAME
);
truncate_shm
(
buffer_shmfd
,
BUFF_SIZE
);
truncate_shm
(
buffer_shmfd
,
BUFF_SIZE
);
circ_buffer
=
(
buffer_t
*
)
open_shm
(
buffer_shmfd
,
sizeof
(
buffer_t
));
circ_buffer
=
(
buffer_t
*
)
open_shm
(
buffer_shmfd
,
sizeof
(
buffer_t
));
...
@@ -71,7 +78,7 @@ int main(int argc, char *argv[]) {
...
@@ -71,7 +78,7 @@ int main(int argc, char *argv[]) {
if
(
fb_arc
.
edge_num
==
0
)
{
if
(
fb_arc
.
edge_num
==
0
)
{
/// If the graph is acyclic, set the terminate flag
/// If the graph is acyclic, set the terminate flag
puts
(
"The graph is acyclic!"
);
puts
(
"The graph is acyclic!"
);
signal_handler
();
signal_handler
(
SIGINT
);
}
else
if
(
fb_arc
.
edge_num
<
circ_buffer
->
best_arc_len
)
{
}
else
if
(
fb_arc
.
edge_num
<
circ_buffer
->
best_arc_len
)
{
/// Save ther best feedback arc length and print a solution
/// Save ther best feedback arc length and print a solution
circ_buffer
->
best_arc_len
=
fb_arc
.
edge_num
;
circ_buffer
->
best_arc_len
=
fb_arc
.
edge_num
;
...
@@ -83,7 +90,19 @@ int main(int argc, char *argv[]) {
...
@@ -83,7 +90,19 @@ int main(int argc, char *argv[]) {
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
}
}
exit
(
EXIT_SUCCESS
);
}
/**
* @brief Function to that cleans up the resources
* @details The function closes and destroys all semaphores,
* closes and destroys all shared memory objects and
* closes the file descriptors
* @param none
* @return none
**/
void
clean_up
(
void
)
{
/// Close and destory semaphores
/// Close and destory semaphores
close_sem
(
free_sem
);
close_sem
(
free_sem
);
close_sem
(
use_sem
);
close_sem
(
use_sem
);
...
@@ -96,5 +115,4 @@ int main(int argc, char *argv[]) {
...
@@ -96,5 +115,4 @@ int main(int argc, char *argv[]) {
/// Close and destroy shared memory objects
/// Close and destroy shared memory objects
close_shm
(
circ_buffer
,
sizeof
(
buffer_t
));
close_shm
(
circ_buffer
,
sizeof
(
buffer_t
));
destroy_shm
(
BUFF_SHM_NAME
,
buffer_shmfd
);
destroy_shm
(
BUFF_SHM_NAME
,
buffer_shmfd
);
exit
(
EXIT_SUCCESS
);
}
}
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