[spotify] Thread safety for the webapi access

The web api might be accessed from different threads (library, worker,
dacp), therefor protect from concurrently running refresh-token requests
(accessing the globals in spotify_webapi.c)
This commit is contained in:
chme
2017-12-22 07:47:15 +01:00
committed by ejurgensen
parent 997b4da4ad
commit 2da993cc7b
3 changed files with 66 additions and 25 deletions

View File

@@ -1967,9 +1967,10 @@ spotify_init(void)
CHECK_ERR(L_SPOTIFY, mutex_init(&login_lck));
CHECK_ERR(L_SPOTIFY, pthread_cond_init(&login_cond, NULL));
CHECK_ERR(L_SPOTIFY, mutex_init(&status_lck));
spotifywebapi_init();
/* Spawn thread */
ret = pthread_create(&tid_spotify, NULL, spotify, NULL);
if (ret < 0)
@@ -1988,6 +1989,8 @@ spotify_init(void)
return 0;
thread_fail:
spotifywebapi_deinit();
CHECK_ERR(L_SPOTIFY, pthread_mutex_destroy(&status_lck));
CHECK_ERR(L_SPOTIFY, pthread_cond_destroy(&login_cond));
CHECK_ERR(L_SPOTIFY, pthread_mutex_destroy(&login_lck));
@@ -2054,6 +2057,9 @@ spotify_deinit(void)
CHECK_ERR(L_SPOTIFY, pthread_cond_destroy(&login_cond));
CHECK_ERR(L_SPOTIFY, pthread_mutex_destroy(&login_lck));
/* Deinit web api */
spotifywebapi_deinit();
/* Free audio buffer */
evbuffer_free(spotify_audio_buffer);