src/thread/pth/SDL_syscond.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 10 Jan 2010 05:06:03 +0000
changeset 3623 9a73fecd9181
parent 2859 99210400e8b9
permissions -rw-r--r--
Reverted r5460 ... this was merged from 1.2, but was later reverted there.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     1
/*
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     2
    SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     4
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     5
    This library is free software; you can redistribute it and/or
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     7
    License as published by the Free Software Foundation; either
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
     9
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    10
    This library is distributed in the hope that it will be useful,
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    13
    Lesser General Public License for more details.
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    14
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    16
    License along with this library; if not, write to the Free Software
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    18
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    19
    Sam Lantinga
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    20
    slouken@libsdl.org
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    21
*/
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    22
#include "SDL_config.h"
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    23
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
/*
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
 *	GNU pth conditions variables
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
 *
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
 *	Patrice Mandin
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
 */
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include <pth.h>
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "SDL_thread.h"
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_sysmutex_c.h"
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    35
struct SDL_cond
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    36
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    37
    pth_cond_t condpth_p;
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    38
};
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    39
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
/* Create a condition variable */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    41
SDL_cond *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    42
SDL_CreateCond(void)
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    44
    SDL_cond *cond;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    46
    cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    47
    if (cond) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    48
        if (pth_cond_init(&(cond->condpth_p)) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    49
            SDL_SetError("pthread_cond_init() failed");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    50
            SDL_free(cond);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    51
            cond = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    52
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    53
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    54
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    55
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    56
    return (cond);
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
}
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
/* Destroy a condition variable */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    60
void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    61
SDL_DestroyCond(SDL_cond * cond)
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    63
    if (cond) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    64
        SDL_free(cond);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    65
    }
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
}
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
/* Restart one of the threads that are waiting on the condition variable */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    69
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    70
SDL_CondSignal(SDL_cond * cond)
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    72
    int retval;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    74
    if (!cond) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    75
        SDL_SetError("Passed a NULL condition variable");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    76
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    77
    }
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    79
    retval = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    80
    if (pth_cond_notify(&(cond->condpth_p), FALSE) != 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    81
        SDL_SetError("pth_cond_notify() failed");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    82
        retval = -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    83
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    84
    return retval;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
}
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
/* Restart all threads that are waiting on the condition variable */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    88
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    89
SDL_CondBroadcast(SDL_cond * cond)
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    91
    int retval;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    93
    if (!cond) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    94
        SDL_SetError("Passed a NULL condition variable");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    95
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    96
    }
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    98
    retval = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    99
    if (pth_cond_notify(&(cond->condpth_p), TRUE) != 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   100
        SDL_SetError("pth_cond_notify() failed");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   101
        retval = -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   102
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   103
    return retval;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
}
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
/* Wait on the condition variable for at most 'ms' milliseconds.
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
   The mutex must be locked before entering this function!
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
   The mutex is unlocked during the wait, and locked again after the wait.
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
Typical use:
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
Thread A:
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
	SDL_LockMutex(lock);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
	while ( ! condition ) {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
		SDL_CondWait(cond);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
	}
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
	SDL_UnlockMutex(lock);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
Thread B:
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
	SDL_LockMutex(lock);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
	...
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
	condition = true;
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
	...
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
	SDL_UnlockMutex(lock);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   126
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   127
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   129
    int retval;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   130
    pth_event_t ev;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   131
    int sec;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   133
    if (!cond) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   134
        SDL_SetError("Passed a NULL condition variable");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   135
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   136
    }
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   138
    retval = 0;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   140
    sec = ms / 1000;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   141
    ev = pth_event(PTH_EVENT_TIME,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   142
                   pth_timeout(sec, (ms - sec * 1000) * 1000));
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   144
    if (pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   145
        SDL_SetError("pth_cond_await() failed");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   146
        retval = -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   147
    }
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
    pth_event_free(ev, PTH_FREE_ALL);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   151
    return retval;
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
}
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
/* Wait on the condition variable forever */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   155
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   156
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   158
    int retval;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   159
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   160
    if (!cond) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   161
        SDL_SetError("Passed a NULL condition variable");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   162
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   163
    }
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   165
    retval = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   166
    if (pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   167
        SDL_SetError("pth_cond_await() failed");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   168
        retval = -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   169
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   170
    return retval;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   171
}
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   173
/* vi: set ts=4 sw=4 expandtab: */