This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstring> | |
| #include <iostream> | |
| #include <sys/wait.h> | |
| #include <unistd.h> | |
| int main(int argc, char *argv[], char *envp[]) { | |
| int p_fds[2]; | |
| if (pipe(p_fds) == -1) { | |
| std::cerr << "Error: pipe() - " << strerror(errno) << std::endl; | |
| exit(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstring> | |
| #include <iostream> | |
| #include <sys/wait.h> | |
| #include <unistd.h> | |
| int main(int argc, char *argv[], char *envp[]) { | |
| int p_fds[2]; | |
| if (pipe(p_fds) == -1) { | |
| std::cerr << "Error: pipe() - " << strerror(errno) << std::endl; | |
| exit(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstring> | |
| #include <iostream> | |
| #include <sys/wait.h> | |
| #include <unistd.h> | |
| #define BUF_SIZE 10 | |
| int main(int argc, char *argv[]) { | |
| int p_fds[2]; | |
| if (pipe(p_fds) == -1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| bool SortedList<T>::exists(T elem) | |
| { | |
| NodeListWithLock<T> *prev = this->_head; | |
| prev->lock_node(); | |
| NodeListWithLock<T> *curr = prev->_next; | |
| while (curr != nullptr && | |
| curr->data() < elem) { | |
| curr->lock_node(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| bool SortedList<T>::remove(T elem) | |
| { | |
| NodeListWithLock<T> *prev = this->_head; | |
| prev->lock_node(); | |
| NodeListWithLock<T> *curr = prev->_next; | |
| while (curr != nullptr && | |
| curr->data() < elem) { | |
| curr->lock_node(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| bool SortedList<T>::add(T elem) | |
| { | |
| NodeListWithLock<T> *prev = this->_head; | |
| prev->lock_node(); | |
| NodeListWithLock<T> *curr = prev->_next; | |
| while(curr != nullptr && | |
| curr->data() < elem) { | |
| curr->lock_node(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| class SortedList : public Set<T> | |
| { | |
| private: | |
| NodeListWithLock<T> *_head; | |
| public: | |
| SortedList(); | |
| ~SortedList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| class NodeListWithLock | |
| { | |
| private: | |
| T _data; | |
| std::mutex _mux; | |
| public: | |
| NodeListWithLock<T> _next; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| bool List<T>::remove_if_exists(T elem) | |
| { | |
| // Empty list | |
| if (this->empty()) { | |
| return false; | |
| } | |
| // Need to remove the head element | |
| if (this->_head->data() == elem) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FileObject { | |
| private: | |
| FILE *_fp; | |
| public: | |
| FileObject(const std::string &file_name, const std::string &mode); | |
| ~FileObject(); | |
| // Copy/Assignment according to your usecase |
NewerOlder