1 |
739 |
jeremybenn |
/* Thread and mutex controls for Objective C.
|
2 |
|
|
Copyright (C) 1996, 1997, 2002, 2004, 2009, 2010
|
3 |
|
|
Free Software Foundation, Inc.
|
4 |
|
|
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
|
5 |
|
|
|
6 |
|
|
This file is part of GCC.
|
7 |
|
|
|
8 |
|
|
GCC is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 3, or (at your option)
|
11 |
|
|
any later version.
|
12 |
|
|
|
13 |
|
|
GCC is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
Under Section 7 of GPL version 3, you are granted additional
|
19 |
|
|
permissions described in the GCC Runtime Library Exception, version
|
20 |
|
|
3.1, as published by the Free Software Foundation.
|
21 |
|
|
|
22 |
|
|
You should have received a copy of the GNU General Public License and
|
23 |
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
24 |
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
25 |
|
|
<http://www.gnu.org/licenses/>. */
|
26 |
|
|
|
27 |
|
|
#ifndef __thread_INCLUDE_GNU
|
28 |
|
|
#define __thread_INCLUDE_GNU
|
29 |
|
|
|
30 |
|
|
#include "objc.h"
|
31 |
|
|
|
32 |
|
|
#ifdef __cplusplus
|
33 |
|
|
extern "C" {
|
34 |
|
|
#endif /* __cplusplus */
|
35 |
|
|
|
36 |
|
|
/*************************************************************************
|
37 |
|
|
* Universal static variables:
|
38 |
|
|
*/
|
39 |
|
|
extern int __objc_thread_exit_status; /* Global exit status. */
|
40 |
|
|
|
41 |
|
|
/********
|
42 |
|
|
* Thread safe implementation types and functions.
|
43 |
|
|
*/
|
44 |
|
|
|
45 |
|
|
/* Thread priorities */
|
46 |
|
|
#define OBJC_THREAD_INTERACTIVE_PRIORITY 2
|
47 |
|
|
#define OBJC_THREAD_BACKGROUND_PRIORITY 1
|
48 |
|
|
#define OBJC_THREAD_LOW_PRIORITY 0
|
49 |
|
|
|
50 |
|
|
/* A thread */
|
51 |
|
|
typedef void * objc_thread_t;
|
52 |
|
|
|
53 |
|
|
/* This structure represents a single mutual exclusion lock. */
|
54 |
|
|
struct objc_mutex
|
55 |
|
|
{
|
56 |
|
|
volatile objc_thread_t owner; /* Id of thread that owns. */
|
57 |
|
|
volatile int depth; /* # of acquires. */
|
58 |
|
|
void * backend; /* Specific to backend */
|
59 |
|
|
};
|
60 |
|
|
typedef struct objc_mutex *objc_mutex_t;
|
61 |
|
|
|
62 |
|
|
/* This structure represents a single condition mutex */
|
63 |
|
|
struct objc_condition
|
64 |
|
|
{
|
65 |
|
|
void * backend; /* Specific to backend */
|
66 |
|
|
};
|
67 |
|
|
typedef struct objc_condition *objc_condition_t;
|
68 |
|
|
|
69 |
|
|
/* Frontend mutex functions */
|
70 |
|
|
objc_mutex_t objc_mutex_allocate (void);
|
71 |
|
|
int objc_mutex_deallocate (objc_mutex_t mutex);
|
72 |
|
|
int objc_mutex_lock (objc_mutex_t mutex);
|
73 |
|
|
int objc_mutex_unlock (objc_mutex_t mutex);
|
74 |
|
|
int objc_mutex_trylock (objc_mutex_t mutex);
|
75 |
|
|
|
76 |
|
|
/* Frontend condition mutex functions */
|
77 |
|
|
objc_condition_t objc_condition_allocate (void);
|
78 |
|
|
int objc_condition_deallocate (objc_condition_t condition);
|
79 |
|
|
int objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex);
|
80 |
|
|
int objc_condition_signal (objc_condition_t condition);
|
81 |
|
|
int objc_condition_broadcast (objc_condition_t condition);
|
82 |
|
|
|
83 |
|
|
/* Frontend thread functions */
|
84 |
|
|
objc_thread_t objc_thread_detach (SEL selector, id object, id argument);
|
85 |
|
|
void objc_thread_yield (void);
|
86 |
|
|
int objc_thread_exit (void);
|
87 |
|
|
int objc_thread_set_priority (int priority);
|
88 |
|
|
int objc_thread_get_priority (void);
|
89 |
|
|
void * objc_thread_get_data (void);
|
90 |
|
|
int objc_thread_set_data (void *value);
|
91 |
|
|
objc_thread_t objc_thread_id (void);
|
92 |
|
|
void objc_thread_add (void);
|
93 |
|
|
void objc_thread_remove (void);
|
94 |
|
|
|
95 |
|
|
/*
|
96 |
|
|
Use this to set the hook function that will be called when the
|
97 |
|
|
runtime initially becomes multi threaded.
|
98 |
|
|
The hook function is only called once, meaning only when the
|
99 |
|
|
2nd thread is spawned, not for each and every thread.
|
100 |
|
|
|
101 |
|
|
It returns the previous hook function or NULL if there is none.
|
102 |
|
|
|
103 |
|
|
A program outside of the runtime could set this to some function so
|
104 |
|
|
it can be informed; for example, the GNUstep Base Library sets it
|
105 |
|
|
so it can implement the NSBecomingMultiThreaded notification.
|
106 |
|
|
*/
|
107 |
|
|
typedef void (*objc_thread_callback) (void);
|
108 |
|
|
objc_thread_callback objc_set_thread_callback (objc_thread_callback func);
|
109 |
|
|
|
110 |
|
|
/* Backend initialization functions */
|
111 |
|
|
int __objc_init_thread_system (void);
|
112 |
|
|
|
113 |
|
|
#ifdef __cplusplus
|
114 |
|
|
}
|
115 |
|
|
#endif /* __cplusplus */
|
116 |
|
|
|
117 |
|
|
#endif /* not __thread_INCLUDE_GNU */
|