2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of semaphore
22 #ifndef DPL_SEMAPHORE_H
23 #define DPL_SEMAPHORE_H
25 #include <dpl/noncopyable.h>
26 #include <dpl/exception.h>
27 #include <semaphore.h>
39 Semaphore *m_semaphore;
42 explicit ScopedLock(Semaphore *semaphore);
49 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
50 DECLARE_EXCEPTION_TYPE(Base, CreateFailed)
51 DECLARE_EXCEPTION_TYPE(Base, LockFailed)
52 DECLARE_EXCEPTION_TYPE(Base, UnlockFailed)
53 DECLARE_EXCEPTION_TYPE(Base, RemoveFailed)
80 sem_t *InternalGet() const;
81 void InternalDestroy();
85 * decrement the semaphore counter
90 * increment the semaphore counter
95 * Remove a named semaphore
97 * @param fileName Name of the semaphore
99 static void Remove(const std::string &fileName);
102 * Open an unnamed semaphore
104 * @param maxLockCount Maximum number of threads allowed to enter semaphore
106 explicit Semaphore(size_t maxLockCount);
109 * Open a named semaphore
111 * @param fileName Semaphore filename
112 * @param allowCreate Should non-existing semaphore be created
113 * @param maxLockCount Maximum number of threads allowed to enter semaphore
114 * @param permissions Semaphore file permissions
115 * @param unlinkOnDestroy Should semaphore file be deleted on destruction
117 explicit Semaphore(const std::string &fileName,
118 bool allowCreate = true,
119 bool exclusiveCreate = false,
120 size_t maxLockCount = 1,
121 int permissions = 0600,
122 bool unlinkOnDestroy = false);
125 * Destroy a semaphore
131 #endif // DPL_SEMAPHORE_H