os/textandloc/fontservices/textshaperplugin/IcuSource/common/mutex.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/mutex.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1997-2003, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +******************************************************************************
    1.11 +*/
    1.12 +//----------------------------------------------------------------------------
    1.13 +// File:     mutex.h
    1.14 +//
    1.15 +// Lightweight C++ wrapper for umtx_ C mutex functions
    1.16 +//
    1.17 +// Author:   Alan Liu  1/31/97
    1.18 +// History:
    1.19 +// 06/04/97   helena         Updated setImplementation as per feedback from 5/21 drop.
    1.20 +// 04/07/1999  srl               refocused as a thin wrapper
    1.21 +//
    1.22 +//----------------------------------------------------------------------------
    1.23 +#ifndef MUTEX_H
    1.24 +#define MUTEX_H
    1.25 +
    1.26 +#include "unicode/utypes.h"
    1.27 +#include "unicode/uobject.h"
    1.28 +#include "umutex.h"
    1.29 +
    1.30 +U_NAMESPACE_BEGIN
    1.31 +
    1.32 +//----------------------------------------------------------------------------
    1.33 +// Code within that accesses shared static or global data should
    1.34 +// should instantiate a Mutex object while doing so. You should make your own 
    1.35 +// private mutex where possible.
    1.36 +
    1.37 +// For example:
    1.38 +// 
    1.39 +// UMTX myMutex;
    1.40 +// 
    1.41 +// int InitializeMyMutex()
    1.42 +// {
    1.43 +//    umtx_init( &myMutex );
    1.44 +//    return 0;
    1.45 +// }
    1.46 +// 
    1.47 +// static int initializeMyMutex = InitializeMyMutex();
    1.48 +//
    1.49 +// void Function(int arg1, int arg2)
    1.50 +// {
    1.51 +//    static Object* foo;     // Shared read-write object
    1.52 +//    Mutex mutex(&myMutex);  // or no args for the global lock
    1.53 +//    foo->Method();
    1.54 +//    // When 'mutex' goes out of scope and gets destroyed here, the lock is released
    1.55 +// }
    1.56 +//
    1.57 +// Note:  Do NOT use the form 'Mutex mutex();' as that merely forward-declares a function
    1.58 +//        returning a Mutex. This is a common mistake which silently slips through the
    1.59 +//        compiler!!
    1.60 +//
    1.61 +
    1.62 +class U_COMMON_API Mutex : public UMemory {
    1.63 +public:
    1.64 +  inline Mutex(UMTX *mutex = NULL);
    1.65 +  inline ~Mutex();
    1.66 +
    1.67 +private:
    1.68 +  UMTX   *fMutex;
    1.69 +
    1.70 +  Mutex(const Mutex &other); // forbid copying of this class
    1.71 +  Mutex &operator=(const Mutex &other); // forbid copying of this class
    1.72 +};
    1.73 +
    1.74 +inline Mutex::Mutex(UMTX *mutex)
    1.75 +  : fMutex(mutex)
    1.76 +{
    1.77 +  umtx_lock(fMutex);
    1.78 +}
    1.79 +
    1.80 +inline Mutex::~Mutex()
    1.81 +{
    1.82 +  umtx_unlock(fMutex);
    1.83 +}
    1.84 +
    1.85 +U_NAMESPACE_END
    1.86 +
    1.87 +#endif //_MUTEX_
    1.88 +//eof