LCOV - code coverage report
Current view: top level - cppu/source/threadpool - threadident.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 45 95.6 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <list>
      21             : 
      22             : #include <osl/mutex.hxx>
      23             : #include <osl/thread.hxx>
      24             : #include <osl/diagnose.h>
      25             : 
      26             : #include <rtl/process.h>
      27             : #include <rtl/byteseq.hxx>
      28             : 
      29             : #include <uno/threadpool.h>
      30             : 
      31             : #include "current.hxx"
      32             : 
      33             : 
      34             : using namespace ::std;
      35             : using namespace ::osl;
      36             : using namespace ::cppu;
      37             : 
      38             : 
      39         860 : static inline void createLocalId( sal_Sequence **ppThreadId )
      40             : {
      41         860 :     rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 );
      42         860 :     sal_uInt32 id = osl::Thread::getCurrentIdentifier();
      43         860 :     (*ppThreadId)->elements[0] = id & 0xFF;
      44         860 :     (*ppThreadId)->elements[1] = (id >> 8) & 0xFF;
      45         860 :     (*ppThreadId)->elements[2] = (id >> 16) & 0xFF;
      46         860 :     (*ppThreadId)->elements[3] = (id >> 24) & 0xFF;
      47         860 :     rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8 *>(&(*ppThreadId)->elements[4]) );
      48         860 : }
      49             : 
      50             : 
      51             : extern "C" void SAL_CALL
      52       30898 : uno_getIdOfCurrentThread( sal_Sequence **ppThreadId )
      53             :     SAL_THROW_EXTERN_C()
      54             : {
      55       30898 :     IdContainer * p = getIdContainer();
      56       30898 :     if( ! p->bInit )
      57             :     {
      58             :         // first time, that the thread enters the bridge
      59          40 :         createLocalId( ppThreadId );
      60             : 
      61             :         // TODO
      62             :         // note : this is a leak !
      63          40 :         p->pLocalThreadId = *ppThreadId;
      64          40 :         p->pCurrentId = *ppThreadId;
      65          40 :         p->nRefCountOfCurrentId = 1;
      66          40 :         rtl_byte_sequence_acquire( p->pLocalThreadId );
      67          40 :         rtl_byte_sequence_acquire( p->pCurrentId );
      68          40 :         p->bInit = true;
      69             :     }
      70             :     else
      71             :     {
      72       30858 :         p->nRefCountOfCurrentId ++;
      73       30858 :         if( *ppThreadId )
      74             :         {
      75           0 :             rtl_byte_sequence_release( *ppThreadId );
      76             :         }
      77       30858 :         *ppThreadId = p->pCurrentId;
      78       30858 :         rtl_byte_sequence_acquire( *ppThreadId );
      79             :     }
      80       30898 : }
      81             : 
      82             : 
      83      230931 : extern "C" void SAL_CALL uno_releaseIdFromCurrentThread()
      84             :     SAL_THROW_EXTERN_C()
      85             : {
      86      230931 :     IdContainer *p = getIdContainer();
      87             :     OSL_ASSERT( p );
      88             :     OSL_ASSERT( p->nRefCountOfCurrentId );
      89             : 
      90      230931 :     p->nRefCountOfCurrentId --;
      91      230931 :     if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) )
      92             :     {
      93      200033 :         rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId );
      94             :     }
      95      230931 : }
      96             : 
      97      200032 : extern "C" sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId )
      98             :     SAL_THROW_EXTERN_C()
      99             : {
     100      200032 :     IdContainer *p = getIdContainer();
     101      200033 :     if( ! p->bInit )
     102             :     {
     103         820 :         p->pLocalThreadId = 0;
     104         820 :         createLocalId( &(p->pLocalThreadId) );
     105         820 :         p->nRefCountOfCurrentId = 1;
     106         820 :         p->pCurrentId = pThreadId;
     107         820 :         rtl_byte_sequence_acquire( p->pCurrentId );
     108         820 :         p->bInit = true;
     109             :     }
     110             :     else
     111             :     {
     112             :         OSL_ASSERT( 0 == p->nRefCountOfCurrentId );
     113      199213 :         if( 0 == p->nRefCountOfCurrentId )
     114             :         {
     115      199213 :             rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId );
     116      199211 :             p->nRefCountOfCurrentId ++;
     117             :         }
     118             :         else
     119             :         {
     120           0 :             return sal_False;
     121             :         }
     122             : 
     123             :     }
     124      200031 :     return sal_True;
     125             : }
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11