source: branches/libc-0.6/src/gcc/libobjc/thr-solaris.c@ 3411

Last change on this file since 3411 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.7 KB
Line 
1/* GNU Objective C Runtime Thread Interface
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Galen C. Hunt ([email protected])
4 Conditions added by Mircea Oancea ([email protected])
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify it under the
9terms of the GNU General Public License as published by the Free Software
10Foundation; either version 2, or (at your option) any later version.
11
12GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15details.
16
17You should have received a copy of the GNU General Public License along with
18GNU CC; see the file COPYING. If not, write to the Free Software
19Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* As a special exception, if you link this library with files compiled with
23 GCC to produce an executable, this does not cause the resulting executable
24 to be covered by the GNU General Public License. This exception does not
25 however invalidate any other reasons why the executable file might be
26 covered by the GNU General Public License. */
27
28#include <objc/thr.h>
29#include "runtime.h"
30
31#include <thread.h>
32#include <synch.h>
33#include <errno.h>
34
35/* Key structure for maintaining thread specific storage */
36static thread_key_t __objc_thread_data_key;
37
38/* Backend initialization functions */
39
40/* Initialize the threads subsystem. */
41int
42__objc_init_thread_system(void)
43{
44 /* Initialize the thread storage key */
45 if (thr_keycreate(&__objc_thread_data_key, NULL) == 0)
46 return 0;
47 else
48 return -1;
49}
50
51/* Close the threads subsystem. */
52int
53__objc_close_thread_system(void)
54{
55 return 0;
56}
57
58/* Backend thread functions */
59
60/* Create a new thread of execution. */
61objc_thread_t
62__objc_thread_detach(void (*func)(void *arg), void *arg)
63{
64 objc_thread_t thread_id;
65 thread_t new_thread_id = 0;
66
67 if (thr_create(NULL, 0, (void *)func, arg,
68 THR_DETACHED | THR_NEW_LWP,
69 &new_thread_id) == 0)
70 thread_id = *(objc_thread_t *)&new_thread_id;
71 else
72 thread_id = NULL;
73
74 return thread_id;
75}
76
77/* Set the current thread's priority. */
78int
79__objc_thread_set_priority(int priority)
80{
81 int sys_priority = 0;
82
83 switch (priority)
84 {
85 case OBJC_THREAD_INTERACTIVE_PRIORITY:
86 sys_priority = 300;
87 break;
88 default:
89 case OBJC_THREAD_BACKGROUND_PRIORITY:
90 sys_priority = 200;
91 break;
92 case OBJC_THREAD_LOW_PRIORITY:
93 sys_priority = 1000;
94 break;
95 }
96
97 /* Change priority */
98 if (thr_setprio(thr_self(), sys_priority) == 0)
99 return 0;
100 else
101 return -1;
102}