Skip to content

Commit

Permalink
Added fork data struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Herrera committed Oct 1, 2021
1 parent 298bcd3 commit 1c15a71
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Dining Philosophers Problem [![license](https://img.shields.io/github/license/herrera-diego/dining-philosophers)](./LICENSE)
# Dining Philosophers Problem [![license](https://img.shields.io/github/license/herrera-diego/dining-philosophers)](./LICENSE) [![Makefile CI](https://github.com/herrera-diego/dining-philosophers/actions/workflows/makefile.yml/badge.svg?branch=main)](https://github.com/herrera-diego/dining-philosophers/actions/workflows/makefile.yml)


Implementation on Dining Philosophers problem on C++

Expand Down
14 changes: 14 additions & 0 deletions code/src/waiting-state/fork.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "fork.h"

using namespace WaitingPhilosopher;

Fork::Fork()
{

}

bool Fork::isBeingUsed()
{
return IsUsed;
}

26 changes: 26 additions & 0 deletions code/src/waiting-state/fork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef FORK_H_
#define FORK_H_

// #ifdef __cplusplus
// extern "C" {
// #endif
#include <string>

namespace WaitingPhilosopher
{
class Fork
{
public:
Fork();
bool isBeingUsed();
protected:
bool IsUsed = true;



};
}

#endif /* FORK_H_ */

// EOF
7 changes: 2 additions & 5 deletions code/src/waiting-state/philosopher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ Philosopher::Philosopher()

}

bool Philosopher::checkNeighbor()
{
bool neighborBusy = true;

return neighborBusy;
void Philosopher::think()
{
}

void Philosopher::wait()
Expand Down
2 changes: 1 addition & 1 deletion code/src/waiting-state/philosopher.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace WaitingPhilosopher
{
public:
Philosopher();
bool checkNeighbor();
void think();
void wait();
void eat();
protected:
Expand Down
7 changes: 5 additions & 2 deletions code/unittest/test-waiting-state.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gtest/gtest.h"
#include <string>
#include "waiting-state/philosopher.h"
#include "waiting-state/fork.h"

using namespace WaitingPhilosopher;
using namespace std;
Expand Down Expand Up @@ -32,8 +33,10 @@ class WaitingPhilosopherTest : public testing::Test

TEST_F(WaitingPhilosopherTest, evenPhilosophers)
{
Philosopher nietzche;
ASSERT_TRUE(nietzche.checkNeighbor());
int numPh = 6;
Philosopher phs[numPh];
Fork forks[numPh*2 -1];
ASSERT_TRUE(forks[0].isBeingUsed());


}
Expand Down

0 comments on commit 1c15a71

Please sign in to comment.