Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 107 lines (83 sloc) 2.09 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
/* Copyright (c) 2001, Stanford University
* All rights reserved.
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#ifndef CR_THREADS_H
#define CR_THREADS_H

#ifdef __cplusplus
extern "C" {
#endif

#include "chromium.h"
#include "cr_bits.h"

#ifdef WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <pthread.h>
#include <semaphore.h>
#endif


/*
* Handle for Thread-Specific Data
*/
typedef struct {
#ifdef WINDOWS
DWORD key;
#else
pthread_key_t key;
#endif
int initMagic;
} CRtsd;


extern void crInitTSD(CRtsd *tsd);
extern void crInitTSDF(CRtsd *tsd, void (*destructor)(void *));
extern void crFreeTSD(CRtsd *tsd);
extern void crSetTSD(CRtsd *tsd, void *ptr);
extern void *crGetTSD(CRtsd *tsd);
extern unsigned long crThreadID(void);


/* Mutex datatype */
#ifdef WINDOWS
typedef CRITICAL_SECTION CRmutex;
#else
typedef pthread_mutex_t CRmutex;
#endif

extern void crInitMutex(CRmutex *mutex);
extern void crFreeMutex(CRmutex *mutex);
extern void crLockMutex(CRmutex *mutex);
extern void crUnlockMutex(CRmutex *mutex);


/* Condition variable datatype */
#ifdef WINDOWS
typedef int CRcondition;
#else
typedef pthread_cond_t CRcondition;
#endif

extern void crInitCondition(CRcondition *cond);
extern void crFreeCondition(CRcondition *cond);
extern void crWaitCondition(CRcondition *cond, CRmutex *mutex);
extern void crSignalCondition(CRcondition *cond);


/* Barrier datatype */
typedef struct {
unsigned int count;
#ifdef WINDOWS
HANDLE hEvents[CR_MAX_CONTEXTS];
#else
unsigned int waiting;
pthread_cond_t cond;
pthread_mutex_t mutex;
#endif
} CRbarrier;

extern void crInitBarrier(CRbarrier *b, unsigned int count);
extern void crFreeBarrier(CRbarrier *b);
extern void crWaitBarrier(CRbarrier *b);


/* Semaphores */
#ifdef WINDOWS
typedef int CRsemaphore;
#else
typedef sem_t CRsemaphore;
#endif

extern void crInitSemaphore(CRsemaphore *s, unsigned int count);
extern void crWaitSemaphore(CRsemaphore *s);
extern void crSignalSemaphore(CRsemaphore *s);


#ifdef __cplusplus
}
#endif

#endif /* CR_THREADS_H */
Something went wrong with that request. Please try again.