X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tizen%2FDEVICE%2Fsrc%2Ffile.c;h=eea51e86dc718ea8b9754ea0161d51d459e82f9b;hb=c0d35f453660d15646532d58a08dd1c1a3b0ca10;hp=40631667f48e953e7dc476cc66ebd2f6273d658f;hpb=b4159fdc374a1e85d08f316be752bba19af2ad8b;p=platform%2Fcore%2Fsystem%2Fhaptic-module-tizen.git diff --git a/tizen/DEVICE/src/file.c b/tizen/DEVICE/src/file.c index 4063166..eea51e8 100644 --- a/tizen/DEVICE/src/file.c +++ b/tizen/DEVICE/src/file.c @@ -55,7 +55,8 @@ typedef struct { static pthread_t tid; static BUFFER gbuffer; -static int lock; +static int stop; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static int _check_valid_haptic_format(HapticFile *file) { @@ -112,13 +113,16 @@ static int _cancel_thread(void) return 0; } - MODULE_LOG("lock state : %d", lock); - while (lock) { + MODULE_LOG("cancel thread!!!"); + + stop = 1; + + while (pthread_mutex_trylock(&mutex) == EBUSY) { usleep(100); - MODULE_LOG("already locked..."); + 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); @@ -148,6 +152,8 @@ static void __clean_up(void *arg) MODULE_LOG("clean up handler!!! : %d", tid); + stop = 0; + for (i = 0; i < pbuffer->channels; ++i) { free(pbuffer->ppbuffer[i]); pbuffer->ppbuffer[i] = NULL; @@ -175,13 +181,17 @@ static void* __play_cb(void *arg) 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) { - lock = 1; __haptic_predefine_action(pbuffer->handle, LEVEL, ch); - lock = 0; prev = ch; } + pthread_mutex_unlock(&mutex); usleep(BITPERMS * 1000); } }