X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fbase.cpp;h=95a3685fc34021322b800e185e7a52c9343d8521;hp=bf4c82018dc60d9a6d4ddd18be350468f9a4c0a0;hb=bd892a8afd93f849aec21706a009f69a5868b34d;hpb=82d74297d5b469b0a506d7010a84ab5115cd88ee diff --git a/source/io/base.cpp b/source/io/base.cpp index bf4c820..95a3685 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,5 +59,24 @@ void Base::set_eof() } } +const Handle &Base::get_handle(Mode) +{ + throw logic_error("Base::get_handle"); +} + + +Base::Synchronize::Synchronize(Base &i): + io(i) +{ + if(!io.mutex) + io.mutex = new Mutex; + io.mutex->lock(); +} + +Base::Synchronize::~Synchronize() +{ + io.mutex->unlock(); +} + } // namespace IO } // namespace Msp