~ubuntu-branches/ubuntu/vivid/libsdl2/vivid

« back to all changes in this revision

Viewing changes to test/testthread.c

  • Committer: Package Import Robot
  • Author(s): Manuel A. Fernandez Montecelo, Felix Geyer
  • Date: 2013-12-28 12:31:19 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131228123119-e0k27gckmnzskfgb
Tags: 2.0.1+dfsg1-1
* New upstream release (Closes: #728974)
  - Remove patch applied upstream:
    bug-723797-false_positives_in_mouse_wheel_code.patch
* Bump Standards-Version to 3.9.5, no changes needed.

[ Felix Geyer ]
* Import upstream gpg key for uscan to verify the orig tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
ThreadFunc(void *data)
35
35
{
36
36
    SDL_TLSSet(tls, "baby thread", NULL);
37
 
    printf("Started thread %s: My thread id is %lu, thread data = %s\n",
 
37
    SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
38
38
           (char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
39
39
    while (alive) {
40
 
        printf("Thread '%s' is alive!\n", (char *) data);
 
40
        SDL_Log("Thread '%s' is alive!\n", (char *) data);
41
41
        SDL_Delay(1 * 1000);
42
42
    }
43
 
    printf("Thread '%s' exiting!\n", (char *) data);
 
43
    SDL_Log("Thread '%s' exiting!\n", (char *) data);
44
44
    return (0);
45
45
}
46
46
 
47
47
static void
48
48
killed(int sig)
49
49
{
50
 
    printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
 
50
    SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
51
51
    SDL_Delay(5 * 1000);
52
52
    alive = 0;
53
53
    quit(0);
58
58
{
59
59
    SDL_Thread *thread;
60
60
 
 
61
        /* Enable standard application logging */
 
62
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
 
63
 
61
64
    /* Load the SDL library */
62
65
    if (SDL_Init(0) < 0) {
63
 
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
 
66
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
64
67
        return (1);
65
68
    }
66
69
 
67
70
    tls = SDL_TLSCreate();
68
71
    SDL_assert(tls);
69
72
    SDL_TLSSet(tls, "main thread", NULL);
70
 
    printf("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
 
73
    SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
71
74
 
72
75
    alive = 1;
73
76
    thread = SDL_CreateThread(ThreadFunc, "One", "#1");
74
77
    if (thread == NULL) {
75
 
        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
 
78
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
76
79
        quit(1);
77
80
    }
78
81
    SDL_Delay(5 * 1000);
79
 
    printf("Waiting for thread #1\n");
 
82
    SDL_Log("Waiting for thread #1\n");
80
83
    alive = 0;
81
84
    SDL_WaitThread(thread, NULL);
82
85
 
83
 
    printf("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
 
86
    SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
84
87
 
85
88
    alive = 1;
86
89
    signal(SIGTERM, killed);
87
90
    thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
88
91
    if (thread == NULL) {
89
 
        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
 
92
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
90
93
        quit(1);
91
94
    }
92
95
    raise(SIGTERM);