LCOV - code coverage report
Current view: top level - cppu/source/threadpool - threadident.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 45 95.6 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 12 83.3 %

           Branch data     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 <stdio.h>
      21                 :            : 
      22                 :            : #include <list>
      23                 :            : 
      24                 :            : #include <osl/mutex.hxx>
      25                 :            : #include <osl/thread.h>
      26                 :            : #include <osl/diagnose.h>
      27                 :            : 
      28                 :            : #include <rtl/process.h>
      29                 :            : #include <rtl/byteseq.hxx>
      30                 :            : 
      31                 :            : #include <uno/threadpool.h>
      32                 :            : 
      33                 :            : #include "current.hxx"
      34                 :            : 
      35                 :            : 
      36                 :            : using namespace ::std;
      37                 :            : using namespace ::osl;
      38                 :            : using namespace ::rtl;
      39                 :            : using namespace ::cppu;
      40                 :            : 
      41                 :            : 
      42                 :       1639 : static inline void createLocalId( sal_Sequence **ppThreadId )
      43                 :            : {
      44                 :       1639 :     rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 );
      45                 :       1639 :     sal_uInt32 id = osl_getThreadIdentifier(0);
      46                 :       1639 :     (*ppThreadId)->elements[0] = id & 0xFF;
      47                 :       1639 :     (*ppThreadId)->elements[1] = (id >> 8) & 0xFF;
      48                 :       1639 :     (*ppThreadId)->elements[2] = (id >> 16) & 0xFF;
      49                 :       1639 :     (*ppThreadId)->elements[3] = (id >> 24) & 0xFF;
      50                 :       1639 :     rtl_getGlobalProcessId( (sal_uInt8 * ) &( (*ppThreadId)->elements[4]) );
      51                 :       1639 : }
      52                 :            : 
      53                 :            : 
      54                 :            : extern "C" void SAL_CALL
      55                 :      59170 : uno_getIdOfCurrentThread( sal_Sequence **ppThreadId )
      56                 :            :     SAL_THROW_EXTERN_C()
      57                 :            : {
      58                 :      59170 :     IdContainer * p = getIdContainer();
      59         [ +  + ]:      59170 :     if( ! p->bInit )
      60                 :            :     {
      61                 :            :         // first time, that the thread enters the bridge
      62                 :         54 :         createLocalId( ppThreadId );
      63                 :            : 
      64                 :            :         // TODO
      65                 :            :         // note : this is a leak !
      66                 :         54 :         p->pLocalThreadId = *ppThreadId;
      67                 :         54 :         p->pCurrentId = *ppThreadId;
      68                 :         54 :         p->nRefCountOfCurrentId = 1;
      69                 :         54 :         rtl_byte_sequence_acquire( p->pLocalThreadId );
      70                 :         54 :         rtl_byte_sequence_acquire( p->pCurrentId );
      71                 :         54 :         p->bInit = sal_True;
      72                 :            :     }
      73                 :            :     else
      74                 :            :     {
      75                 :      59116 :         p->nRefCountOfCurrentId ++;
      76         [ -  + ]:      59116 :         if( *ppThreadId )
      77                 :            :         {
      78                 :          0 :             rtl_byte_sequence_release( *ppThreadId );
      79                 :            :         }
      80                 :      59116 :         *ppThreadId = p->pCurrentId;
      81                 :      59116 :         rtl_byte_sequence_acquire( *ppThreadId );
      82                 :            :     }
      83                 :      59170 : }
      84                 :            : 
      85                 :            : 
      86                 :     315921 : extern "C" void SAL_CALL uno_releaseIdFromCurrentThread()
      87                 :            :     SAL_THROW_EXTERN_C()
      88                 :            : {
      89                 :     315921 :     IdContainer *p = getIdContainer();
      90                 :            :     OSL_ASSERT( p );
      91                 :            :     OSL_ASSERT( p->nRefCountOfCurrentId );
      92                 :            : 
      93                 :     315925 :     p->nRefCountOfCurrentId --;
      94 [ +  + ][ +  + ]:     315925 :     if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) )
      95                 :            :     {
      96                 :     256755 :         rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId );
      97                 :            :     }
      98                 :     315925 : }
      99                 :            : 
     100                 :     256755 : extern "C" sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId )
     101                 :            :     SAL_THROW_EXTERN_C()
     102                 :            : {
     103                 :     256755 :     IdContainer *p = getIdContainer();
     104         [ +  + ]:     256755 :     if( ! p->bInit )
     105                 :            :     {
     106                 :       1585 :         p->pLocalThreadId = 0;
     107                 :       1585 :         createLocalId( &(p->pLocalThreadId) );
     108                 :       1585 :         p->nRefCountOfCurrentId = 1;
     109                 :       1585 :         p->pCurrentId = pThreadId;
     110                 :       1585 :         rtl_byte_sequence_acquire( p->pCurrentId );
     111                 :       1585 :         p->bInit = sal_True;
     112                 :            :     }
     113                 :            :     else
     114                 :            :     {
     115                 :            :         OSL_ASSERT( 0 == p->nRefCountOfCurrentId );
     116         [ +  - ]:     255170 :         if( 0 == p->nRefCountOfCurrentId )
     117                 :            :         {
     118                 :     255170 :             rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId );
     119                 :     255170 :             p->nRefCountOfCurrentId ++;
     120                 :            :         }
     121                 :            :         else
     122                 :            :         {
     123                 :          0 :             return sal_False;
     124                 :            :         }
     125                 :            : 
     126                 :            :     }
     127                 :     256755 :     return sal_True;
     128                 :            : }
     129                 :            : 
     130                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10