#define API __attribute__ ((visibility("default")))
#endif
-static bool binit;
+static unsigned int init_cnt;
+static pthread_mutex_t fmutex = PTHREAD_MUTEX_INITIALIZER;
API int feedback_initialize(void)
{
- if (binit)
- return FEEDBACK_ERROR_NONE;
-
+ pthread_mutex_lock(&fmutex);
if (!profile) {
_E("there is no valid profile module.");
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NOT_SUPPORTED;
}
+ if (init_cnt++ > 0) {
+ pthread_mutex_unlock(&fmutex);
+ return FEEDBACK_ERROR_NONE;
+ }
+
/* initialize device */
devices_init();
if (profile->init)
profile->init();
- binit = true;
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NONE;
}
API int feedback_deinitialize(void)
{
- if (!binit)
+ pthread_mutex_lock(&fmutex);
+ if (!init_cnt) {
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NOT_INITIALIZED;
+ }
+
+ if (init_cnt-- > 1) {
+ pthread_mutex_unlock(&fmutex);
+ return FEEDBACK_ERROR_NONE;
+ }
/* deinitialize device */
devices_exit();
if (profile->exit)
profile->exit();
- binit = false;
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NONE;
}
int switched;
/* check initialize */
- if (!binit) {
+ pthread_mutex_lock(&fmutex);
+ if (!init_cnt) {
_E("Not initialized");
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NOT_INITIALIZED;
}
+ pthread_mutex_unlock(&fmutex);
if (pattern <= FEEDBACK_PATTERN_NONE ||
pattern >= profile->max_pattern) {
int switched;
/* check initialize */
- if (!binit) {
+ pthread_mutex_lock(&fmutex);
+ if (!init_cnt) {
_E("Not initialized");
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NOT_INITIALIZED;
}
+ pthread_mutex_unlock(&fmutex);
if (type <= FEEDBACK_TYPE_NONE ||
type >= profile->max_type) {
int err;
/* check initialize */
- if (!binit) {
+ pthread_mutex_lock(&fmutex);
+ if (!init_cnt) {
_E("Not initialized");
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NOT_INITIALIZED;
}
+ pthread_mutex_unlock(&fmutex);
/* stop all device */
err = devices_stop();
int switched;
/* check initialize */
- if (!binit) {
+ pthread_mutex_lock(&fmutex);
+ if (!init_cnt) {
_E("Not initialized");
+ pthread_mutex_unlock(&fmutex);
return FEEDBACK_ERROR_NOT_INITIALIZED;
}
+ pthread_mutex_unlock(&fmutex);
if (!status) {
_E("Invalid parameter : status(NULL)");