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>
40 Semaphore *m_semaphore;
43 explicit ScopedLock(Semaphore *semaphore);
50 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
51 DECLARE_EXCEPTION_TYPE(Base, CreateFailed)
52 DECLARE_EXCEPTION_TYPE(Base, LockFailed)
53 DECLARE_EXCEPTION_TYPE(Base, UnlockFailed)
54 DECLARE_EXCEPTION_TYPE(Base, RemoveFailed)
81 sem_t *InternalGet() const;
82 void InternalDestroy();
89 * Remove a named semaphore
91 * @param fileName Name of the semaphore
93 static void Remove(const std::string &fileName);
96 * Open an unnamed semaphore
98 * @param maxLockCount Maximum number of threads allowed to enter semaphore
100 explicit Semaphore(size_t maxLockCount);
103 * Open a named semaphore
105 * @param fileName Semaphore filename
106 * @param allowCreate Should non-existing semaphore be created
107 * @param maxLockCount Maximum number of threads allowed to enter semaphore
108 * @param permissions Semaphore file permissions
109 * @param unlinkOnDestroy Should semaphore file be deleted on destruction
111 explicit Semaphore(const std::string &fileName,
112 bool allowCreate = true,
113 bool exclusiveCreate = false,
114 size_t maxLockCount = 1,
115 int permissions = 0600,
116 bool unlinkOnDestroy = false);
119 * Destroy a semaphore
125 #endif // DPL_SEMAPHORE_H