1 // Package : omnithread
2 // omnithread/threaddata.cc Created : 10/2000 dpg1
4 // Copyright (C) 2000 AT&T Laboratories Cambridge
6 // This file is part of the omnithread library
8 // The omnithread library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free
20 // Software Foundation, Inc., 51 Franklin Street, Boston, MA
24 // Implementation of per-thread data
26 #ifndef INSIDE_THREAD_IMPL_CC
27 #error "threaddata.cc must be #included by a thread implementation."
31 static omni_thread::key_t allocated_keys = 0;
34 omni_thread::allocate_key()
36 omni_mutex_lock l(*next_id_mutex);
37 return ++allocated_keys;
41 omni_thread::set_value(key_t k, value_t* v)
44 if (k > _value_alloc) {
45 next_id_mutex->lock();
46 key_t alloc = allocated_keys;
47 next_id_mutex->unlock();
49 if (k > alloc) return 0;
51 value_t** nv = new value_t*[alloc];
54 for (; i < _value_alloc; i++)
58 for (; i < alloc; i++)
64 if (_values[k-1]) delete _values[k-1];
70 omni_thread::get_value(key_t k)
72 if (k > _value_alloc) return 0;
77 omni_thread::remove_value(key_t k)
79 if (k > _value_alloc) return 0;
80 value_t* v = _values[k-1];