blob: 6ce7a2a418e5b87082d9b428568693e118366bbf [file] [log] [blame]
Jiho Chang61bc1542012-03-24 05:52:01 +09001/*
2 * Copyright@ Samsung Electronics Co. LTD
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15*/
16
17/*!
18 * \file ExynosMutex.h
19 * \brief header file for ExynosMutex
20 * \author Sangwoo, Park(sw5771.park@samsung.com)
21 * \date 2011/06/15
22 *
23 * <b>Revision History: </b>
24 * - 2010/06/15 : Sangwoo, Park(sw5771.park@samsung.com) \n
25 * Initial version
26 *
27 */
28
Jiho Chang61bc1542012-03-24 05:52:01 +090029#ifndef __EXYNOS_MUTEX_H__
30#define __EXYNOS_MUTEX_H__
31
32#ifdef __cplusplus
33
34//! ExynosMutex
35/*!
36 * \ingroup Exynos
37 */
38class ExynosMutex
39{
40public:
41 enum TYPE {
42 TYPE_BASE = 0,
43 TYPE_PRIVATE, //!< within this process
44 TYPE_SHARED, //!< within whole system
45 TYPE_MAX,
46 };
47
Jiho Chang61bc1542012-03-24 05:52:01 +090048public:
Jiho Changc3e0af62012-04-26 13:52:52 -070049 //! Constructor.
50 ExynosMutex();
Jiho Chang61bc1542012-03-24 05:52:01 +090051
52 //! Destructor
53 virtual ~ExynosMutex();
54
Jiho Changc3e0af62012-04-26 13:52:52 -070055 //! Create Mutex
56 bool create(int type, char* name);
57
58 //! Destroy Mutex
59 void destroy(void);
60
61 //! Get Mutex created status
62 bool getCreatedStatus(void);
63
Jiho Chang61bc1542012-03-24 05:52:01 +090064 //! Lock Mutex
65 bool lock(void);
66
67 //! Unlock Mutex
68 bool unLock(void);
69
70 //! trylock Mutex
71 bool tryLock(void);
72
73 //! Get Mutex type
74 int getType(void);
75
Jiho Chang61bc1542012-03-24 05:52:01 +090076private:
77 void *m_mutex;
Jiho Changc3e0af62012-04-26 13:52:52 -070078 bool m_flagCreate;
Jiho Chang61bc1542012-03-24 05:52:01 +090079
80 int m_type;
81 char m_name[128];
82
83public:
84 //! Autolock
85 /*!
86 * \ingroup ExynosMutex
87 */
88 class Autolock {
89 public:
90 //! Lock on constructor
91 inline Autolock(ExynosMutex& mutex) : mLock(mutex) { mLock.lock(); }
92
93 //! Lock on constructor
94 inline Autolock(ExynosMutex* mutex) : mLock(*mutex) { mLock.lock(); }
95
96 //! Unlock on destructor
97 inline ~Autolock() { mLock.unLock(); }
98 private:
99 ExynosMutex& mLock;
100 };
101};
102
103extern "C" {
104#endif
105
106enum EXYNOS_MUTEX_TYPE {
107 EXYNOS_MUTEX_TYPE_BASE = 0,
108 EXYNOS_MUTEX_TYPE_PRIVATE, //!< within this process
109 EXYNOS_MUTEX_TYPE_SHARED, //!< within whole system
110 EXYNOS_MUTEX_TYPE_MAX,
111};
112
Jiho Chang61bc1542012-03-24 05:52:01 +0900113void *exynos_mutex_create(
114 int type,
115 char *name);
116
117bool exynos_mutex_destroy(
118 void *handle);
119
120bool exynos_mutex_lock(
121 void *handle);
122
123bool exynos_mutex_unlock(
124 void *handle);
125
126bool exynos_mutex_trylock(
127 void *handle);
128
129int exynos_mutex_type(
130 void *handle);
131
Jiho Changc3e0af62012-04-26 13:52:52 -0700132bool exynos_mutex_get_created_status(
Jiho Chang61bc1542012-03-24 05:52:01 +0900133 void *handle);
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif //__EXYNOS_MUTEX_H__