xref: /netbsd-src/external/gpl3/gcc.old/dist/libobjc/objc/thr.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg /* Thread and mutex controls for Objective C.
2*8feb0f0bSmrg    Copyright (C) 1996-2020 Free Software Foundation, Inc.
336ac495dSmrg    Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
436ac495dSmrg 
536ac495dSmrg This file is part of GCC.
636ac495dSmrg 
736ac495dSmrg GCC is free software; you can redistribute it and/or modify
836ac495dSmrg it under the terms of the GNU General Public License as published by
936ac495dSmrg the Free Software Foundation; either version 3, or (at your option)
1036ac495dSmrg any later version.
1136ac495dSmrg 
1236ac495dSmrg GCC is distributed in the hope that it will be useful,
1336ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of
1436ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1536ac495dSmrg GNU General Public License for more details.
1636ac495dSmrg 
1736ac495dSmrg Under Section 7 of GPL version 3, you are granted additional
1836ac495dSmrg permissions described in the GCC Runtime Library Exception, version
1936ac495dSmrg 3.1, as published by the Free Software Foundation.
2036ac495dSmrg 
2136ac495dSmrg You should have received a copy of the GNU General Public License and
2236ac495dSmrg a copy of the GCC Runtime Library Exception along with this program;
2336ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2436ac495dSmrg <http://www.gnu.org/licenses/>.  */
2536ac495dSmrg 
2636ac495dSmrg #ifndef __thread_INCLUDE_GNU
2736ac495dSmrg #define __thread_INCLUDE_GNU
2836ac495dSmrg 
2936ac495dSmrg #include "objc.h"
3036ac495dSmrg 
3136ac495dSmrg #ifdef __cplusplus
3236ac495dSmrg extern "C" {
3336ac495dSmrg #endif /* __cplusplus */
3436ac495dSmrg 
3536ac495dSmrg /*************************************************************************
3636ac495dSmrg  *  Universal static variables:
3736ac495dSmrg  */
3836ac495dSmrg extern int __objc_thread_exit_status;      /* Global exit status.   */
3936ac495dSmrg 
4036ac495dSmrg /********
4136ac495dSmrg  *  Thread safe implementation types and functions.
4236ac495dSmrg  */
4336ac495dSmrg 
4436ac495dSmrg /* Thread priorities */
4536ac495dSmrg #define OBJC_THREAD_INTERACTIVE_PRIORITY        2
4636ac495dSmrg #define OBJC_THREAD_BACKGROUND_PRIORITY         1
4736ac495dSmrg #define OBJC_THREAD_LOW_PRIORITY                0
4836ac495dSmrg 
4936ac495dSmrg /* A thread */
5036ac495dSmrg typedef void * objc_thread_t;
5136ac495dSmrg 
5236ac495dSmrg /* This structure represents a single mutual exclusion lock. */
5336ac495dSmrg struct objc_mutex
5436ac495dSmrg {
5536ac495dSmrg   volatile objc_thread_t owner;     /* Id of thread that owns. */
5636ac495dSmrg   volatile int depth;               /* # of acquires. */
5736ac495dSmrg   void * backend;                   /* Specific to backend */
5836ac495dSmrg };
5936ac495dSmrg typedef struct objc_mutex *objc_mutex_t;
6036ac495dSmrg 
6136ac495dSmrg /* This structure represents a single condition mutex */
6236ac495dSmrg struct objc_condition
6336ac495dSmrg {
6436ac495dSmrg   void * backend;                   /* Specific to backend */
6536ac495dSmrg };
6636ac495dSmrg typedef struct objc_condition *objc_condition_t;
6736ac495dSmrg 
6836ac495dSmrg /* Frontend mutex functions */
6936ac495dSmrg objc_mutex_t objc_mutex_allocate (void);
7036ac495dSmrg int objc_mutex_deallocate (objc_mutex_t mutex);
7136ac495dSmrg int objc_mutex_lock (objc_mutex_t mutex);
7236ac495dSmrg int objc_mutex_unlock (objc_mutex_t mutex);
7336ac495dSmrg int objc_mutex_trylock (objc_mutex_t mutex);
7436ac495dSmrg 
7536ac495dSmrg /* Frontend condition mutex functions */
7636ac495dSmrg objc_condition_t objc_condition_allocate (void);
7736ac495dSmrg int objc_condition_deallocate (objc_condition_t condition);
7836ac495dSmrg int objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex);
7936ac495dSmrg int objc_condition_signal (objc_condition_t condition);
8036ac495dSmrg int objc_condition_broadcast (objc_condition_t condition);
8136ac495dSmrg 
8236ac495dSmrg /* Frontend thread functions */
8336ac495dSmrg objc_thread_t objc_thread_detach (SEL selector, id object, id argument);
8436ac495dSmrg void objc_thread_yield (void);
8536ac495dSmrg int objc_thread_exit (void);
8636ac495dSmrg int objc_thread_set_priority (int priority);
8736ac495dSmrg int objc_thread_get_priority (void);
8836ac495dSmrg void * objc_thread_get_data (void);
8936ac495dSmrg int objc_thread_set_data (void *value);
9036ac495dSmrg objc_thread_t objc_thread_id (void);
9136ac495dSmrg void objc_thread_add (void);
9236ac495dSmrg void objc_thread_remove (void);
9336ac495dSmrg 
9436ac495dSmrg /*
9536ac495dSmrg   Use this to set the hook function that will be called when the
9636ac495dSmrg   runtime initially becomes multi threaded.
9736ac495dSmrg   The hook function is only called once, meaning only when the
9836ac495dSmrg   2nd thread is spawned, not for each and every thread.
9936ac495dSmrg 
10036ac495dSmrg   It returns the previous hook function or NULL if there is none.
10136ac495dSmrg 
10236ac495dSmrg   A program outside of the runtime could set this to some function so
10336ac495dSmrg   it can be informed; for example, the GNUstep Base Library sets it
10436ac495dSmrg   so it can implement the NSBecomingMultiThreaded notification.
10536ac495dSmrg   */
10636ac495dSmrg typedef void (*objc_thread_callback) (void);
10736ac495dSmrg objc_thread_callback objc_set_thread_callback (objc_thread_callback func);
10836ac495dSmrg 
10936ac495dSmrg /* Backend initialization functions */
11036ac495dSmrg int __objc_init_thread_system (void);
11136ac495dSmrg 
11236ac495dSmrg #ifdef __cplusplus
11336ac495dSmrg }
11436ac495dSmrg #endif /* __cplusplus */
11536ac495dSmrg 
11636ac495dSmrg #endif /* not __thread_INCLUDE_GNU */
117