summaryrefslogtreecommitdiff
path: root/rsScriptC_Lib.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2011-01-07 15:11:30 -0800
committerStephen Hines <srhines@google.com>2011-01-09 17:04:18 -0800
commitca3f09c0924e9515901dfd47fa5f95385d53cf80 (patch)
treebe6401d33679ca4ebe998456397092bef4f993a3 /rsScriptC_Lib.cpp
parentcf912de17f1e086ccea707d8607a3d2eda56b98f (diff)
downloadrs-ca3f09c0924e9515901dfd47fa5f95385d53cf80.tar.gz
Split time functions into rs_time.rsh header.
Change-Id: I598b0031d15749c91d11fbd37b075d0564a94dbf
Diffstat (limited to 'rsScriptC_Lib.cpp')
-rw-r--r--rsScriptC_Lib.cpp80
1 files changed, 15 insertions, 65 deletions
diff --git a/rsScriptC_Lib.cpp b/rsScriptC_Lib.cpp
index f61b983b..0b216699 100644
--- a/rsScriptC_Lib.cpp
+++ b/rsScriptC_Lib.cpp
@@ -100,70 +100,24 @@ static float SC_frac(float v) {
// Time routines
//////////////////////////////////////////////////////////////////////////////
-static int32_t SC_second() {
+static time_t SC_time(time_t *timer) {
GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_sec;
-}
-
-static int32_t SC_minute() {
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_min;
-}
-
-static int32_t SC_hour() {
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_hour;
+ return time(timer);
}
-static int32_t SC_day() {
+static tm* SC_localtime(tm *local, time_t *timer) {
GET_TLS();
+ if (!local) {
+ return NULL;
+ }
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_mday;
-}
-
-static int32_t SC_month() {
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_mon;
-}
-
-static int32_t SC_year() {
- GET_TLS();
-
- time_t rawtime;
- time(&rawtime);
-
- struct tm *timeinfo;
- timeinfo = localtime(&rawtime);
- return timeinfo->tm_year;
+ // The native localtime function is not thread-safe, so we
+ // have to apply locking for proper behavior in RenderScript.
+ pthread_mutex_lock(&rsc->gLibMutex);
+ tm *tmp = localtime(timer);
+ memcpy(local, tmp, sizeof(*tmp));
+ pthread_mutex_unlock(&rsc->gLibMutex);
+ return local;
}
static int64_t SC_uptimeMillis() {
@@ -498,12 +452,8 @@ static ScriptCState::SymbolTable_t gSyms[] = {
{ "_Z6rsFracf", (void *)&SC_frac, true },
// time
- { "_Z8rsSecondv", (void *)&SC_second, true },
- { "_Z8rsMinutev", (void *)&SC_minute, true },
- { "_Z6rsHourv", (void *)&SC_hour, true },
- { "_Z5rsDayv", (void *)&SC_day, true },
- { "_Z7rsMonthv", (void *)&SC_month, true },
- { "_Z6rsYearv", (void *)&SC_year, true },
+ { "_Z6rsTimePi", (void *)&SC_time, true },
+ { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_localtime, true },
{ "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis, true },
{ "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos, true },
{ "_Z7rsGetDtv", (void*)&SC_getDt, false },