Skip to content
Snippets Groups Projects
Commit 8e38e5ee authored by Avi Kivity's avatar Avi Kivity
Browse files

pthread: add pthread_{getspecific,setspecific,key_create}

parent 98a90fb7
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ drivers += elf.o
objects = exceptions.o
objects += entry.o
objects += mutex.o
objects += pthread.o
libc = libc/string/strcmp.o
......
#include "mutex.hh"
#include <pthread.h>
#include <errno.h>
#include <mutex>
#include <vector>
#include <algorithm>
namespace pthread_private {
const unsigned tsd_nkeys = 100;
__thread void* tsd[tsd_nkeys];
mutex tsd_key_mutex;
std::vector<bool> tsd_used_keys(tsd_nkeys);
}
using namespace pthread_private;
pthread_key_t pthread_key_create()
{
std::lock_guard<mutex> guard(tsd_key_mutex);
auto p = std::find(tsd_used_keys.begin(), tsd_used_keys.end(), false);
if (p == tsd_used_keys.end()) {
return ENOMEM;
}
*p = true;
}
void* pthread_getspecific(pthread_key_t key)
{
return tsd[key];
}
int pthread_setspecific(pthread_key_t key, void* value)
{
tsd[key] = value;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment