diff options
author | liang121.sun <liang121.sun@samsung.com> | 2013-05-07 17:46:55 +0800 |
---|---|---|
committer | Seungbae Shin <seungbae.shin@samsung.com> | 2013-05-14 16:46:55 +0900 |
commit | 2947cebaf7d70c92fe427972d65b2b616e5711d3 (patch) | |
tree | b7d76c9cfa86ec706b10e057ac30cae98803f2d5 /avsys-audio-handle.c | |
parent | b113fa7bf18865a1cd296da58c6e456536080388 (diff) | |
download | avsystem-2947cebaf7d70c92fe427972d65b2b616e5711d3.tar.gz avsystem-2947cebaf7d70c92fe427972d65b2b616e5711d3.tar.bz2 avsystem-2947cebaf7d70c92fe427972d65b2b616e5711d3.zip |
[Merge] Fix race condition issue.submit/tizen_2.1/20130515.030444submit/tizen/20130517.044954accepted/tizen/20130520.101107tizen_2.1
Change-Id: Icce57d8413d081194a150f3dc3205f610392675d
Diffstat (limited to 'avsys-audio-handle.c')
-rw-r--r-- | avsys-audio-handle.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/avsys-audio-handle.c b/avsys-audio-handle.c index 8eca6b3..1232c92 100644 --- a/avsys-audio-handle.c +++ b/avsys-audio-handle.c @@ -439,6 +439,39 @@ int avsys_audio_handle_alloc(int *handle) } } +int avsys_audio_handle_alloc_unlocked(int *handle) +{ + long long int flag = 0x01; + int i; + avsys_audio_handle_info_t *control = NULL; + avsys_audio_handle_info_t **temp = NULL; + temp = &control; + + avsys_info(AVAUDIO, "%s\n", __func__); + AVSYS_GET_SHM(temp,AVSYS_STATE_ERR_INTERNAL); + + for (i = 0; i < AVSYS_AUDIO_HANDLE_MAX; i++) { + if ((control->allocated & flag) == 0) { /* alloc condition */ + control->allocated |= flag; + break; + } else { + flag <<= 1; + } + } + + if (i == AVSYS_AUDIO_HANDLE_MAX) { + *handle = -1; + return AVSYS_STATE_ERR_RANGE_OVER; + } else { + avsys_info(AVAUDIO, "handle allocated %d\n", i); + memset(&control->handles[i], 0, sizeof(avsys_audio_handle_t)); + control->handles[i].pid = getpid(); + control->handles[i].tid = avsys_gettid(); + *handle = i; + return AVSYS_STATE_SUCCESS; + } +} + int avsys_audio_handle_free(int handle) { long long int flag = 0x01; @@ -523,6 +556,43 @@ int avsys_audio_handle_get_ptr(int handle, avsys_audio_handle_t **ptr, const int return ret; } +int avsys_audio_handle_get_ptr_unlocked(int handle, avsys_audio_handle_t **ptr, const int mode) +{ + long long int flag = 0x01; + avsys_audio_handle_info_t *control = NULL; + avsys_audio_handle_info_t **temp = NULL; + int ret = AVSYS_STATE_SUCCESS; + + if (handle < 0 || handle >= AVSYS_AUDIO_HANDLE_MAX) { + *ptr = NULL; + return AVSYS_STATE_ERR_INVALID_HANDLE; + } + + if (mode < 0 || mode >= HANDLE_PTR_MODE_NUM) { + *ptr = NULL; + return AVSYS_STATE_ERR_INVALID_PARAMETER; + } + + temp = &control; + if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, (void **)temp))) { + avsys_error(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__); + *ptr = NULL; + return AVSYS_STATE_ERR_INTERNAL; + } + + flag <<= handle; + + if (control->allocated & flag) { + *ptr = &(control->handles[handle]); + ret = AVSYS_STATE_SUCCESS; + } else { + *ptr = NULL; + ret = AVSYS_STATE_ERR_INVALID_VALUE; + } + + return ret; +} + int avsys_audio_handle_release_ptr(int handle, const int mode) { long long int flag = 0x01; |