From 72013046fcc182298aac76db97317cdb17bb5da4 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 11 Sep 2012 23:46:00 +0000 Subject: [PATCH] added: Lock class -- locking resources by using Synchro object the destructor automatically calls Unlock() git-svn-id: svn://ttmath.org/publicrep/winix/trunk@886 e52654a7-88a9-db11-a3e9-0013d4bc506e --- core/Makefile.dep | 1 + core/Makefile.o.dep | 2 +- core/lock.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++ core/lock.h | 37 ++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100755 core/lock.cpp create mode 100755 core/lock.h diff --git a/core/Makefile.dep b/core/Makefile.dep index 9249468..b8771e4 100755 --- a/core/Makefile.dep +++ b/core/Makefile.dep @@ -310,6 +310,7 @@ loadavg.o: ../templates/htmltextstream.h ../core/textstream.h misc.h loadavg.o: ../../pikotools/utf8/utf8.h ../../pikotools/space/spacetojson.h loadavg.o: session.h user.h plugindata.h rebus.h mount.h loadavg.o: ../templates/locale.h +lock.o: lock.h synchro.h log.o: log.h textstream.h logmanipulators.h log.o: ../../pikotools/textstream/textstream.h ../../pikotools/space/space.h log.o: ../../pikotools/date/date.h ../../pikotools/convert/convert.h diff --git a/core/Makefile.o.dep b/core/Makefile.o.dep index 025d321..90286e2 100755 --- a/core/Makefile.o.dep +++ b/core/Makefile.o.dep @@ -1 +1 @@ -o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o image.o item.o job.o lastcontainer.o loadavg.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o +o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o groups.o htmlfilter.o httpsimpleparser.o image.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o diff --git a/core/lock.cpp b/core/lock.cpp new file mode 100755 index 0000000..70dfa7a --- /dev/null +++ b/core/lock.cpp @@ -0,0 +1,49 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2012, Tomasz Sowa + * All rights reserved. + * + */ + +#include "lock.h" + + + +Lock::Lock() +{ + synchro = 0; +} + + +Lock::Lock(Synchro * synchro_) +{ + synchro = synchro_; + synchro->Lock(); +} + + +Lock::Lock(Synchro & synchro_) +{ + synchro = &synchro_; + synchro->Lock(); +} + + +Lock::~Lock() +{ + Unlock(); +} + + +void Lock::Unlock() +{ + if( synchro ) + { + synchro->Unlock(); + synchro = 0; + } +} + + diff --git a/core/lock.h b/core/lock.h new file mode 100755 index 0000000..c72c5b2 --- /dev/null +++ b/core/lock.h @@ -0,0 +1,37 @@ +/* + * This file is a part of Winix + * and is not publicly distributed + * + * Copyright (c) 2012, Tomasz Sowa + * All rights reserved. + * + */ + +#ifndef headerfile_winix_core_lock +#define headerfile_winix_core_lock + +#include "synchro.h" + + +class Lock +{ +public: + + Lock(Synchro * synchro_); + Lock(Synchro & synchro_); + + ~Lock(); + + void Unlock(); + + +private: + + Synchro * synchro; + + Lock(); + +}; + + +#endif