LCOV - code coverage report
Current view: top level - include/osl - conditn.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 16 16 100.0 %
Date: 2014-11-03 Functions: 6 6 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             : #ifndef INCLUDED_OSL_CONDITN_HXX
      21             : #define INCLUDED_OSL_CONDITN_HXX
      22             : 
      23             : #ifdef __cplusplus
      24             : 
      25             : #include <osl/time.h>
      26             : 
      27             : #include <osl/conditn.h>
      28             : 
      29             : 
      30             : namespace osl
      31             : {
      32             :     /**
      33             :      * Warning: the Condition abstraction is inadequate for any
      34             :      * situation where there may be multiple threads setting,
      35             :      * waiting, and resetting the same condition. It can only be
      36             :      * used to synchronise interactions between two threads
      37             :      * cf. lost wakeups in:
      38             :      *    http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
      39             :      */
      40             :     class Condition
      41             :     {
      42             :     public:
      43             : 
      44             :         enum Result
      45             :         {
      46             :             result_ok      = osl_cond_result_ok,
      47             :             result_error   = osl_cond_result_error,
      48             :             result_timeout = osl_cond_result_timeout
      49             :         };
      50             : 
      51             :         /* Create a condition.
      52             :          */
      53      291950 :         Condition()
      54             :         {
      55      291950 :             condition = osl_createCondition();
      56      291950 :         }
      57             : 
      58             :         /* Release the OS-structures and free condition data-structure.
      59             :          */
      60      291544 :         ~Condition()
      61             :         {
      62      291544 :             osl_destroyCondition(condition);
      63      291544 :         }
      64             : 
      65             :         /* Release all waiting threads, check returns true.
      66             :          */
      67     2311607 :         void set()
      68             :         {
      69     2311607 :             osl_setCondition(condition);
      70     2311607 :         }
      71             : 
      72             :         /* Reset condition to false: wait() will block, check() returns false.
      73             :          */
      74     2103990 :         void reset() {
      75     2103990 :             osl_resetCondition(condition);
      76     2103990 :         }
      77             : 
      78             :         /** Blocks the calling thread until condition is set.
      79             :          */
      80      731900 :         Result wait(const TimeValue *pTimeout = 0)
      81             :         {
      82      731900 :             return (Result) osl_waitCondition(condition, pTimeout);
      83             :         }
      84             : 
      85             :         /** Checks if the condition is set without blocking.
      86             :          */
      87     2382926 :         bool check()
      88             :         {
      89     2382926 :             return osl_checkCondition(condition);
      90             :         }
      91             : 
      92             : 
      93             :     private:
      94             :         oslCondition condition;
      95             : 
      96             :         /** The underlying oslCondition has no reference count.
      97             : 
      98             :         Since the underlying oslCondition is not a reference counted object, copy
      99             :         constructed Condition may work on an already destructed oslCondition object.
     100             : 
     101             :         */
     102             :         Condition(const Condition&);
     103             : 
     104             :         /** The underlying oslCondition has no reference count.
     105             : 
     106             :         When destructed, the Condition object destroys the undelying oslCondition,
     107             :         which might cause severe problems in case it's a temporary object.
     108             : 
     109             :         */
     110             :         Condition(oslCondition condition);
     111             : 
     112             :         /** This assignment operator is private for the same reason as
     113             :             the copy constructor.
     114             :         */
     115             :         Condition& operator= (const Condition&);
     116             : 
     117             :         /** This assignment operator is private for the same reason as
     118             :             the constructor taking a oslCondition argument.
     119             :         */
     120             :         Condition& operator= (oslCondition);
     121             :     };
     122             : 
     123             : }
     124             : 
     125             : #endif  /* __cplusplus */
     126             : #endif // INCLUDED_OSL_CONDITN_HXX
     127             : 
     128             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10