diff options
author | Tavian Barnes <tavianator@gmail.com> | 2012-08-21 23:08:30 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2012-08-21 23:09:51 -0400 |
commit | c150be9eb7e0d69def245d877bd66f6df87f58a1 (patch) | |
tree | 4aa5c7cbd4fe2826538a0785dfa2dde61dd4d9f7 /libdimension | |
parent | b2c3b538298f650e4d1dfb522d52de31de9be645 (diff) | |
download | dimension-c150be9eb7e0d69def245d877bd66f6df87f58a1.tar.xz |
Get Dimension working on Android.android
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/error.c | 28 | ||||
-rw-r--r-- | libdimension/future.c | 11 | ||||
-rw-r--r-- | libdimension/platform.c | 4 | ||||
-rw-r--r-- | libdimension/threads.c | 8 |
4 files changed, 24 insertions, 27 deletions
diff --git a/libdimension/error.c b/libdimension/error.c index 371c7cd..9fb116a 100644 --- a/libdimension/error.c +++ b/libdimension/error.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2012 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -28,13 +28,18 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> +#include <android/log.h> + +/** Android log tag. */ +#define TAG "libdimension" /** Report internal errors in this file. */ -#define DMNSN_LOCAL_ERROR(str) \ - do { \ - fprintf(stderr, "Dimension ERROR: %s, %s:%u: %s\n", \ - DMNSN_FUNC, __FILE__, __LINE__, (str)); \ - abort(); \ +#define DMNSN_LOCAL_ERROR(str) \ + do { \ + __android_log_print(ANDROID_LOG_ERROR, TAG, \ + "Dimension ERROR: %s, %s:%u: %s\n", \ + DMNSN_FUNC, __FILE__, __LINE__, (str)); \ + abort(); \ } while (0) /** dmnsn_local_lock_mutex implementation. */ @@ -89,18 +94,19 @@ dmnsn_report_error(bool die, const char *func, const char *file, dmnsn_local_unlock_mutex(&dmnsn_always_die_mutex); /* Print the diagnostic string */ - fprintf(stderr, "Dimension %s: %s, %s:%u: %s\n", - die ? "ERROR" : "WARNING", func, file, line, str); + __android_log_print(ANDROID_LOG_ERROR, TAG, + "Dimension %s: %s, %s:%u: %s\n", + die ? "ERROR" : "WARNING", func, file, line, str); /* Print the value of errno */ if (err != 0) { - fprintf(stderr, "Last error: %d", err); + __android_log_print(ANDROID_LOG_ERROR, TAG, "Last error: %d", err); #if DMNSN_SYS_ERRLIST if (err >= 0 && err < sys_nerr) { - fprintf(stderr, " (%s)", sys_errlist[err]); + __android_log_print(ANDROID_LOG_ERROR, TAG, " (%s)", sys_errlist[err]); } #endif - fprintf(stderr, "\n"); + __android_log_print(ANDROID_LOG_ERROR, TAG, "\n"); } /* Print a stack trace to standard error */ diff --git a/libdimension/future.c b/libdimension/future.c index c328815..437b490 100644 --- a/libdimension/future.c +++ b/libdimension/future.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2009-2012 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -61,7 +61,7 @@ dmnsn_future_join(dmnsn_future *future) if (future) { /* Get the thread's return value */ dmnsn_join_thread(future->thread, &ptr); - if (ptr && ptr != PTHREAD_CANCELED) { + if (ptr) { retval = *(int *)ptr; dmnsn_free(ptr); } @@ -89,7 +89,7 @@ dmnsn_future_join(dmnsn_future *future) void dmnsn_future_cancel(dmnsn_future *future) { - pthread_cancel(future->thread); + dmnsn_error("Thread cancellation not supported on Android."); } /* Get the current progress of the worker thread, in [0.0, 1.0] */ @@ -133,11 +133,6 @@ dmnsn_future_set_total(dmnsn_future *future, size_t total) void dmnsn_future_increment(dmnsn_future *future) { - /* Allow a thread to be canceled whenever it increments a future object -- - this is close to PTHREAD_CANCEL_ASYNCHRONOUS but allows consistent state - on cancellation */ - pthread_testcancel(); - dmnsn_write_lock(future->rwlock); ++future->progress; dmnsn_unlock_rwlock(future->rwlock); diff --git a/libdimension/platform.c b/libdimension/platform.c index a27343d..b4efa09 100644 --- a/libdimension/platform.c +++ b/libdimension/platform.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2010-2012 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -67,6 +67,8 @@ dmnsn_is_main_thread(void) { #if DMNSN_GETTID return getpid() == syscall(SYS_gettid); +#elif DMNSN_GETTID_DIRECT + return getpid() == gettid(); #else return true; #endif diff --git a/libdimension/threads.c b/libdimension/threads.c index 0aed16d..5dce26c 100644 --- a/libdimension/threads.c +++ b/libdimension/threads.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2010-2012 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -102,12 +102,6 @@ dmnsn_ccthread_cleanup(void *ptr) for (unsigned int i = 0; i < payload->nthreads; ++i) { if (payload->payloads[i].started) { - pthread_cancel(payload->threads[i]); - } - } - - for (unsigned int i = 0; i < payload->nthreads; ++i) { - if (payload->payloads[i].started) { dmnsn_join_thread(payload->threads[i], NULL); } } |