Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2007-11-02 05:17:03


Author: anthonyw
Date: 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
New Revision: 40679
URL: http://svn.boost.org/trac/boost/changeset/40679

Log:
Added changes from David Deakins to enable compilation on Windows CE
Text files modified:
   trunk/boost/detail/interlocked.hpp | 5 +++
   trunk/boost/thread/win32/thread_heap_alloc.hpp | 4 ++
   trunk/boost/thread/win32/thread_primitives.hpp | 66 ++++++++++++++++++++++++++++++++++++---
   trunk/libs/thread/src/tss_null.cpp | 3 +
   trunk/libs/thread/src/win32/thread.cpp | 45 ++++++++++++++++++++++++---
   trunk/libs/thread/src/win32/tss.cpp | 52 +++---------------------------
   trunk/libs/thread/src/win32/tss_hooks.cpp | 6 +++
   trunk/libs/thread/src/win32/tss_pe.cpp | 4 +
   8 files changed, 126 insertions(+), 59 deletions(-)

Modified: trunk/boost/detail/interlocked.hpp
==============================================================================
--- trunk/boost/detail/interlocked.hpp (original)
+++ trunk/boost/detail/interlocked.hpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -47,6 +47,11 @@
 # define BOOST_INTERLOCKED_EXCHANGE InterlockedExchange
 # define BOOST_INTERLOCKED_EXCHANGE_ADD InterlockedExchangeAdd
 
+# define BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(dest,exchange,compare) \
+ ((void*)BOOST_INTERLOCKED_COMPARE_EXCHANGE((long*)(dest),(long)(exchange),(long)(compare)))
+# define BOOST_INTERLOCKED_EXCHANGE_POINTER(dest,exchange) \
+ ((void*)BOOST_INTERLOCKED_EXCHANGE((long*)(dest),(long)(exchange)))
+
 #elif defined( BOOST_MSVC ) || defined( BOOST_INTEL_WIN )
 
 extern "C" long __cdecl _InterlockedIncrement( long volatile * );

Modified: trunk/boost/thread/win32/thread_heap_alloc.hpp
==============================================================================
--- trunk/boost/thread/win32/thread_heap_alloc.hpp (original)
+++ trunk/boost/thread/win32/thread_heap_alloc.hpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -25,6 +25,10 @@
 
 #else
 
+# ifdef HeapAlloc
+# undef HeapAlloc
+# endif
+
 namespace boost
 {
     namespace detail

Modified: trunk/boost/thread/win32/thread_primitives.hpp
==============================================================================
--- trunk/boost/thread/win32/thread_primitives.hpp (original)
+++ trunk/boost/thread/win32/thread_primitives.hpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -3,7 +3,8 @@
 
 // win32_thread_primitives.hpp
 //
-// (C) Copyright 2005-6 Anthony Williams
+// (C) Copyright 2005-7 Anthony Williams
+// (C) Copyright 2007 David Deakins
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
@@ -28,9 +29,15 @@
             unsigned const timeout=WAIT_TIMEOUT;
             handle const invalid_handle_value=INVALID_HANDLE_VALUE;
 
+# ifdef BOOST_NO_ANSI_APIS
+ using ::CreateMutexW;
+ using ::CreateEventW;
+ using ::CreateSemaphoreW;
+# else
             using ::CreateMutexA;
             using ::CreateEventA;
             using ::CreateSemaphoreA;
+# endif
             using ::CloseHandle;
             using ::ReleaseMutex;
             using ::ReleaseSemaphore;
@@ -50,6 +57,29 @@
     }
 }
 #elif defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+
+# ifdef UNDER_CE
+# ifndef WINAPI
+# ifndef _WIN32_WCE_EMULATION
+# define WINAPI __cdecl // Note this doesn't match the desktop definition
+# else
+# define WINAPI __stdcall
+# endif
+# endif
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+typedef int BOOL;
+typedef unsigned long DWORD;
+typedef void* HANDLE;
+
+# include <kfuncs.h>
+# ifdef __cplusplus
+}
+# endif
+# endif
+
 namespace boost
 {
     namespace detail
@@ -70,25 +100,41 @@
             extern "C"
             {
                 struct _SECURITY_ATTRIBUTES;
+# ifdef BOOST_NO_ANSI_APIS
+ __declspec(dllimport) void* __stdcall CreateMutexW(_SECURITY_ATTRIBUTES*,int,wchar_t const*);
+ __declspec(dllimport) void* __stdcall CreateSemaphoreW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*);
+ __declspec(dllimport) void* __stdcall CreateEventW(_SECURITY_ATTRIBUTES*,int,int,wchar_t const*);
+# else
                 __declspec(dllimport) void* __stdcall CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*);
                 __declspec(dllimport) void* __stdcall CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*);
                 __declspec(dllimport) void* __stdcall CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*);
+# endif
                 __declspec(dllimport) int __stdcall CloseHandle(void*);
                 __declspec(dllimport) int __stdcall ReleaseMutex(void*);
- __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
- __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
                 __declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void*,unsigned long);
+ __declspec(dllimport) unsigned long __stdcall WaitForMultipleObjects(unsigned long nCount,void* const * lpHandles,int bWaitAll,unsigned long dwMilliseconds);
                 __declspec(dllimport) int __stdcall ReleaseSemaphore(void*,long,long*);
- __declspec(dllimport) void* __stdcall GetCurrentThread();
- __declspec(dllimport) void* __stdcall GetCurrentProcess();
                 __declspec(dllimport) int __stdcall DuplicateHandle(void*,void*,void*,void**,unsigned long,int,unsigned long);
                 __declspec(dllimport) unsigned long __stdcall SleepEx(unsigned long,int);
                 __declspec(dllimport) void __stdcall Sleep(unsigned long);
                 typedef void (__stdcall *queue_user_apc_callback_function)(ulong_ptr);
                 __declspec(dllimport) unsigned long __stdcall QueueUserAPC(queue_user_apc_callback_function,void*,ulong_ptr);
+
+# ifndef UNDER_CE
+ __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
+ __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
+ __declspec(dllimport) void* __stdcall GetCurrentThread();
+ __declspec(dllimport) void* __stdcall GetCurrentProcess();
                 __declspec(dllimport) int __stdcall SetEvent(void*);
                 __declspec(dllimport) int __stdcall ResetEvent(void*);
- __declspec(dllimport) unsigned long __stdcall WaitForMultipleObjects(unsigned long nCount,void* const * lpHandles,int bWaitAll,unsigned long dwMilliseconds);
+# else
+ using ::GetCurrentProcessId;
+ using ::GetCurrentThreadId;
+ using ::GetCurrentThread;
+ using ::GetCurrentProcess;
+ using ::SetEvent;
+ using ::ResetEvent;
+# endif
             }
         }
     }
@@ -117,7 +163,11 @@
             
             inline handle create_anonymous_event(event_type type,initial_event_state state)
             {
+#if !defined(BOOST_NO_ANSI_APIS)
                 handle const res=win32::CreateEventA(0,type,state,0);
+#else
+ handle const res=win32::CreateEventW(0,type,state,0);
+#endif
                 if(!res)
                 {
                     throw thread_resource_error();
@@ -127,7 +177,11 @@
 
             inline handle create_anonymous_semaphore(long initial_count,long max_count)
             {
+#if !defined(BOOST_NO_ANSI_APIS)
                 handle const res=CreateSemaphoreA(NULL,initial_count,max_count,NULL);
+#else
+ handle const res=CreateSemaphoreW(NULL,initial_count,max_count,NULL);
+#endif
                 if(!res)
                 {
                     throw thread_resource_error();

Modified: trunk/libs/thread/src/tss_null.cpp
==============================================================================
--- trunk/libs/thread/src/tss_null.cpp (original)
+++ trunk/libs/thread/src/tss_null.cpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -1,11 +1,12 @@
 // (C) Copyright Michael Glassford 2004.
+// (C) Copyright 2007 Anthony Williams
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #include <boost/thread/detail/config.hpp>
 
-#if defined(BOOST_HAS_WINTHREADS) && (defined(BOOST_THREAD_BUILD_LIB) || defined(BOOST_THREAD_TEST)) && !defined(_MSC_VER)
+#if defined(BOOST_HAS_WINTHREADS) && (defined(BOOST_THREAD_BUILD_LIB) || defined(BOOST_THREAD_TEST)) && (!defined(_MSC_VER) || defined(UNDER_CE))
 
     /*
     This file is a "null" implementation of tss cleanup; it's

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -2,11 +2,14 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 // (C) Copyright 2007 Anthony Williams
+// (C) Copyright 2007 David Deakins
 
 #include <boost/thread/thread.hpp>
 #include <algorithm>
 #include <windows.h>
+#ifndef UNDER_CE
 #include <process.h>
+#endif
 #include <stdio.h>
 #include <boost/thread/once.hpp>
 #include <boost/assert.hpp>
@@ -15,7 +18,7 @@
 {
     namespace
     {
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && !defined(UNDER_CE)
         __declspec(thread) detail::thread_data_base* current_thread_data=0;
         detail::thread_data_base* get_current_thread_data()
         {
@@ -59,6 +62,41 @@
             BOOST_ASSERT(res);
         }
 #endif
+
+#ifdef BOOST_NO_THREADEX
+// Windows CE doesn't define _beginthreadex
+
+ struct ThreadProxyData
+ {
+ typedef unsigned (__stdcall* func)(void*);
+ func start_address_;
+ void* arglist_;
+ ThreadProxyData(func start_address,void* arglist) : start_address_(start_address), arglist_(arglist) {}
+ };
+
+ DWORD WINAPI ThreadProxy(LPVOID args)
+ {
+ ThreadProxyData* data=reinterpret_cast<ThreadProxyData*>(args);
+ DWORD ret=data->start_address_(data->arglist_);
+ delete data;
+ return ret;
+ }
+
+ typedef void* uintptr_t;
+
+ inline uintptr_t const _beginthreadex(void* security, unsigned stack_size, unsigned (__stdcall* start_address)(void*),
+ void* arglist, unsigned initflag, unsigned* thrdaddr)
+ {
+ DWORD threadID;
+ HANDLE hthread=CreateThread(static_cast<LPSECURITY_ATTRIBUTES>(security),stack_size,ThreadProxy,
+ new ThreadProxyData(start_address,arglist),initflag,&threadID);
+ if (hthread!=0)
+ *thrdaddr=threadID;
+ return reinterpret_cast<uintptr_t const>(hthread);
+ }
+
+#endif
+
     }
 
     void thread::yield()
@@ -166,12 +204,9 @@
             externally_launched_thread()
             {
                 ++count;
+ cancel_enabled=false;
                 thread_handle=detail::win32::duplicate_handle(detail::win32::GetCurrentThread());
             }
- ~externally_launched_thread()
- {
- OutputDebugString("External thread finished\n");
- }
             
             void run()
             {}

Modified: trunk/libs/thread/src/win32/tss.cpp
==============================================================================
--- trunk/libs/thread/src/win32/tss.cpp (original)
+++ trunk/libs/thread/src/win32/tss.cpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -1,5 +1,7 @@
 // Copyright (C) 2001-2003 William E. Kempf
 // Copyright (C) 2006 Roland Schwarz
+// Copyright (C) 2007 Anthony Williams
+// Copyright (C) 2007 David Deakins
 //
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,9 +19,10 @@
 #include <stdexcept>
 #include <cassert>
 
-#if defined(BOOST_HAS_WINTHREADS)
-# include <windows.h>
-# include <boost/thread/detail/tss_hooks.hpp>
+#include <windows.h>
+#include <boost/thread/detail/tss_hooks.hpp>
+#if defined(UNDER_CE) && !defined(TLS_OUT_OF_INDEXES)
+# define TLS_OUT_OF_INDEXES 0xFFFFFFFF
 #endif
 
 namespace {
@@ -30,13 +33,7 @@
 boost::once_flag tss_data_once = BOOST_ONCE_INIT;
 boost::mutex* tss_data_mutex = 0;
 tss_data_cleanup_handlers_type* tss_data_cleanup_handlers = 0;
-#if defined(BOOST_HAS_WINTHREADS)
     DWORD tss_data_native_key=TLS_OUT_OF_INDEXES;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_key_t tss_data_native_key;
-#elif defined(BOOST_HAS_MPTASKS)
- TaskStorageIndex tss_data_native_key;
-#endif
 int tss_data_use = 0;
 
 void tss_data_inc_use(boost::mutex::scoped_lock& lk)
@@ -58,15 +55,8 @@
         lk.unlock();
         delete tss_data_mutex;
         tss_data_mutex = 0;
-#if defined(BOOST_HAS_WINTHREADS)
         TlsFree(tss_data_native_key);
         tss_data_native_key=TLS_OUT_OF_INDEXES;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_key_delete(tss_data_native_key);
-#elif defined(BOOST_HAS_MPTASKS)
- // Don't know what to put here.
- // But MPTASKS isn't currently maintained anyways...
-#endif
     }
 }
 
@@ -79,9 +69,7 @@
         (*(*tss_data_cleanup_handlers)[i])((*slots)[i]);
         (*slots)[i] = 0;
     }
-#if defined(BOOST_HAS_WINTHREADS)
     TlsSetValue(tss_data_native_key,0);
-#endif
     tss_data_dec_use(lock);
     delete slots;
 }
@@ -95,7 +83,6 @@
     if (temp_mutex.get() == 0)
         throw boost::thread_resource_error();
 
-#if defined(BOOST_HAS_WINTHREADS)
     //Force the cleanup implementation library to be linked in
     tss_cleanup_implemented();
 
@@ -103,15 +90,6 @@
     tss_data_native_key = TlsAlloc();
     if (tss_data_native_key == TLS_OUT_OF_INDEXES)
         return;
-#elif defined(BOOST_HAS_PTHREADS)
- int res = pthread_key_create(&tss_data_native_key, &cleanup_slots);
- if (res != 0)
- return;
-#elif defined(BOOST_HAS_MPTASKS)
- OSStatus status = MPAllocateTaskStorageIndex(&tss_data_native_key);
- if (status != noErr)
- return;
-#endif
 
     // The life time of cleanup handlers and mutex is beeing
     // managed by a reference counting technique.
@@ -123,7 +101,6 @@
     tss_data_mutex = temp_mutex.release();
 }
 
-#if defined(BOOST_HAS_WINTHREADS)
 tss_slots* get_slots(bool alloc);
 
 void __cdecl tss_thread_exit()
@@ -132,39 +109,22 @@
     if (slots)
         cleanup_slots(slots);
 }
-#endif
 
 tss_slots* get_slots(bool alloc)
 {
     tss_slots* slots = 0;
 
-#if defined(BOOST_HAS_WINTHREADS)
     slots = static_cast<tss_slots*>(
         TlsGetValue(tss_data_native_key));
-#elif defined(BOOST_HAS_PTHREADS)
- slots = static_cast<tss_slots*>(
- pthread_getspecific(tss_data_native_key));
-#elif defined(BOOST_HAS_MPTASKS)
- slots = static_cast<tss_slots*>(
- MPGetTaskStorageValue(tss_data_native_key));
-#endif
 
     if (slots == 0 && alloc)
     {
         std::auto_ptr<tss_slots> temp(new tss_slots);
 
-#if defined(BOOST_HAS_WINTHREADS)
         if (at_thread_exit(&tss_thread_exit) == -1)
             return 0;
         if (!TlsSetValue(tss_data_native_key, temp.get()))
             return 0;
-#elif defined(BOOST_HAS_PTHREADS)
- if (pthread_setspecific(tss_data_native_key, temp.get()) != 0)
- return 0;
-#elif defined(BOOST_HAS_MPTASKS)
- if (MPSetTaskStorageValue(tss_data_native_key, temp.get()) != noErr)
- return 0;
-#endif
         {
             boost::mutex::scoped_lock lock(*tss_data_mutex);
             tss_data_inc_use(lock);

Modified: trunk/libs/thread/src/win32/tss_hooks.cpp
==============================================================================
--- trunk/libs/thread/src/win32/tss_hooks.cpp (original)
+++ trunk/libs/thread/src/win32/tss_hooks.cpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -1,5 +1,7 @@
 // Copyright (C) 2004 Michael Glassford
 // Copyright (C) 2006 Roland Schwarz
+// Copyright (C) 2007 Anthony Williams
+// Copyright (C) 2007 David Deakins
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -19,6 +21,10 @@
     #define WIN32_LEAN_AND_MEAN
     #include <windows.h>
 
+# if defined(UNDER_CE) && !defined(TLS_OUT_OF_INDEXES)
+# define TLS_OUT_OF_INDEXES 0xFFFFFFFF
+# endif
+
     namespace
     {
         class CScopedCSLock

Modified: trunk/libs/thread/src/win32/tss_pe.cpp
==============================================================================
--- trunk/libs/thread/src/win32/tss_pe.cpp (original)
+++ trunk/libs/thread/src/win32/tss_pe.cpp 2007-11-02 05:17:02 EDT (Fri, 02 Nov 2007)
@@ -1,11 +1,13 @@
 // (C) Copyright Aaron W. LaFramboise, Roland Schwarz, Michael Glassford 2004.
+// (C) Copyright 2007 Anthony Williams
+// (C) Copyright 2007 David Deakins
 // Use, modification and distribution are subject to the
 // Boost Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #include <boost/thread/detail/config.hpp>
 
-#if defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB) && defined(_MSC_VER)
+#if defined(BOOST_THREAD_BUILD_LIB) && defined(_MSC_VER) && !defined(UNDER_CE)
 
     #include <boost/thread/detail/tss_hooks.hpp>
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk