]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/base.cpp
Synchronize access to the underlying object of Slice
[libs/core.git] / source / io / base.cpp
index 052d464becb6f793cb774c32e38c4fa40e686721..da2b5a98cb1c8db3f211b292137783b0c19d4e7d 100644 (file)
@@ -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
@@ -62,5 +64,19 @@ 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