annotate libobjc/objc/thr.h @ 158:494b0b89df80 default tip

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