From 8e3916f8ef7f29c7fc15250c8d3f5ac510988116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 2 Sep 2009 14:53:06 +0000 Subject: [PATCH] Extracted SemaphoreLocker into it's own file. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32904 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/installer/CopyEngine.cpp | 36 ++---------------------- src/apps/installer/CopyEngine.h | 3 +- src/apps/installer/SemaphoreLocker.h | 41 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 src/apps/installer/SemaphoreLocker.h diff --git a/src/apps/installer/CopyEngine.cpp b/src/apps/installer/CopyEngine.cpp index a3a014dbbb..db412e6bd3 100644 --- a/src/apps/installer/CopyEngine.cpp +++ b/src/apps/installer/CopyEngine.cpp @@ -19,46 +19,14 @@ #include #include -#include "AutoLocker.h" #include "InstallerWindow.h" // TODO: For PACKAGES_DIRECTORY and VAR_DIRECTORY, not so nice... +#include "SemaphoreLocker.h" + using std::nothrow; -// SemaphoreLocking -class SemaphoreLocking { -public: - inline bool Lock(sem_id* lockable) - { - return acquire_sem(*lockable) == B_OK; - } - - inline void Unlock(sem_id* lockable) - { - release_sem(*lockable); - } -}; - -// SemaphoreLocker -class SemaphoreLocker : public AutoLocker { -public: - inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false, - bool lockIfNotLocked = true) - : - AutoLocker(), - fSem(semaphore) - { - SetTo(&fSem, alreadyLocked, lockIfNotLocked); - } - -private: - sem_id fSem; -}; - - - - CopyEngine::CopyEngine(const BMessenger& messenger, BMessage* message) : fBufferQueue(), diff --git a/src/apps/installer/CopyEngine.h b/src/apps/installer/CopyEngine.h index 887b2b0a74..bda85ad7a4 100644 --- a/src/apps/installer/CopyEngine.h +++ b/src/apps/installer/CopyEngine.h @@ -18,6 +18,7 @@ class BFile; class BMessage; class BMessenger; + class CopyEngine { public: CopyEngine(const BMessenger& messenger, @@ -109,4 +110,4 @@ private: }; -#endif // COPY_ENGINE_2_H +#endif // COPY_ENGINE_H diff --git a/src/apps/installer/SemaphoreLocker.h b/src/apps/installer/SemaphoreLocker.h new file mode 100644 index 0000000000..a88a9feb30 --- /dev/null +++ b/src/apps/installer/SemaphoreLocker.h @@ -0,0 +1,41 @@ +/* + * Copyright 2008-2009, Stephan Aßmus + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _SEMAPHORE_LOCKER_H +#define _SEMAPHORE_LOCKER_H + + +#include "AutoLocker.h" + + +class SemaphoreLocking { +public: + inline bool Lock(sem_id* lockable) + { + return acquire_sem(*lockable) == B_OK; + } + + inline void Unlock(sem_id* lockable) + { + release_sem(*lockable); + } +}; + + +class SemaphoreLocker : public AutoLocker { +public: + inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false, + bool lockIfNotLocked = true) + : + AutoLocker(), + fSem(semaphore) + { + SetTo(&fSem, alreadyLocked, lockIfNotLocked); + } + +private: + sem_id fSem; +}; + +#endif // _SEMAPHORE_LOCKER_H