-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4083a1
commit 5353ed2
Showing
4 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Utility functions | ||
#ifndef UTILS_H | ||
#define UTILS_H | ||
|
||
/// @cond | ||
#include <string> | ||
/// @endcond | ||
|
||
// Print a message to stdout in a thread-safe manner | ||
void printMessage(std::string message); | ||
|
||
// Print an error message to stderr in a thread-safe manner | ||
void printError(std::string message); | ||
|
||
#endif // UTILS_H |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "utils.h" | ||
|
||
/// @cond | ||
#include <stdio.h> | ||
#include <string> | ||
#include <iostream> | ||
#include <mutex> | ||
/// @endcond | ||
|
||
|
||
// Define print mutex | ||
std::mutex print_mtx; | ||
|
||
// Thread-safe print message function | ||
void printMessage(std::string message) | ||
{ | ||
std::lock_guard<std::mutex> lock(print_mtx); | ||
std::cout << message << std::endl; | ||
} | ||
|
||
// Thread-safe print error function | ||
void printError(std::string message) | ||
{ | ||
std::lock_guard<std::mutex> lock(print_mtx); | ||
std::cerr << message << std::endl; | ||
} |