• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
29 #ifndef __EXYNOS_MUTEX_H__
30 #define __EXYNOS_MUTEX_H__
31 
32 #ifdef __cplusplus
33 
34 //! ExynosMutex
35 /*!
36  * \ingroup Exynos
37  */
38 class ExynosMutex
39 {
40 public:
41     enum TYPE {
42         TYPE_BASE = 0,
43         TYPE_PRIVATE,  //!< within this process
44         TYPE_SHARED,   //!< within whole system
45         TYPE_MAX,
46     };
47 
48 public:
49     //! Constructor.
50     ExynosMutex();
51 
52     //! Destructor
53     virtual ~ExynosMutex();
54 
55     //! 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 
64     //! 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 
76 private:
77     void *m_mutex;
78     bool  m_flagCreate;
79 
80     int   m_type;
81     char  m_name[128];
82 
83 public:
84     //! Autolock
85     /*!
86      * \ingroup ExynosMutex
87      */
88     class Autolock {
89     public:
90         //! Lock on constructor
Autolock(ExynosMutex & mutex)91         inline Autolock(ExynosMutex& mutex) : mLock(mutex)  { mLock.lock(); }
92 
93         //! Lock on constructor
Autolock(ExynosMutex * mutex)94         inline Autolock(ExynosMutex* mutex) : mLock(*mutex) { mLock.lock(); }
95 
96         //! Unlock on destructor
~Autolock()97         inline ~Autolock() { mLock.unLock(); }
98     private:
99         ExynosMutex& mLock;
100     };
101 };
102 
103 extern "C" {
104 #endif
105 
106 enum 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 
113 void *exynos_mutex_create(
114     int   type,
115     char *name);
116 
117 bool exynos_mutex_destroy(
118     void *handle);
119 
120 bool exynos_mutex_lock(
121     void *handle);
122 
123 bool exynos_mutex_unlock(
124     void *handle);
125 
126 bool exynos_mutex_trylock(
127     void *handle);
128 
129 int exynos_mutex_type(
130     void *handle);
131 
132 bool exynos_mutex_get_created_status(
133     void *handle);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif //__EXYNOS_MUTEX_H__
140