src/thread/riscos/SDL_systhread.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1402 d910939febfa
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
slouken@955
     1
/*
slouken@955
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@955
     4
slouken@955
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@955
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@955
     9
slouken@955
    10
    This library is distributed in the hope that it will be useful,
slouken@955
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@955
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@955
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@955
    18
slouken@955
    19
    Sam Lantinga
slouken@955
    20
    slouken@libsdl.org
slouken@955
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@955
    23
slouken@955
    24
/* RISC OS version based on pthreads linux source */
slouken@955
    25
slouken@955
    26
#include "SDL_thread.h"
slouken@1361
    27
#include "../SDL_systhread.h"
slouken@955
    28
slouken@1361
    29
#if SDL_THREADS_DISABLED
slouken@955
    30
slouken@1662
    31
int
slouken@1662
    32
SDL_SYS_CreateThread (SDL_Thread * thread, void *args)
slouken@955
    33
{
slouken@1662
    34
    SDL_SetError
slouken@1662
    35
        ("Threads have not been compiled into this version of the library");
slouken@1662
    36
    return (-1);
slouken@955
    37
}
slouken@955
    38
slouken@1662
    39
void
slouken@1662
    40
SDL_SYS_SetupThread (void)
slouken@955
    41
{
slouken@1662
    42
    return;
slouken@955
    43
}
slouken@955
    44
slouken@1662
    45
Uint32
slouken@1662
    46
SDL_ThreadID (void)
slouken@955
    47
{
slouken@1662
    48
    return (0);
slouken@955
    49
}
slouken@955
    50
slouken@1662
    51
void
slouken@1662
    52
SDL_SYS_WaitThread (SDL_Thread * thread)
slouken@955
    53
{
slouken@1662
    54
    return;
slouken@955
    55
}
slouken@955
    56
slouken@1662
    57
void
slouken@1662
    58
SDL_SYS_KillThread (SDL_Thread * thread)
slouken@955
    59
{
slouken@1662
    60
    return;
slouken@955
    61
}
slouken@955
    62
slouken@955
    63
#else
slouken@955
    64
slouken@955
    65
#include <signal.h>
slouken@955
    66
slouken@955
    67
/* List of signals to mask in the subthreads */
slouken@955
    68
static int sig_list[] = {
slouken@1662
    69
    SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
slouken@1662
    70
    SIGVTALRM, SIGPROF, 0
slouken@955
    71
};
slouken@955
    72
slouken@955
    73
#include <pthread.h>
slouken@955
    74
slouken@955
    75
int riscos_using_threads = 0;
slouken@1662
    76
Uint32 riscos_main_thread = 0;  /* Thread running events */
slouken@955
    77
slouken@1662
    78
static void *
slouken@1662
    79
RunThread (void *data)
slouken@955
    80
{
slouken@1662
    81
    SDL_RunThread (data);
slouken@1662
    82
    pthread_exit ((void *) 0);
slouken@1662
    83
    return ((void *) 0);        /* Prevent compiler warning */
slouken@955
    84
}
slouken@955
    85
slouken@1662
    86
int
slouken@1662
    87
SDL_SYS_CreateThread (SDL_Thread * thread, void *args)
slouken@955
    88
{
slouken@1662
    89
    pthread_attr_t type;
slouken@955
    90
slouken@1662
    91
    /* Set the thread attributes */
slouken@1662
    92
    if (pthread_attr_init (&type) != 0) {
slouken@1662
    93
        SDL_SetError ("Couldn't initialize pthread attributes");
slouken@1662
    94
        return (-1);
slouken@1662
    95
    }
slouken@1662
    96
    pthread_attr_setdetachstate (&type, PTHREAD_CREATE_JOINABLE);
slouken@955
    97
slouken@1662
    98
    /* Create the thread and go! */
slouken@1662
    99
    if (pthread_create (&thread->handle, &type, RunThread, args) != 0) {
slouken@1662
   100
        SDL_SetError ("Not enough resources to create thread");
slouken@1662
   101
        return (-1);
slouken@1662
   102
    }
slouken@955
   103
slouken@1662
   104
    if (riscos_using_threads == 0) {
slouken@1662
   105
        riscos_using_threads = 1;
slouken@1662
   106
        riscos_main_thread = SDL_ThreadID ();
slouken@1662
   107
    }
slouken@1662
   108
slouken@1662
   109
    return (0);
slouken@955
   110
}
slouken@955
   111
slouken@1662
   112
void
slouken@1662
   113
SDL_SYS_SetupThread (void)
slouken@955
   114
{
slouken@1662
   115
    int i;
slouken@1662
   116
    sigset_t mask;
slouken@955
   117
slouken@1662
   118
    /* Mask asynchronous signals for this thread */
slouken@1662
   119
    sigemptyset (&mask);
slouken@1662
   120
    for (i = 0; sig_list[i]; ++i) {
slouken@1662
   121
        sigaddset (&mask, sig_list[i]);
slouken@1662
   122
    }
slouken@1662
   123
    pthread_sigmask (SIG_BLOCK, &mask, 0);
slouken@1662
   124
slouken@955
   125
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
slouken@1662
   126
    /* Allow ourselves to be asynchronously cancelled */
slouken@1662
   127
    {
slouken@1662
   128
        int oldstate;
slouken@1662
   129
        pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
slouken@1662
   130
    }
slouken@955
   131
#endif
slouken@955
   132
}
slouken@955
   133
slouken@1662
   134
Uint32
slouken@1662
   135
SDL_ThreadID (void)
slouken@955
   136
{
slouken@1662
   137
    return ((Uint32) pthread_self ());
slouken@955
   138
}
slouken@955
   139
slouken@1662
   140
void
slouken@1662
   141
SDL_SYS_WaitThread (SDL_Thread * thread)
slouken@955
   142
{
slouken@1662
   143
    pthread_join (thread->handle, 0);
slouken@955
   144
}
slouken@955
   145
slouken@1662
   146
void
slouken@1662
   147
SDL_SYS_KillThread (SDL_Thread * thread)
slouken@955
   148
{
slouken@955
   149
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
slouken@1662
   150
    pthread_cancel (thread->handle);
slouken@955
   151
#else
slouken@1662
   152
    pthread_kill (thread->handle, SIGKILL);
slouken@955
   153
#endif
slouken@955
   154
}
slouken@955
   155
slouken@955
   156
#endif
slouken@1662
   157
/* vi: set ts=4 sw=4 expandtab: */