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

Generated by: LCOV version 1.11