X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fbase.cpp;h=9c2b40a1f2a9460eee16a34f6e0b08aab245786c;hp=052d464becb6f793cb774c32e38c4fa40e686721;hb=292aed8e23ea543b089d5f2a73000de4640befe7;hpb=5b541316a8c7bbf8b812c0f1e2dbebaa6563b0ee diff --git a/source/io/base.cpp b/source/io/base.cpp index 052d464..9c2b40a 100644 --- a/source/io/base.cpp +++ b/source/io/base.cpp @@ -8,12 +8,14 @@ namespace IO { Base::Base(): mode(M_READ), - eof_flag(false) + eof_flag(false), + mutex(0) { } Base::~Base() { signal_deleted.emit(); + delete mutex; } void Base::check_access(Mode m) const @@ -29,7 +31,7 @@ bool Base::getline(string &line) if(eof_flag) return false; - while(1) + while(!eof()) { int c = get(); if(c==-1 || c=='\n') @@ -57,9 +59,18 @@ void Base::set_eof() } } -const Handle &Base::get_handle(Mode) + +Base::Synchronize::Synchronize(Base &i): + io(i) +{ + if(!io.mutex) + io.mutex = new Mutex; + io.mutex->lock(); +} + +Base::Synchronize::~Synchronize() { - throw logic_error("Base::get_handle"); + io.mutex->unlock(); } } // namespace IO