static pthread_t tid;
static BUFFER gbuffer;
+static int stop;
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int _check_valid_haptic_format(HapticFile *file)
{
return 0;
}
+ MODULE_LOG("cancel thread!!!");
+
+ stop = 1;
+
+ while (pthread_mutex_trylock(&mutex) == EBUSY) {
+ usleep(100);
+ MODULE_LOG("Already locked..");
+ }
__haptic_predefine_action(gbuffer.handle, STOP, NULL);
+ pthread_mutex_unlock(&mutex);
if ((ret = pthread_cancel(tid)) < 0) {
MODULE_ERROR("pthread_cancel is failed : %s, ret(%d)", strerror(errno), ret);
MODULE_LOG("clean up handler!!! : %d", tid);
+ stop = 0;
+
for (i = 0; i < pbuffer->channels; ++i) {
free(pbuffer->ppbuffer[i]);
pbuffer->ppbuffer[i] = NULL;
for (i = 0; i < pbuffer->iteration; i++) {
for (j = 0; j < pbuffer->length; ++j) {
for (k = 0; k < pbuffer->channels; ++k) {
+ pthread_mutex_lock(&mutex);
+ if (stop) {
+ pthread_mutex_unlock(&mutex);
+ pthread_exit((void*)0);
+ }
ch = pbuffer->ppbuffer[k][j];
if (ch != prev) {
__haptic_predefine_action(pbuffer->handle, LEVEL, ch);
prev = ch;
}
+ pthread_mutex_unlock(&mutex);
usleep(BITPERMS * 1000);
}
}