-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadSafeWriter.h
More file actions
33 lines (31 loc) · 865 Bytes
/
ThreadSafeWriter.h
File metadata and controls
33 lines (31 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespace ua { namespace kiev { namespace ukma { namespace downloader {
/**
This class will be used to write messages in multi-threaded environment.
To achieve this purpose, we have private _lock variable, which is set to false in the constructor.
Of course, you should use the same ThreadSafeWriter object in every thread.
*/
class ThreadSafeWriter
{
public:
/**
Constructor
@param file File to write messages
*/
ThreadSafeWriter(fstream& file);
/**
Writes message to a file
@param s A message to write
*/
void write(const string s) const;
/**
Writes message to a file and ends with carriage return (endl, "\n")
@param s A message to write
*/
void writeln(const string& s = "") const;
private:
fstream& _file;
mutable bool _lock;
ThreadSafeWriter(const ThreadSafeWriter&);
ThreadSafeWriter& operator= (const ThreadSafeWriter&);
};
}}}}