diff options
author | Andreas Bille <abi@openoffice.org> | 2002-06-20 13:49:21 +0000 |
---|---|---|
committer | Andreas Bille <abi@openoffice.org> | 2002-06-20 13:49:21 +0000 |
commit | 77f7fbd6ebeab675be6bd1108d89fdbcacdb453b (patch) | |
tree | 397eac7962163db8188be61661e51e42b8b55956 /ucb/source/ucp/ftp/ftploaderthread.cxx | |
parent | f41a382dbaba620c8c03829a255afe247b2b96af (diff) |
Changed to oslThreadKey and partners
Diffstat (limited to 'ucb/source/ucp/ftp/ftploaderthread.cxx')
-rw-r--r-- | ucb/source/ucp/ftp/ftploaderthread.cxx | 128 |
1 files changed, 21 insertions, 107 deletions
diff --git a/ucb/source/ucp/ftp/ftploaderthread.cxx b/ucb/source/ucp/ftp/ftploaderthread.cxx index 0298f4a54ea5..fb97f893efb4 100644 --- a/ucb/source/ucp/ftp/ftploaderthread.cxx +++ b/ucb/source/ucp/ftp/ftploaderthread.cxx @@ -9,24 +9,25 @@ using namespace ftp; - /********************************************************************************/ /* */ -/* the joiner */ +/* cleanup function for thread specific data */ /* */ /********************************************************************************/ -static void ftploaderthread_terminater(void *pData) -{ - FtpLoaderThread* pLoaderThread = static_cast<FtpLoaderThread*>(pData); - oslThreadIdentifier threaId(pLoaderThread->threadId()); -// oslThread aThread = osl_getThreadFromIdentifier(threaId); -// osl_joinWithThread(aThread); -// FtpLoaderThread::remove(threaId); -} +#ifdef __cplusplus +extern "C" { +#endif + void delete_CURL(void *pData) + { + curl_easy_cleanup(static_cast<CURL*>(pData)); + } +#ifdef __cplusplus +} +#endif /********************************************************************************/ @@ -37,112 +38,25 @@ static void ftploaderthread_terminater(void *pData) FtpLoaderThread::FtpLoaderThread() - : m_nThreadId(osl_getThreadIdentifier(NULL)), - m_pHandle(NULL) -{ -} - - -FtpLoaderThread::FtpLoaderThread(oslThreadIdentifier nThreadId) - : m_nThreadId(nThreadId), - m_pHandle(NULL) -{ -} - - -FtpLoaderThread::FtpLoaderThread(const FtpLoaderThread& r) -{ - m_nThreadId = r.m_nThreadId; - m_pHandle = r.m_pHandle; - r.m_pHandle = NULL; -} - - -FtpLoaderThread& FtpLoaderThread::operator=(const FtpLoaderThread& r) -{ - m_nThreadId = r.m_nThreadId; - m_pHandle = r.m_pHandle; - r.m_pHandle = NULL; - return *this; -} - - -FtpLoaderThread::~FtpLoaderThread() -{ - if(m_pHandle) - curl_easy_cleanup(m_pHandle); -} - - -bool FtpLoaderThread::operator==(const FtpLoaderThread& r) const -{ - return m_nThreadId == r.threadId(); + : m_threadKey(osl_createThreadKey(delete_CURL)) { } -oslThreadIdentifier FtpLoaderThread::threadId() const -{ - return m_nThreadId; -} - -void FtpLoaderThread::init() const -{ - m_pHandle = curl_easy_init(); - osl_createThread(ftploaderthread_terminater,(void*)this); +FtpLoaderThread::~FtpLoaderThread() { + osl_destroyThreadKey(m_threadKey); } -/********************************************************************************/ -/* */ -/* FtpLoaderThreadHashSet */ -/* */ -/********************************************************************************/ - - - -size_t FtpLoaderThreadHash::operator()(const FtpLoaderThread& p) const -{ - return size_t(p.threadId()); -} - - - -/********************************************************************************/ -/* */ -/* Static part of FtpLoaderThread */ -/* */ -/********************************************************************************/ - -osl::Mutex FtpLoaderThread::ftploader_mutex; - - -FtpLoaderThread::FtpLoaderThreadSet FtpLoaderThread::ftploaderthread_set; - - - -CURL* FtpLoaderThread::curlHandle() -{ - osl::MutexGuard aGuard(ftploader_mutex); - - if(ftploaderthread_set.empty()) - curl_global_init(CURL_GLOBAL_DEFAULT); - - FtpLoaderThread loader; - std::pair<FtpLoaderThreadSet::iterator,bool> p(ftploaderthread_set.insert(loader)); - if(p.second) - p.first->init(); - return p.first->m_pHandle; -} - -void FtpLoaderThread::remove(oslThreadIdentifier nThreadId) -{ - osl::MutexGuard aGuard(ftploader_mutex); +CURL* FtpLoaderThread::handle() { + CURL* ret; + if(!(ret = osl_getThreadKeyData(m_threadKey))) { + ret = curl_easy_init(); + osl_setThreadKeyData(m_threadKey,static_cast<void*>(ret)); + } - ftploaderthread_set.erase(FtpLoaderThread(nThreadId)); - if(ftploaderthread_set.empty()) - curl_global_cleanup(); + return ret; } |