fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / cppu / source / threadpool / threadident.cxx
blobdcf6d1fe9475499c8dcab8888bb5ee7471d636cb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <list>
22 #include <osl/mutex.hxx>
23 #include <osl/thread.hxx>
24 #include <osl/diagnose.h>
26 #include <rtl/process.h>
27 #include <rtl/byteseq.hxx>
29 #include <uno/threadpool.h>
31 #include "current.hxx"
34 using namespace ::std;
35 using namespace ::osl;
36 using namespace ::cppu;
39 static inline void createLocalId( sal_Sequence **ppThreadId )
41 rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 );
42 sal_uInt32 id = osl::Thread::getCurrentIdentifier();
43 (*ppThreadId)->elements[0] = id & 0xFF;
44 (*ppThreadId)->elements[1] = (id >> 8) & 0xFF;
45 (*ppThreadId)->elements[2] = (id >> 16) & 0xFF;
46 (*ppThreadId)->elements[3] = (id >> 24) & 0xFF;
47 rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8 *>(&(*ppThreadId)->elements[4]) );
51 extern "C" void SAL_CALL
52 uno_getIdOfCurrentThread( sal_Sequence **ppThreadId )
53 SAL_THROW_EXTERN_C()
55 IdContainer * p = getIdContainer();
56 if( ! p->bInit )
58 // first time, that the thread enters the bridge
59 createLocalId( ppThreadId );
61 // TODO
62 // note : this is a leak !
63 p->pLocalThreadId = *ppThreadId;
64 p->pCurrentId = *ppThreadId;
65 p->nRefCountOfCurrentId = 1;
66 rtl_byte_sequence_acquire( p->pLocalThreadId );
67 rtl_byte_sequence_acquire( p->pCurrentId );
68 p->bInit = true;
70 else
72 p->nRefCountOfCurrentId ++;
73 if( *ppThreadId )
75 rtl_byte_sequence_release( *ppThreadId );
77 *ppThreadId = p->pCurrentId;
78 rtl_byte_sequence_acquire( *ppThreadId );
83 extern "C" void SAL_CALL uno_releaseIdFromCurrentThread()
84 SAL_THROW_EXTERN_C()
86 IdContainer *p = getIdContainer();
87 OSL_ASSERT( p );
88 OSL_ASSERT( p->nRefCountOfCurrentId );
90 p->nRefCountOfCurrentId --;
91 if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) )
93 rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId );
97 extern "C" sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId )
98 SAL_THROW_EXTERN_C()
100 IdContainer *p = getIdContainer();
101 if( ! p->bInit )
103 p->pLocalThreadId = 0;
104 createLocalId( &(p->pLocalThreadId) );
105 p->nRefCountOfCurrentId = 1;
106 p->pCurrentId = pThreadId;
107 rtl_byte_sequence_acquire( p->pCurrentId );
108 p->bInit = true;
110 else
112 OSL_ASSERT( 0 == p->nRefCountOfCurrentId );
113 if( 0 == p->nRefCountOfCurrentId )
115 rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId );
116 p->nRefCountOfCurrentId ++;
118 else
120 return sal_False;
124 return sal_True;
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */