SDL  2.0
testerror.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "SDL.h"
+ Include dependency graph for testerror.c:

Go to the source code of this file.

Functions

static void quit (int rc)
 
int ThreadFunc (void *data)
 
int main (int argc, char *argv[])
 

Variables

static int alive = 0
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 46 of file testerror.c.

References alive, NULL, quit(), SDL_CreateThread, SDL_Delay, SDL_GetError, SDL_Init, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_Quit, SDL_SetError, SDL_WaitThread, and ThreadFunc().

47 {
48  SDL_Thread *thread;
49 
50  /* Enable standard application logging */
52 
53  /* Load the SDL library */
54  if (SDL_Init(0) < 0) {
55  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
56  return (1);
57  }
58 
59  /* Set the error value for the main thread */
60  SDL_SetError("No worries");
61 
62  alive = 1;
63  thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
64  if (thread == NULL) {
65  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
66  quit(1);
67  }
68  SDL_Delay(5 * 1000);
69  SDL_Log("Waiting for thread #1\n");
70  alive = 0;
71  SDL_WaitThread(thread, NULL);
72 
73  SDL_Log("Main thread error string: %s\n", SDL_GetError());
74 
75  SDL_Quit();
76  return (0);
77 }
#define SDL_GetError
#define SDL_LogError
#define SDL_Log
#define SDL_Quit
int ThreadFunc(void *data)
Definition: testerror.c:32
static void quit(int rc)
Definition: testerror.c:25
#define SDL_CreateThread
#define SDL_Delay
#define SDL_LogSetPriority
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
#define SDL_Init
#define SDL_WaitThread
static int alive
Definition: testerror.c:21

◆ quit()

static void quit ( int  rc)
static

Definition at line 25 of file testerror.c.

References SDL_Quit, and SDLCALL.

Referenced by main().

26 {
27  SDL_Quit();
28  exit(rc);
29 }
#define SDL_Quit

◆ ThreadFunc()

int ThreadFunc ( void data)

Definition at line 32 of file testerror.c.

References alive, SDL_Delay, SDL_GetError, SDL_Log, SDL_SetError, and SDL_ThreadID.

Referenced by main().

33 {
34  /* Set the child thread error string */
35  SDL_SetError("Thread %s (%lu) had a problem: %s",
36  (char *) data, SDL_ThreadID(), "nevermind");
37  while (alive) {
38  SDL_Log("Thread '%s' is alive!\n", (char *) data);
39  SDL_Delay(1 * 1000);
40  }
41  SDL_Log("Child thread error string: %s\n", SDL_GetError());
42  return (0);
43 }
#define SDL_ThreadID
#define SDL_GetError
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
#define SDL_Log
#define SDL_Delay
#define SDL_SetError
static int alive
Definition: testerror.c:21

Variable Documentation

◆ alive

int alive = 0
static

Definition at line 21 of file testerror.c.

Referenced by main(), and ThreadFunc().