src/cdrom/macosx/SDLOSXCAGuard.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 09 Mar 2006 06:33:21 +0000
changeset 1487 dc6b59e925a2
parent 1402 d910939febfa
child 1662 782fd950bd46
child 1895 c121d94672cb
child 4159 a1b03ba2fcd0
permissions -rw-r--r--
Cleaning up warnings on MacOS X
icculus@1143
     1
/*
icculus@1143
     2
    SDL - Simple DirectMedia Layer
icculus@1143
     3
    Copyright (C) 1997-2004 Sam Lantinga
icculus@1143
     4
icculus@1143
     5
    This library is free software; you can redistribute it and/or
icculus@1143
     6
    modify it under the terms of the GNU Library General Public
icculus@1143
     7
    License as published by the Free Software Foundation; either
icculus@1143
     8
    version 2 of the License, or (at your option) any later version.
icculus@1143
     9
icculus@1143
    10
    This library is distributed in the hope that it will be useful,
icculus@1143
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
icculus@1143
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
icculus@1143
    13
    Library General Public License for more details.
icculus@1143
    14
icculus@1143
    15
    You should have received a copy of the GNU Library General Public
icculus@1143
    16
    License along with this library; if not, write to the Free
icculus@1143
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
icculus@1143
    18
icculus@1143
    19
    Sam Lantinga
icculus@1143
    20
    slouken@libsdl.org
icculus@1143
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@1402
    23
icculus@1143
    24
/*  
icculus@1143
    25
    Note: This file hasn't been modified so technically we have to keep the disclaimer :-(
icculus@1143
    26
icculus@1143
    27
icculus@1143
    28
    Copyright:  © Copyright 2002 Apple Computer, Inc. All rights reserved.
icculus@1143
    29
icculus@1143
    30
    Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
icculus@1143
    31
            ("Apple") in consideration of your agreement to the following terms, and your
icculus@1143
    32
            use, installation, modification or redistribution of this Apple software
icculus@1143
    33
            constitutes acceptance of these terms.  If you do not agree with these terms,
icculus@1143
    34
            please do not use, install, modify or redistribute this Apple software.
icculus@1143
    35
icculus@1143
    36
            In consideration of your agreement to abide by the following terms, and subject
icculus@1143
    37
            to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
icculus@1143
    38
            copyrights in this original Apple software (the "Apple Software"), to use,
icculus@1143
    39
            reproduce, modify and redistribute the Apple Software, with or without
icculus@1143
    40
            modifications, in source and/or binary forms; provided that if you redistribute
icculus@1143
    41
            the Apple Software in its entirety and without modifications, you must retain
icculus@1143
    42
            this notice and the following text and disclaimers in all such redistributions of
icculus@1143
    43
            the Apple Software.  Neither the name, trademarks, service marks or logos of
icculus@1143
    44
            Apple Computer, Inc. may be used to endorse or promote products derived from the
icculus@1143
    45
            Apple Software without specific prior written permission from Apple.  Except as
icculus@1143
    46
            expressly stated in this notice, no other rights or licenses, express or implied,
icculus@1143
    47
            are granted by Apple herein, including but not limited to any patent rights that
icculus@1143
    48
            may be infringed by your derivative works or by other works in which the Apple
icculus@1143
    49
            Software may be incorporated.
icculus@1143
    50
icculus@1143
    51
            The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
icculus@1143
    52
            WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
icculus@1143
    53
            WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
icculus@1143
    54
            PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
icculus@1143
    55
            COMBINATION WITH YOUR PRODUCTS.
icculus@1143
    56
icculus@1143
    57
            IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
icculus@1143
    58
            CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
icculus@1143
    59
            GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
icculus@1143
    60
            ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
icculus@1143
    61
            OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
icculus@1143
    62
            (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
icculus@1143
    63
            ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
icculus@1143
    64
*/
icculus@1143
    65
/*=============================================================================
icculus@1143
    66
    CAGuard.h
icculus@1143
    67
icculus@1143
    68
=============================================================================*/
icculus@1143
    69
#if !defined(__CAGuard_h__)
icculus@1143
    70
#define __CAGuard_h__
icculus@1143
    71
slouken@1487
    72
/*=============================================================================
slouken@1487
    73
    Includes
slouken@1487
    74
  =============================================================================*/
icculus@1143
    75
icculus@1143
    76
#include <CoreAudio/CoreAudioTypes.h>
icculus@1143
    77
#include <pthread.h>
icculus@1143
    78
icculus@1143
    79
slouken@1487
    80
/*=============================================================================
slouken@1487
    81
    CAGuard
slouken@1487
    82
  
slouken@1487
    83
    This is your typical mutex with signalling implemented via pthreads.
slouken@1487
    84
    Lock() will return true if and only if the guard is locked on that call.
slouken@1487
    85
    A thread that already has the guard will receive 'false' if it locks it
slouken@1487
    86
    again. Use of the stack-based CAGuard::Locker class is highly recommended
slouken@1487
    87
    to properly manage the recursive nesting. The Wait calls with timeouts
slouken@1487
    88
    will return true if and only if the timeout period expired. They will
slouken@1487
    89
    return false if they receive notification any other way.
slouken@1487
    90
  =============================================================================*/
icculus@1143
    91
icculus@1143
    92
typedef struct S_SDLOSXCAGuard
icculus@1143
    93
{
icculus@1143
    94
slouken@1487
    95
/*  Construction/Destruction */
slouken@1487
    96
/*public:*/
slouken@1487
    97
/*  Actions */
slouken@1487
    98
/*public:*/
icculus@1143
    99
    int     (*Lock)(struct S_SDLOSXCAGuard *cag);
icculus@1143
   100
    void    (*Unlock)(struct S_SDLOSXCAGuard *cag);
slouken@1487
   101
    int     (*Try)(struct S_SDLOSXCAGuard *cag, int *outWasLocked);    /* returns true if lock is free, false if not */
icculus@1143
   102
    void    (*Wait)(struct S_SDLOSXCAGuard *cag);
icculus@1143
   103
    void    (*Notify)(struct S_SDLOSXCAGuard *cag);
icculus@1143
   104
slouken@1487
   105
/*  Implementation */
slouken@1487
   106
/*protected:*/
icculus@1143
   107
    pthread_mutex_t mMutex;
icculus@1143
   108
    pthread_cond_t  mCondVar;
icculus@1143
   109
    pthread_t       mOwner;
icculus@1143
   110
} SDLOSXCAGuard;
icculus@1143
   111
icculus@1143
   112
SDLOSXCAGuard *new_SDLOSXCAGuard(void);
icculus@1143
   113
void delete_SDLOSXCAGuard(SDLOSXCAGuard *cag);
icculus@1143
   114
icculus@1143
   115
#endif
icculus@1143
   116