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