Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
L
lepl1503-2020-groupe-C1
Gestion
Activité
Membres
Code
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Déploiement
Releases
Registre de conteneur
Registre de modèles
Analyse
Analyse des contributeurs
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Corentin Lengelé
lepl1503-2020-groupe-C1
Validations
ffcca1e2
Valider
ffcca1e2
rédigé
5 years ago
par
Hugo Clercq
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
cppcheck fixes
parent
b70d7d27
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
functions.c
+8
-9
8 ajouts, 9 suppressions
functions.c
main.c
+9
-13
9 ajouts, 13 suppressions
main.c
avec
17 ajouts
et
22 suppressions
functions.c
+
8
−
9
Voir le fichier @
ffcca1e2
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
...
@@ -77,6 +79,7 @@ queue_t* new_queue(){
...
@@ -77,6 +79,7 @@ queue_t* new_queue(){
if
(
result
->
buffer
==
NULL
){
// Test malloc failure
if
(
result
->
buffer
==
NULL
){
// Test malloc failure
printf
(
"Malloc failed in newArray() for result->first"
);
printf
(
"Malloc failed in newArray() for result->first"
);
free
(
result
);
return
NULL
;
// Malloc fail
return
NULL
;
// Malloc fail
}
}
...
@@ -126,6 +129,7 @@ div_queue_t* new_div_queue(){
...
@@ -126,6 +129,7 @@ div_queue_t* new_div_queue(){
if
(
result
->
buffer
==
NULL
){
// Test malloc failure
if
(
result
->
buffer
==
NULL
){
// Test malloc failure
printf
(
"Malloc failed in newArray() for result->first"
);
printf
(
"Malloc failed in newArray() for result->first"
);
free
(
result
);
return
NULL
;
// Malloc fail
return
NULL
;
// Malloc fail
}
}
...
@@ -158,17 +162,13 @@ void div_free_queue(div_queue_t *queue){//Free a queue
...
@@ -158,17 +162,13 @@ void div_free_queue(div_queue_t *queue){//Free a queue
//Print help for option -h or --help
//Print help for option -h or --help
void
printHelp
(){
void
printHelp
(){
printf
(
"Usage: ./prime_divs [OPTION...]
\n
"
printf
(
"Usage: ./prime_divs [OPTION...]
input_file output_file
\n
"
"
\t
-v, --verbose
\t
print debug
\n
"
"
\t
-v, --verbose
\t
print debug
\n
"
"
\t
-q
\t\t
do not print debug
\n
"
"
\t
-N
\t\t
specify number of threads
\n
"
);
"
\t
-r
\t\t
specify input file
\n
"
"
\t
-r
\t\t
specify output file
\n
"
"
\t
-N
\t\t
specify number of threads"
);
}
}
// Return number modulo i
// Return number modulo i
int
is_div
(
long
long
number
,
long
long
i
){
int
is_div
(
long
long
number
,
long
long
i
){
//if (number == i) return false;
return
(
number
%
i
)
==
0
;
return
(
number
%
i
)
==
0
;
}
}
...
@@ -244,14 +244,13 @@ void* produce(){
...
@@ -244,14 +244,13 @@ void* produce(){
char
*
line
=
NULL
;
char
*
line
=
NULL
;
size_t
len
=
0
;
size_t
len
=
0
;
ssize_t
read
;
char
*
eptr
;
char
*
eptr
;
while
(
(
read
=
getline
(
&
line
,
&
len
,
fdIn
)
)
!=
-
1
){
while
(
getline
(
&
line
,
&
len
,
fdIn
)
!=
-
1
){
long
long
number
=
strtoll
(
line
,
&
eptr
,
10
);
long
long
number
=
strtoll
(
line
,
&
eptr
,
10
);
if
(
number
==
0
){
if
(
number
==
0
){
printf
(
"Conversion error string to ll
\n
"
);
printf
(
"Conversion error string to ll
\n
"
);
}
}
printf
(
"%lld
\n
"
,
number
);
//
printf("%lld \n", number);
if
(
number
<
2
){
if
(
number
<
2
){
printf
(
"Error number < 2 in file
\n
"
);
printf
(
"Error number < 2 in file
\n
"
);
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
main.c
+
9
−
13
Voir le fichier @
ffcca1e2
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
int
main
(
int
argc
,
char
**
argv
){
int
main
(
int
argc
,
char
**
argv
){
Args
.
nThreads
=
8
;
//default number of threads
Args
.
nThreads
=
8
;
//default number of threads
const
char
*
strOpts
=
"h
qvr:w:
N:"
;
const
char
*
strOpts
=
"h
v
N:"
;
const
struct
option
longOpts
[]
=
{
const
struct
option
longOpts
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"verbose"
,
no_argument
,
NULL
,
'v'
}
{
"verbose"
,
no_argument
,
NULL
,
'v'
}
...
@@ -20,23 +20,16 @@ int main(int argc, char** argv){
...
@@ -20,23 +20,16 @@ int main(int argc, char** argv){
case
'h'
:
case
'h'
:
printHelp
();
printHelp
();
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
case
'q'
:
Args
.
verbose
=
0
;
break
;
case
'v'
:
case
'v'
:
Args
.
verbose
=
1
;
Args
.
verbose
=
1
;
break
;
break
;
case
'r'
:
Args
.
input_file
=
optarg
;
break
;
case
'w'
:
Args
.
output_file
=
optarg
;
break
;
case
'N'
:
case
'N'
:
Args
.
nThreads
=
atoi
(
optarg
);
Args
.
nThreads
=
atoi
(
optarg
);
break
;
break
;
}
}
}
}
Args
.
input_file
=
argv
[
argc
-
2
];
Args
.
output_file
=
argv
[
argc
-
1
];
FILE
*
LineCounter
=
fopen
(
Args
.
input_file
,
"r"
);
FILE
*
LineCounter
=
fopen
(
Args
.
input_file
,
"r"
);
if
(
LineCounter
==
NULL
){
if
(
LineCounter
==
NULL
){
...
@@ -46,7 +39,6 @@ int main(int argc, char** argv){
...
@@ -46,7 +39,6 @@ int main(int argc, char** argv){
counter
=
0
;
counter
=
0
;
char
*
line
=
NULL
;
char
*
line
=
NULL
;
size_t
len
=
0
;
size_t
len
=
0
;
char
*
eptr
;
while
(
getline
(
&
line
,
&
len
,
LineCounter
)
!=-
1
){
while
(
getline
(
&
line
,
&
len
,
LineCounter
)
!=-
1
){
counter
++
;
counter
++
;
}
}
...
@@ -61,12 +53,12 @@ int main(int argc, char** argv){
...
@@ -61,12 +53,12 @@ int main(int argc, char** argv){
done2
=
Args
.
nThreads
;
done2
=
Args
.
nThreads
;
buffer
=
new_queue
(
1
);
buffer
=
new_queue
();
pthread_mutex_init
(
&
mutex
,
NULL
);
pthread_mutex_init
(
&
mutex
,
NULL
);
sem_init
(
&
empty
,
0
,(
2
*
Args
.
nThreads
)
+
1
);
sem_init
(
&
empty
,
0
,(
2
*
Args
.
nThreads
)
+
1
);
sem_init
(
&
full
,
0
,
0
);
sem_init
(
&
full
,
0
,
0
);
buffer2
=
new_div_queue
(
0
);
buffer2
=
new_div_queue
();
pthread_mutex_init
(
&
mutex2
,
NULL
);
pthread_mutex_init
(
&
mutex2
,
NULL
);
sem_init
(
&
empty2
,
0
,(
2
*
Args
.
nThreads
)
+
1
);
sem_init
(
&
empty2
,
0
,(
2
*
Args
.
nThreads
)
+
1
);
sem_init
(
&
full2
,
0
,
0
);
sem_init
(
&
full2
,
0
,
0
);
...
@@ -76,6 +68,10 @@ int main(int argc, char** argv){
...
@@ -76,6 +68,10 @@ int main(int argc, char** argv){
pthread_t
writer
;
pthread_t
writer
;
//pthread_t threads[Args.nThreads];
//pthread_t threads[Args.nThreads];
threads
=
malloc
(
sizeof
(
pthread_t
)
*
Args
.
nThreads
);
threads
=
malloc
(
sizeof
(
pthread_t
)
*
Args
.
nThreads
);
if
(
threads
==
NULL
){
printf
(
"Malloc error for threads in main
\n
"
);
return
EXIT_FAILURE
;
}
finished
=
0
;
finished
=
0
;
if
(
pthread_create
(
&
reader
,
NULL
,
&
produce
,
NULL
)
!=
0
){
if
(
pthread_create
(
&
reader
,
NULL
,
&
produce
,
NULL
)
!=
0
){
printf
(
"Error while creating the reader thread
\n
"
);
printf
(
"Error while creating the reader thread
\n
"
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter