summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllen Winter <allen.winter@kdab.com>2018-01-27 12:01:52 -0500
committerAllen Winter <allen.winter@kdab.com>2018-01-27 12:01:52 -0500
commit4cee1aca2034c0c9895bbbeddd1ab12ec48fd02f (patch)
tree43ce85520ddab214f619b2eef2bfa2c850cf8642
parentd9244fa3dce4ab337a9559c9b29bb62c92bf6758 (diff)
downloadlibical-git-fixthreading.tar.gz
src/libical/icaltimezone.c - fix threading problems on BSD-type systemsfixthreading
-rw-r--r--src/libical/icaltimezone.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/src/libical/icaltimezone.c b/src/libical/icaltimezone.c
index 070b1252..81e1cbaf 100644
--- a/src/libical/icaltimezone.c
+++ b/src/libical/icaltimezone.c
@@ -281,10 +281,7 @@ static void icaltimezone_init(icaltimezone *zone)
zone->component = NULL;
zone->builtin_timezone = NULL;
zone->end_year = 0;
-
- icaltimezone_changes_lock();
zone->changes = NULL;
- icaltimezone_changes_unlock();
}
/** Gets the TZID, LOCATION/X-LIC-LOCATION and TZNAME properties of
@@ -468,32 +465,19 @@ char *icaltimezone_get_tznames_from_vtimezone(icalcomponent *component)
static void icaltimezone_ensure_coverage(icaltimezone *zone, int end_year)
{
-#if defined(HAVE_PTHREAD)
- /* Avoid data race in multithreaded when accessing icaltimezone_minimum_expansion_year */
- static pthread_mutex_t year_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
/* When we expand timezone changes we always expand at least up to this
year, plus ICALTIMEZONE_EXTRA_COVERAGE. */
static int icaltimezone_minimum_expansion_year = -1;
int changes_end_year;
- icaltimezone_builtin_lock();
icaltimezone_load_builtin_timezone(zone);
- icaltimezone_builtin_unlock();
-#if defined(HAVE_PTHREAD)
- pthread_mutex_lock(&year_mutex);
-#endif
if (icaltimezone_minimum_expansion_year == -1) {
struct icaltimetype today = icaltime_today();
icaltimezone_minimum_expansion_year = today.year;
}
-#if defined(HAVE_PTHREAD)
- pthread_mutex_unlock(&year_mutex);
-#endif
changes_end_year = end_year;
if (changes_end_year < icaltimezone_minimum_expansion_year)
@@ -501,15 +485,11 @@ static void icaltimezone_ensure_coverage(icaltimezone *zone, int end_year)
changes_end_year += ICALTIMEZONE_EXTRA_COVERAGE;
- icaltimezone_changes_lock();
-
if (changes_end_year > ICALTIMEZONE_MAX_YEAR)
changes_end_year = ICALTIMEZONE_MAX_YEAR;
if (!zone->changes || zone->end_year < end_year)
icaltimezone_expand_changes(zone, changes_end_year);
-
- icaltimezone_changes_unlock();
}
/* Hold the icaltimezone_changes_lock(); before calling this function */
@@ -841,11 +821,11 @@ int icaltimezone_get_utc_offset(icaltimezone *zone, struct icaltimetype *tt, int
if (zone->builtin_timezone)
zone = zone->builtin_timezone;
+ icaltimezone_changes_lock();
+
/* Make sure the changes array is expanded up to the given time. */
icaltimezone_ensure_coverage(zone, tt->year);
- icaltimezone_changes_lock();
-
if (!zone->changes || zone->changes->num_elements == 0) {
icaltimezone_changes_unlock();
return 0;