/* Copyright (c) 2001, Stanford University
* All rights reserved.
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include <stdio.h>
#include "cr_threads.h"
#include "cr_error.h"
/* perror() messages */
/* Magic number to determine if a CRtsd has been initialized */
/* Initialize a CRtsd */
{
#ifdef WINDOWS
crError("crInitTSD failed!");
}
(void) destructor;
#else
crDebug("crServer: failed to allocate TLS key.");
else
#endif
}
{
}
{
#ifdef WINDOWS
/* Windows returns true on success, 0 on failure */
crError("crFreeTSD failed!");
}
#else
else
#endif
}
/* Set thread-specific data */
{
/* initialize this CRtsd */
}
#ifdef WINDOWS
crError("crSetTSD failed!");
}
#else
crError("crSetTSD failed!");
}
#endif
}
/* Get thread-specific data */
{
#ifdef WINDOWS
void * value;
#endif
}
#ifdef WINDOWS
if (!value) {
err = GetLastError();
if ( err != ERROR_SUCCESS ) {
NULL,
err,
0, NULL );
}
}
return value;
#else
#endif
}
/* Return ID of calling thread */
unsigned long crThreadID(void)
{
#ifdef WINDOWS
return (unsigned long) GetCurrentThreadId();
#else
return (unsigned long) pthread_self();
#endif
}
{
#ifdef WINDOWS
#else
int rc;
#endif
}
{
#ifdef WINDOWS
#else
#endif
}
{
#ifdef WINDOWS
#else
#endif
}
{
#ifdef WINDOWS
#else
#endif
}
{
#ifdef WINDOWS
/* XXX fix me */
(void) cond;
#else
if (err) {
crError("crInitCondition failed");
}
#endif
}
{
#ifdef WINDOWS
/* XXX fix me */
(void) cond;
#else
if (err) {
crError("crFreeCondition error (threads waiting on the condition?)");
}
#endif
}
/**
* We're basically just wrapping the pthread condition var interface.
* See the man page for pthread_cond_wait to learn about the mutex parameter.
*/
{
#ifdef WINDOWS
/* XXX fix me */
(void) cond;
(void) mutex;
#else
#endif
}
{
#ifdef WINDOWS
/* XXX fix me */
(void) cond;
#else
#endif
}
{
#ifdef WINDOWS
unsigned int i;
for (i = 0; i < count; i++)
#else
b->waiting = 0;
#endif
}
{
/* XXX anything to do? */
}
{
#ifdef WINDOWS
#else
pthread_mutex_lock( &(b->mutex) );
b->waiting++;
}
else {
pthread_cond_broadcast( &(b->cond) );
b->waiting = 0;
}
pthread_mutex_unlock( &(b->mutex) );
#endif
}
{
#ifdef WINDOWS
crWarning("CRsemaphore functions not implemented on Windows");
#else
#endif
}
{
#ifdef WINDOWS
/* to do */
#else
sem_wait(s);
#endif
}
{
#ifdef WINDOWS
/* to do */
#else
sem_post(s);
#endif
}