#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "erregapi.h"
#include "erregxsd.h"
#include "erregxml.h"
#include "erregtypes_f.h"
#include "erreglog.h"
#include <pthread.h>
Go to the source code of this file.
Defines | |
#define | MAX_ARGC 20 |
Functions | |
static void | testThreads (void) |
int | main () |
static void * | threadFunc (void *private_data) |
Variables | |
static pthread_t | tid [MAX_ARGC] |
static const char * | Okay = "OK" |
static const char * | Failed = "Failed" |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition in file testlock.c.
#define MAX_ARGC 20 |
Definition at line 66 of file testlock.c.
int main | ( | ) |
Definition at line 45 of file testlock.c.
00046 { 00047 gboolean bRet; 00048 00049 // initialize rwlock 00050 bRet = erRegRWLockInit(); 00051 if (FALSE == bRet) 00052 { 00053 ERREG_ERRORPRINTF("error"); 00054 return 0; 00055 } 00056 00057 testThreads(); 00058 00059 // destroy rwlock 00060 erRegRWLockDestroy(); 00061 00062 return 0; 00063 }
static void testThreads | ( | void | ) | [static] |
Definition at line 99 of file testlock.c.
00100 { 00101 unsigned int i; 00102 unsigned int num_threads = 4; 00103 void *results[MAX_ARGC]; 00104 int ret; 00105 00106 for (i = 0; i < num_threads; i++) { 00107 results[i] = NULL; 00108 tid[i] = (pthread_t) -1; 00109 } 00110 00111 for (i = 0; i < num_threads; i++) { 00112 ret = pthread_create(&tid[i], NULL, threadFunc, 00113 (void *) NULL); 00114 if (ret != 0) { 00115 ERREG_ERRORPRINTF("pthread_create"); 00116 perror("pthread_create"); 00117 exit(1); 00118 } 00119 } 00120 for (i = 0; i < num_threads; i++) { 00121 ret = pthread_join(tid[i], &results[i]); 00122 if (ret != 0) { 00123 ERREG_ERRORPRINTF("pthread_join"); 00124 perror("pthread_join"); 00125 exit(1); 00126 } 00127 } 00128 00129 for (i = 0; i < num_threads; i++) 00130 if (results[i] != (void *) Okay) 00131 ERREG_ERRORPRINTF("Thread %d handling failed", i); 00132 }
static void* threadFunc | ( | void * | private_data | ) | [static] |
Definition at line 71 of file testlock.c.
00072 { 00073 int okay = 1; 00074 gboolean bRet; 00075 00076 // locking write lock 00077 // bRet = erRegWriteLock(); 00078 bRet = erRegReadLock(); 00079 if (FALSE == bRet) 00080 { 00081 ERREG_ERRORPRINTF("error"); 00082 return FALSE; 00083 } 00084 00085 while (1) 00086 { 00087 ERREG_ERRORPRINTF("HERE"); 00088 usleep(5*1000); 00089 } 00090 00091 // unlocking write lock 00092 erRegUnlock(); 00093 00094 if (okay == 0) 00095 return((void *) Failed); 00096 return ((void *) Okay); 00097 }
const char* Failed = "Failed" [static] |
Definition at line 69 of file testlock.c.
const char* Okay = "OK" [static] |
Definition at line 68 of file testlock.c.
pthread_t tid[MAX_ARGC] [static] |
Definition at line 67 of file testlock.c.