monotone

monotone Mtn Source Tree

Root/fake_pthread.c

1/*
2
3> enter fake_pthread.c
4
5The stench of incredible wrongness coming from this room is nearly
6overpowering. There is a sign on the wall
7
8> look at sign
9
10The sign says, "But it gives us a >10% performance boost for programs that
11don't really nead pthreads but are forced to link to it by a shared library
12dependency."
13
14> retch on floor
15
16You add to the decor.
17
18*/
19
20#include <stdio.h>
21#include <pthread.h>
22#include <stdlib.h>
23
24int
25pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
26{
27 return 0;
28}
29
30int pthread_mutex_lock(pthread_mutex_t *mutex)
31{
32 return 0;
33}
34
35int pthread_mutex_trylock(pthread_mutex_t *mutex)
36{
37 return 0;
38}
39
40int pthread_mutex_unlock(pthread_mutex_t *mutex)
41{
42 return 0;
43}
44
45int pthread_mutex_destroy(pthread_mutex_t *mutex)
46{
47 return 0;
48}
49
50int pthread_cond_init(pthread_cond_t *cond,
51 const pthread_condattr_t *cond_attr)
52{
53 return 0;
54}
55
56int pthread_cond_signal(pthread_cond_t *cond)
57{
58 return 0;
59}
60
61int pthread_cond_broadcast(pthread_cond_t *cond)
62{
63 return 0;
64}
65
66int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
67{
68 fprintf(stderr,"invalid call to %s\n", __PRETTY_FUNCTION__);
69 abort();
70}
71
72
73int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t
74 *mutex, const struct timespec *abstime)
75{
76 fprintf(stderr,"invalid call to %s\n", __PRETTY_FUNCTION__);
77 abort();
78}
79
80
81int pthread_cond_destroy(pthread_cond_t *cond)
82{
83 return 0;
84}
85
86int pthread_join(pthread_t th, void **thread_return)
87{
88 fprintf(stderr,"invalid call to %s\n", __PRETTY_FUNCTION__);
89 abort();
90}
91
92int pthread_create(pthread_t * thread, const pthread_attr_t * attr, void *
93 (*start_routine)(void *), void * arg)
94{
95 fprintf(stderr,"invalid call to %s\n", __PRETTY_FUNCTION__);
96 abort();
97}
98
99int pthread_once(pthread_once_t *once_control, void (*init_routine)
100 (void))
101{
102 if (PTHREAD_ONCE_INIT == *once_control) {
103 *once_control += 1;
104 init_routine();
105 }
106}
107
108struct keys {
109 void *value;
110 void (*destr_function) (void *);
111};
112
113#define PTHREAD_KEYS_MAX 1024
114struct keys tsd_keys[PTHREAD_KEYS_MAX];
115unsigned int tsd_keys_allocated;
116
117int pthread_key_create(pthread_key_t *key, void (*destr_function) (void *))
118{
119 if (tsd_keys_allocated == PTHREAD_KEYS_MAX) {
120 return -1;
121 }
122 *key = tsd_keys_allocated;
123 ++tsd_keys_allocated;
124 tsd_keys[*key].destr_function = destr_function;
125 // oughta setup an atexit
126}
127
128int pthread_key_delete(pthread_key_t key)
129{
130}
131
132int pthread_setspecific(pthread_key_t key, const void *pointer)
133{
134 if (key < 0 || key >= tsd_keys_allocated) {
135 return -1;
136 }
137 tsd_keys[key].value = (void *)pointer;
138}
139
140void * pthread_getspecific(pthread_key_t key)
141{
142 if (key < 0 || key >= tsd_keys_allocated) {
143 abort();
144 }
145 return tsd_keys[key].value;
146}
147

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status