1/* Thread and mutex controls for Objective C. 2 Copyright (C) 1996, 1997 Free Software Foundation, Inc. 3 Contributed by Galen C. Hunt (gchunt@cs.rochester.edu) 4 5This file is part of GNU CC. 6 7GNU CC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GNU CC is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17GNU CC is free software; you can redistribute it and/or modify it under the 18terms of the GNU General Public License as published by the Free Software 19Foundation; either version 2, or (at your option) any later version. 20 21GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY 22WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 23FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 24details. 25 26You should have received a copy of the GNU General Public License along with 27GNU CC; see the file COPYING. If not, write to the Free Software 28Foundation, 59 Temple Place - Suite 330, 29Boston, MA 02111-1307, USA. */ 30 31/* As a special exception, if you link this library with files 32 compiled with GCC to produce an executable, this does not cause 33 the resulting executable to be covered by the GNU General Public License. 34 This exception does not however invalidate any other reasons why 35 the executable file might be covered by the GNU General Public License. */ 36 37 38#ifndef __thread_INCLUDE_GNU 39#define __thread_INCLUDE_GNU 40 41#include "objc/objc.h" 42 43/************************************************************************* 44 * Universal static variables: 45 */ 46extern int __objc_thread_exit_status; /* Global exit status. */ 47 48/******** 49 * Thread safe implementation types and functions. 50 */ 51 52/* Thread priorities */ 53#define OBJC_THREAD_INTERACTIVE_PRIORITY 2 54#define OBJC_THREAD_BACKGROUND_PRIORITY 1 55#define OBJC_THREAD_LOW_PRIORITY 0 56 57/* A thread */ 58typedef void * objc_thread_t; 59 60/* This structure represents a single mutual exclusion lock. */ 61struct objc_mutex 62{ 63 volatile objc_thread_t owner; /* Id of thread that owns. */ 64 volatile int depth; /* # of acquires. */ 65 void * backend; /* Specific to backend */ 66}; 67typedef struct objc_mutex *objc_mutex_t; 68 69/* This structure represents a single condition mutex */ 70struct objc_condition 71{ 72 void * backend; /* Specific to backend */ 73}; 74typedef struct objc_condition *objc_condition_t; 75 76/* Frontend mutex functions */ 77objc_mutex_t objc_mutex_allocate(void); 78int objc_mutex_deallocate(objc_mutex_t mutex); 79int objc_mutex_lock(objc_mutex_t mutex); 80int objc_mutex_unlock(objc_mutex_t mutex); 81int objc_mutex_trylock(objc_mutex_t mutex); 82 83/* Frontend condition mutex functions */ 84objc_condition_t objc_condition_allocate(void); 85int objc_condition_deallocate(objc_condition_t condition); 86int objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex); 87int objc_condition_signal(objc_condition_t condition); 88int objc_condition_broadcast(objc_condition_t condition); 89 90/* Frontend thread functions */ 91objc_thread_t objc_thread_detach(SEL selector, id object, id argument); 92void objc_thread_yield(void); 93int objc_thread_exit(void); 94int objc_thread_set_priority(int priority); 95int objc_thread_get_priority(void); 96void * objc_thread_get_data(void); 97int objc_thread_set_data(void *value); 98objc_thread_t objc_thread_id(void); 99 100/* 101 Use this to set the hook function that will be called when the 102 runtime initially becomes multi threaded. 103 The hook function is only called once, meaning only when the 104 2nd thread is spawned, not for each and every thread. 105 106 It returns the previous hook function or NULL if there is none. 107 108 A program outside of the runtime could set this to some function so 109 it can be informed; for example, the GNUstep Base Library sets it 110 so it can implement the NSBecomingMultiThreaded notification. 111 */ 112typedef void (*objc_thread_callback)(); 113objc_thread_callback objc_set_thread_callback(objc_thread_callback func); 114 115/* Backend initialization functions */ 116int __objc_init_thread_system(void); 117int __objc_fini_thread_system(void); 118 119/* Backend mutex functions */ 120int __objc_mutex_allocate(objc_mutex_t mutex); 121int __objc_mutex_deallocate(objc_mutex_t mutex); 122int __objc_mutex_lock(objc_mutex_t mutex); 123int __objc_mutex_trylock(objc_mutex_t mutex); 124int __objc_mutex_unlock(objc_mutex_t mutex); 125 126/* Backend condition mutex functions */ 127int __objc_condition_allocate(objc_condition_t condition); 128int __objc_condition_deallocate(objc_condition_t condition); 129int __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex); 130int __objc_condition_broadcast(objc_condition_t condition); 131int __objc_condition_signal(objc_condition_t condition); 132 133/* Backend thread functions */ 134objc_thread_t __objc_thread_detach(void (*func)(void *arg), void *arg); 135int __objc_thread_set_priority(int priority); 136int __objc_thread_get_priority(void); 137void __objc_thread_yield(void); 138int __objc_thread_exit(void); 139objc_thread_t __objc_thread_id(void); 140int __objc_thread_set_data(void *value); 141void * __objc_thread_get_data(void); 142 143#endif /* not __thread_INCLUDE_GNU */ 144