[libdispatch-changes] [60] trunk/src
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 28 01:29:50 PDT 2009
Revision: 60
http://trac.macosforge.org/projects/libdispatch/changeset/60
Author: robert at fledge.watson.org
Date: 2009-10-28 01:29:47 -0700 (Wed, 28 Oct 2009)
Log Message:
-----------
Break out os_shims.h from a single monolothic header into area-specific
headers under src/shims: perfmon (supporting DISPATCH_PERF_MON), time
query functions, and thread-specific data functions. Move os_shims.c to
src/shims/mach.c as it consists solely of Mach-related code. These are
built internally to libdispatch to create a libshims.
Submitted by: Paolo Bonzini <bonzini at gnu.org>
Modified Paths:
--------------
trunk/src/Makefile.am
trunk/src/os_shims.h
Added Paths:
-----------
trunk/src/shims/
trunk/src/shims/mach.c
trunk/src/shims/perfmon.h
trunk/src/shims/time.h
trunk/src/shims/tsd.h
Removed Paths:
-------------
trunk/src/shims.c
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2009-10-27 23:29:17 UTC (rev 59)
+++ trunk/src/Makefile.am 2009-10-28 08:29:47 UTC (rev 60)
@@ -3,6 +3,7 @@
#
lib_LTLIBRARIES=libdispatch.la
+noinst_LTLIBRARIES=libshims.la
libdispatch_la_SOURCES= \
apply.c \
@@ -11,10 +12,12 @@
once.c \
queue.c \
semaphore.c \
- shims.c \
source.c \
time.c
+libshims_la_SOURCES= \
+ shims/mach.c
+
libdispatch_la_CFLAGS=-Wall
INCLUDES=-I$(top_builddir) -I$(top_srcdir) \
@APPLE_LIBC_SOURCE_PATH@ @APPLE_XNU_SOURCE_PATH@
@@ -26,8 +29,11 @@
legacy.c
endif
+libdispatch_la_LIBADD=libshims.la
+libdispatch_la_DEPENDENCIES=libshims.la
+
if USE_LIBPTHREAD
-libdispatch_la_LIBADD=-lpthread
+libdispatch_la_LIBADD+=-lpthread
endif
if USE_MIG
Modified: trunk/src/os_shims.h
===================================================================
--- trunk/src/os_shims.h 2009-10-27 23:29:17 UTC (rev 59)
+++ trunk/src/os_shims.h 2009-10-28 08:29:47 UTC (rev 60)
@@ -42,178 +42,8 @@
__private_extern__ const char *__crashreporter_info__;
#endif
-#ifdef HAVE_PTHREAD_KEY_INIT_NP
-static const unsigned long dispatch_queue_key = __PTK_LIBDISPATCH_KEY0;
-static const unsigned long dispatch_sema4_key = __PTK_LIBDISPATCH_KEY1;
-static const unsigned long dispatch_cache_key = __PTK_LIBDISPATCH_KEY2;
-static const unsigned long dispatch_bcounter_key = __PTK_LIBDISPATCH_KEY3;
-//__PTK_LIBDISPATCH_KEY4
-//__PTK_LIBDISPATCH_KEY5
-#else
-pthread_key_t dispatch_queue_key;
-pthread_key_t dispatch_sema4_key;
-pthread_key_t dispatch_cache_key;
-pthread_key_t dispatch_bcounter_key;
-#endif
+#include "shims/tsd.h"
+#include "shims/perfmon.h"
+#include "shims/time.h"
-#ifdef USE_APPLE_TSD_OPTIMIZATIONS
-#define SIMULATE_5491082 1
-#ifndef _PTHREAD_TSD_OFFSET
-#define _PTHREAD_TSD_OFFSET 0
#endif
-
-static inline void
-_dispatch_thread_setspecific(unsigned long k, void *v)
-{
-#if defined(SIMULATE_5491082) && defined(__i386__)
- asm("movl %1, %%gs:%0" : "=m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)) : "ri" (v) : "memory");
-#elif defined(SIMULATE_5491082) && defined(__x86_64__)
- asm("movq %1, %%gs:%0" : "=m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)) : "rn" (v) : "memory");
-#else
- int res;
- if (_pthread_has_direct_tsd()) {
- res = _pthread_setspecific_direct(k, v);
- } else {
- res = pthread_setspecific(k, v);
- }
- dispatch_assert_zero(res);
-#endif
-}
-
-static inline void *
-_dispatch_thread_getspecific(unsigned long k)
-{
-#if defined(SIMULATE_5491082) && (defined(__i386__) || defined(__x86_64__))
- void *rval;
- asm("mov %%gs:%1, %0" : "=r" (rval) : "m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)));
- return rval;
-#else
- if (_pthread_has_direct_tsd()) {
- return _pthread_getspecific_direct(k);
- } else {
- return pthread_getspecific(k);
- }
-#endif
-}
-
-#else /* !USE_APPLE_TSD_OPTIMIZATIONS */
-
-static inline void
-_dispatch_thread_setspecific(pthread_key_t k, void *v)
-{
- int res;
-
- res = pthread_setspecific(k, v);
- dispatch_assert_zero(res);
-}
-
-static inline void *
-_dispatch_thread_getspecific(pthread_key_t k)
-{
-
- return pthread_getspecific(k);
-}
-#endif /* USE_APPLE_TSD_OPTIMIZATIONS */
-
-#ifdef HAVE_PTHREAD_KEY_INIT_NP
-static inline void
-_dispatch_thread_key_init_np(unsigned long k, void (*d)(void *))
-{
- dispatch_assert_zero(pthread_key_init_np((int)k, d));
-}
-#else
-static inline void
-_dispatch_thread_key_create(pthread_key_t *key, void (*destructor)(void *))
-{
-
- dispatch_assert_zero(pthread_key_create(key, destructor));
-}
-#endif
-
-#define _dispatch_thread_self pthread_self
-
-
-#if DISPATCH_PERF_MON
-
-#if defined (USE_APPLE_TSD_OPTIMIZATIONS) && defined(SIMULATE_5491082) && (defined(__i386__) || defined(__x86_64__))
-#ifdef __LP64__
-#define _dispatch_workitem_inc() asm("incq %%gs:%0" : "+m" \
- (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
-#define _dispatch_workitem_dec() asm("decq %%gs:%0" : "+m" \
- (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
-#else
-#define _dispatch_workitem_inc() asm("incl %%gs:%0" : "+m" \
- (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
-#define _dispatch_workitem_dec() asm("decl %%gs:%0" : "+m" \
- (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
-#endif
-#else /* !USE_APPLE_TSD_OPTIMIZATIONS */
-static inline void
-_dispatch_workitem_inc(void)
-{
- unsigned long cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
- _dispatch_thread_setspecific(dispatch_bcounter_key, (void *)++cnt);
-}
-static inline void
-_dispatch_workitem_dec(void)
-{
- unsigned long cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
- _dispatch_thread_setspecific(dispatch_bcounter_key, (void *)--cnt);
-}
-#endif /* USE_APPLE_TSD_OPTIMIZATIONS */
-
-// C99 doesn't define flsll() or ffsll()
-#ifdef __LP64__
-#define flsll(x) flsl(x)
-#else
-static inline unsigned int
-flsll(uint64_t val)
-{
- union {
- struct {
-#ifdef __BIG_ENDIAN__
- unsigned int hi, low;
-#else
- unsigned int low, hi;
-#endif
- } words;
- uint64_t word;
- } _bucket = {
- .word = val,
- };
- if (_bucket.words.hi) {
- return fls(_bucket.words.hi) + 32;
- }
- return fls(_bucket.words.low);
-}
-#endif
-
-#else
-#define _dispatch_workitem_inc()
-#define _dispatch_workitem_dec()
-#endif // DISPATCH_PERF_MON
-
-static inline uint64_t
-_dispatch_absolute_time(void)
-{
-#ifndef HAVE_MACH_ABSOLUTE_TIME
- struct timespec ts;
- int ret;
-
-#if HAVE_DECL_CLOCK_UPTIME
- ret = clock_gettime(CLOCK_UPTIME, &ts);
-#elif HAVE_DECL_CLOCK_MONOTONIC
- ret = clock_gettime(CLOCK_MONOTONIC, &ts);
-#else
-#error "clock_gettime: no supported absolute time clock"
-#endif
- dispatch_assume_zero(ret);
-
- /* XXXRW: Some kind of overflow detection needed? */
- return (ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec);
-#else
- return mach_absolute_time();
-#endif
-}
-
-#endif
Copied: trunk/src/shims/mach.c (from rev 59, trunk/src/shims.c)
===================================================================
--- trunk/src/shims/mach.c (rev 0)
+++ trunk/src/shims/mach.c 2009-10-28 08:29:47 UTC (rev 60)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+#include "internal.h"
+
+#ifdef HAVE_MACH
+void *
+dispatch_mach_msg_get_context(mach_msg_header_t *msg)
+{
+ mach_msg_context_trailer_t *tp;
+ void *context = NULL;
+
+ tp = (mach_msg_context_trailer_t *)((uint8_t *)msg + round_msg(msg->msgh_size));
+ if (tp->msgh_trailer_size >= (mach_msg_size_t)sizeof(mach_msg_context_trailer_t)) {
+ context = (void *)(uintptr_t)tp->msgh_context;
+ }
+
+ return context;
+}
+
+/*
+ * Raw Mach message support
+ */
+boolean_t
+_dispatch_machport_callback(mach_msg_header_t *msg, mach_msg_header_t *reply,
+ void (*callback)(mach_msg_header_t *))
+{
+ mig_reply_setup(msg, reply);
+ ((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
+
+ callback(msg);
+
+ return TRUE;
+}
+
+/*
+ * CFMachPort compatibility
+ */
+boolean_t
+_dispatch_CFMachPortCallBack(mach_msg_header_t *msg, mach_msg_header_t *reply,
+ void (*callback)(struct __CFMachPort *, void *msg, signed long size, void *))
+{
+ mig_reply_setup(msg, reply);
+ ((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
+
+ callback(NULL, msg, msg->msgh_size, dispatch_mach_msg_get_context(msg));
+
+ return TRUE;
+}
+#endif /* HAVE_MACH */
Added: trunk/src/shims/perfmon.h
===================================================================
--- trunk/src/shims/perfmon.h (rev 0)
+++ trunk/src/shims/perfmon.h 2009-10-28 08:29:47 UTC (rev 60)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+/*
+ * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
+ * which are subject to change in future releases of Mac OS X. Any applications
+ * relying on these interfaces WILL break.
+ */
+
+#ifndef __DISPATCH_SHIMS_PERFMON__
+#define __DISPATCH_SHIMS_PERFMON__
+
+#if DISPATCH_PERF_MON
+
+#if defined (USE_APPLE_TSD_OPTIMIZATIONS) && defined(SIMULATE_5491082) && (defined(__i386__) || defined(__x86_64__))
+#ifdef __LP64__
+#define _dispatch_workitem_inc() asm("incq %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#define _dispatch_workitem_dec() asm("decq %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#else
+#define _dispatch_workitem_inc() asm("incl %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#define _dispatch_workitem_dec() asm("decl %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#endif
+#else /* !USE_APPLE_TSD_OPTIMIZATIONS */
+static inline void
+_dispatch_workitem_inc(void)
+{
+ unsigned long cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
+ _dispatch_thread_setspecific(dispatch_bcounter_key, (void *)++cnt);
+}
+static inline void
+_dispatch_workitem_dec(void)
+{
+ unsigned long cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
+ _dispatch_thread_setspecific(dispatch_bcounter_key, (void *)--cnt);
+}
+#endif /* USE_APPLE_TSD_OPTIMIZATIONS */
+
+// C99 doesn't define flsll() or ffsll()
+#ifdef __LP64__
+#define flsll(x) flsl(x)
+#else
+static inline unsigned int
+flsll(uint64_t val)
+{
+ union {
+ struct {
+#ifdef __BIG_ENDIAN__
+ unsigned int hi, low;
+#else
+ unsigned int low, hi;
+#endif
+ } words;
+ uint64_t word;
+ } _bucket = {
+ .word = val,
+ };
+ if (_bucket.words.hi) {
+ return fls(_bucket.words.hi) + 32;
+ }
+ return fls(_bucket.words.low);
+}
+#endif
+
+#else
+#define _dispatch_workitem_inc()
+#define _dispatch_workitem_dec()
+#endif // DISPATCH_PERF_MON
+
+#endif
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+/*
+ * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
+ * which are subject to change in future releases of Mac OS X. Any applications
+ * relying on these interfaces WILL break.
+ */
+
+#ifndef __DISPATCH_SHIMS_PERFMON__
+#define __DISPATCH_SHIMS_PERFMON__
+
+#if DISPATCH_PERF_MON
+
+#if defined (USE_APPLE_TSD_OPTIMIZATIONS) && defined(SIMULATE_5491082) && (defined(__i386__) || defined(__x86_64__))
+#ifdef __LP64__
+#define _dispatch_workitem_inc() asm("incq %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#define _dispatch_workitem_dec() asm("decq %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#else
+#define _dispatch_workitem_inc() asm("incl %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#define _dispatch_workitem_dec() asm("decl %%gs:%0" : "+m" \
+ (*(void **)(dispatch_bcounter_key * sizeof(void *) + _PTHREAD_TSD_OFFSET)) :: "cc")
+#endif
+#else /* !USE_APPLE_TSD_OPTIMIZATIONS */
+static inline void
+_dispatch_workitem_inc(void)
+{
+ unsigned long cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
+ _dispatch_thread_setspecific(dispatch_bcounter_key, (void *)++cnt);
+}
+static inline void
+_dispatch_workitem_dec(void)
+{
+ unsigned long cnt = (unsigned long)_dispatch_thread_getspecific(dispatch_bcounter_key);
+ _dispatch_thread_setspecific(dispatch_bcounter_key, (void *)--cnt);
+}
+#endif /* USE_APPLE_TSD_OPTIMIZATIONS */
+
+// C99 doesn't define flsll() or ffsll()
+#ifdef __LP64__
+#define flsll(x) flsl(x)
+#else
+static inline unsigned int
+flsll(uint64_t val)
+{
+ union {
+ struct {
+#ifdef __BIG_ENDIAN__
+ unsigned int hi, low;
+#else
+ unsigned int low, hi;
+#endif
+ } words;
+ uint64_t word;
+ } _bucket = {
+ .word = val,
+ };
+ if (_bucket.words.hi) {
+ return fls(_bucket.words.hi) + 32;
+ }
+ return fls(_bucket.words.low);
+}
+#endif
+
+#else
+#define _dispatch_workitem_inc()
+#define _dispatch_workitem_dec()
+#endif // DISPATCH_PERF_MON
+
+#endif
Property changes on: trunk/src/shims/perfmon.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ FreeBSD=%H
Added: svn:eol-style
+ native
Added: trunk/src/shims/time.h
===================================================================
--- trunk/src/shims/time.h (rev 0)
+++ trunk/src/shims/time.h 2009-10-28 08:29:47 UTC (rev 60)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+/*
+ * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
+ * which are subject to change in future releases of Mac OS X. Any applications
+ * relying on these interfaces WILL break.
+ */
+
+#ifndef __DISPATCH_SHIMS_TIME__
+#define __DISPATCH_SHIMS_TIME__
+
+static inline uint64_t
+_dispatch_absolute_time(void)
+{
+#ifndef HAVE_MACH_ABSOLUTE_TIME
+ struct timespec ts;
+ int ret;
+
+#if HAVE_DECL_CLOCK_UPTIME
+ ret = clock_gettime(CLOCK_UPTIME, &ts);
+#elif HAVE_DECL_CLOCK_MONOTONIC
+ ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+#error "clock_gettime: no supported absolute time clock"
+#endif
+ dispatch_assume_zero(ret);
+
+ /* XXXRW: Some kind of overflow detection needed? */
+ return (ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec);
+#else
+ return mach_absolute_time();
+#endif
+}
+
+#endif
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+/*
+ * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
+ * which are subject to change in future releases of Mac OS X. Any applications
+ * relying on these interfaces WILL break.
+ */
+
+#ifndef __DISPATCH_SHIMS_TIME__
+#define __DISPATCH_SHIMS_TIME__
+
+static inline uint64_t
+_dispatch_absolute_time(void)
+{
+#ifndef HAVE_MACH_ABSOLUTE_TIME
+ struct timespec ts;
+ int ret;
+
+#if HAVE_DECL_CLOCK_UPTIME
+ ret = clock_gettime(CLOCK_UPTIME, &ts);
+#elif HAVE_DECL_CLOCK_MONOTONIC
+ ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+#error "clock_gettime: no supported absolute time clock"
+#endif
+ dispatch_assume_zero(ret);
+
+ /* XXXRW: Some kind of overflow detection needed? */
+ return (ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec);
+#else
+ return mach_absolute_time();
+#endif
+}
+
+#endif
Property changes on: trunk/src/shims/time.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ FreeBSD=%H
Added: svn:eol-style
+ native
Added: trunk/src/shims/tsd.h
===================================================================
--- trunk/src/shims/tsd.h (rev 0)
+++ trunk/src/shims/tsd.h 2009-10-28 08:29:47 UTC (rev 60)
@@ -0,0 +1,240 @@
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+/*
+ * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
+ * which are subject to change in future releases of Mac OS X. Any applications
+ * relying on these interfaces WILL break.
+ */
+
+#ifndef __DISPATCH_SHIMS_TSD__
+#define __DISPATCH_SHIMS_TSD__
+
+#ifdef HAVE_PTHREAD_KEY_INIT_NP
+static const unsigned long dispatch_queue_key = __PTK_LIBDISPATCH_KEY0;
+static const unsigned long dispatch_sema4_key = __PTK_LIBDISPATCH_KEY1;
+static const unsigned long dispatch_cache_key = __PTK_LIBDISPATCH_KEY2;
+static const unsigned long dispatch_bcounter_key = __PTK_LIBDISPATCH_KEY3;
+//__PTK_LIBDISPATCH_KEY4
+//__PTK_LIBDISPATCH_KEY5
+#else
+pthread_key_t dispatch_queue_key;
+pthread_key_t dispatch_sema4_key;
+pthread_key_t dispatch_cache_key;
+pthread_key_t dispatch_bcounter_key;
+#endif
+
+#ifdef USE_APPLE_TSD_OPTIMIZATIONS
+#define SIMULATE_5491082 1
+#ifndef _PTHREAD_TSD_OFFSET
+#define _PTHREAD_TSD_OFFSET 0
+#endif
+
+static inline void
+_dispatch_thread_setspecific(unsigned long k, void *v)
+{
+#if defined(SIMULATE_5491082) && defined(__i386__)
+ asm("movl %1, %%gs:%0" : "=m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)) : "ri" (v) : "memory");
+#elif defined(SIMULATE_5491082) && defined(__x86_64__)
+ asm("movq %1, %%gs:%0" : "=m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)) : "rn" (v) : "memory");
+#else
+ int res;
+ if (_pthread_has_direct_tsd()) {
+ res = _pthread_setspecific_direct(k, v);
+ } else {
+ res = pthread_setspecific(k, v);
+ }
+ dispatch_assert_zero(res);
+#endif
+}
+
+static inline void *
+_dispatch_thread_getspecific(unsigned long k)
+{
+#if defined(SIMULATE_5491082) && (defined(__i386__) || defined(__x86_64__))
+ void *rval;
+ asm("mov %%gs:%1, %0" : "=r" (rval) : "m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)));
+ return rval;
+#else
+ if (_pthread_has_direct_tsd()) {
+ return _pthread_getspecific_direct(k);
+ } else {
+ return pthread_getspecific(k);
+ }
+#endif
+}
+
+#else /* !USE_APPLE_TSD_OPTIMIZATIONS */
+
+static inline void
+_dispatch_thread_setspecific(pthread_key_t k, void *v)
+{
+ int res;
+
+ res = pthread_setspecific(k, v);
+ dispatch_assert_zero(res);
+}
+
+static inline void *
+_dispatch_thread_getspecific(pthread_key_t k)
+{
+
+ return pthread_getspecific(k);
+}
+#endif /* USE_APPLE_TSD_OPTIMIZATIONS */
+
+#ifdef HAVE_PTHREAD_KEY_INIT_NP
+static inline void
+_dispatch_thread_key_init_np(unsigned long k, void (*d)(void *))
+{
+ dispatch_assert_zero(pthread_key_init_np((int)k, d));
+}
+#else
+static inline void
+_dispatch_thread_key_create(pthread_key_t *key, void (*destructor)(void *))
+{
+
+ dispatch_assert_zero(pthread_key_create(key, destructor));
+}
+#endif
+
+#define _dispatch_thread_self pthread_self
+
+#endif
+/*
+ * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+/*
+ * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
+ * which are subject to change in future releases of Mac OS X. Any applications
+ * relying on these interfaces WILL break.
+ */
+
+#ifndef __DISPATCH_SHIMS_TSD__
+#define __DISPATCH_SHIMS_TSD__
+
+#ifdef HAVE_PTHREAD_KEY_INIT_NP
+static const unsigned long dispatch_queue_key = __PTK_LIBDISPATCH_KEY0;
+static const unsigned long dispatch_sema4_key = __PTK_LIBDISPATCH_KEY1;
+static const unsigned long dispatch_cache_key = __PTK_LIBDISPATCH_KEY2;
+static const unsigned long dispatch_bcounter_key = __PTK_LIBDISPATCH_KEY3;
+//__PTK_LIBDISPATCH_KEY4
+//__PTK_LIBDISPATCH_KEY5
+#else
+pthread_key_t dispatch_queue_key;
+pthread_key_t dispatch_sema4_key;
+pthread_key_t dispatch_cache_key;
+pthread_key_t dispatch_bcounter_key;
+#endif
+
+#ifdef USE_APPLE_TSD_OPTIMIZATIONS
+#define SIMULATE_5491082 1
+#ifndef _PTHREAD_TSD_OFFSET
+#define _PTHREAD_TSD_OFFSET 0
+#endif
+
+static inline void
+_dispatch_thread_setspecific(unsigned long k, void *v)
+{
+#if defined(SIMULATE_5491082) && defined(__i386__)
+ asm("movl %1, %%gs:%0" : "=m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)) : "ri" (v) : "memory");
+#elif defined(SIMULATE_5491082) && defined(__x86_64__)
+ asm("movq %1, %%gs:%0" : "=m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)) : "rn" (v) : "memory");
+#else
+ int res;
+ if (_pthread_has_direct_tsd()) {
+ res = _pthread_setspecific_direct(k, v);
+ } else {
+ res = pthread_setspecific(k, v);
+ }
+ dispatch_assert_zero(res);
+#endif
+}
+
+static inline void *
+_dispatch_thread_getspecific(unsigned long k)
+{
+#if defined(SIMULATE_5491082) && (defined(__i386__) || defined(__x86_64__))
+ void *rval;
+ asm("mov %%gs:%1, %0" : "=r" (rval) : "m" (*(void **)(k * sizeof(void *) + _PTHREAD_TSD_OFFSET)));
+ return rval;
+#else
+ if (_pthread_has_direct_tsd()) {
+ return _pthread_getspecific_direct(k);
+ } else {
+ return pthread_getspecific(k);
+ }
+#endif
+}
+
+#else /* !USE_APPLE_TSD_OPTIMIZATIONS */
+
+static inline void
+_dispatch_thread_setspecific(pthread_key_t k, void *v)
+{
+ int res;
+
+ res = pthread_setspecific(k, v);
+ dispatch_assert_zero(res);
+}
+
+static inline void *
+_dispatch_thread_getspecific(pthread_key_t k)
+{
+
+ return pthread_getspecific(k);
+}
+#endif /* USE_APPLE_TSD_OPTIMIZATIONS */
+
+#ifdef HAVE_PTHREAD_KEY_INIT_NP
+static inline void
+_dispatch_thread_key_init_np(unsigned long k, void (*d)(void *))
+{
+ dispatch_assert_zero(pthread_key_init_np((int)k, d));
+}
+#else
+static inline void
+_dispatch_thread_key_create(pthread_key_t *key, void (*destructor)(void *))
+{
+
+ dispatch_assert_zero(pthread_key_create(key, destructor));
+}
+#endif
+
+#define _dispatch_thread_self pthread_self
+
+#endif
Property changes on: trunk/src/shims/tsd.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ FreeBSD=%H
Added: svn:eol-style
+ native
Deleted: trunk/src/shims.c
===================================================================
--- trunk/src/shims.c 2009-10-27 23:29:17 UTC (rev 59)
+++ trunk/src/shims.c 2009-10-28 08:29:47 UTC (rev 60)
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
- *
- * @APPLE_APACHE_LICENSE_HEADER_START@
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @APPLE_APACHE_LICENSE_HEADER_END@
- */
-
-#include "internal.h"
-
-#ifdef HAVE_MACH
-void *
-dispatch_mach_msg_get_context(mach_msg_header_t *msg)
-{
- mach_msg_context_trailer_t *tp;
- void *context = NULL;
-
- tp = (mach_msg_context_trailer_t *)((uint8_t *)msg + round_msg(msg->msgh_size));
- if (tp->msgh_trailer_size >= (mach_msg_size_t)sizeof(mach_msg_context_trailer_t)) {
- context = (void *)(uintptr_t)tp->msgh_context;
- }
-
- return context;
-}
-
-/*
- * Raw Mach message support
- */
-boolean_t
-_dispatch_machport_callback(mach_msg_header_t *msg, mach_msg_header_t *reply,
- void (*callback)(mach_msg_header_t *))
-{
- mig_reply_setup(msg, reply);
- ((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
-
- callback(msg);
-
- return TRUE;
-}
-
-/*
- * CFMachPort compatibility
- */
-boolean_t
-_dispatch_CFMachPortCallBack(mach_msg_header_t *msg, mach_msg_header_t *reply,
- void (*callback)(struct __CFMachPort *, void *msg, signed long size, void *))
-{
- mig_reply_setup(msg, reply);
- ((mig_reply_error_t*)reply)->RetCode = MIG_NO_REPLY;
-
- callback(NULL, msg, msg->msgh_size, dispatch_mach_msg_get_context(msg));
-
- return TRUE;
-}
-#endif /* HAVE_MACH */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/libdispatch-changes/attachments/20091028/2858efef/attachment-0001.html>
More information about the libdispatch-changes
mailing list