-const char jcc_rcs[] = "$Id: jcc.c,v 1.185 2008/08/30 12:03:07 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.186 2008/09/04 08:13:58 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.186 2008/09/04 08:13:58 fabiankeil
+ * Prepare for critical sections on Windows by adding a
+ * layer of indirection before the pthread mutex functions.
+ *
* Revision 1.185 2008/08/30 12:03:07 fabiankeil
* Remove FEATURE_COOKIE_JAR.
*
#define sleep(N) DosSleep(((N) * 100))
#endif
-#ifdef FEATURE_PTHREAD
+#ifdef MUTEX_LOCKS_AVAILABLE
/*
* XXX: Does the locking stuff really belong in this file?
*/
privoxy_mutex_t rand_mutex;
#endif /* ndef HAVE_RANDOM */
-#endif /* FEATURE_PTHREAD */
+#endif /* def MUTEX_LOCKS_AVAILABLE */
#if defined(unix)
const char *basedir = NULL;
#endif /* #if !defined(_WIN32) || defined(_WIN_CONSOLE) */
-#ifdef FEATURE_PTHREAD
+#ifdef MUTEX_LOCKS_AVAILABLE
/*********************************************************************
*
* Function : privoxy_mutex_lock
*
- * Description : Locks a mutex using pthread_mutex_lock.
+ * Description : Locks a mutex.
*
* Parameters :
* 1 : mutex = The mutex to lock.
*
- * Returns : Void, exits in case of errors.
+ * Returns : Void. May exit in case of errors.
*
*********************************************************************/
void privoxy_mutex_lock(privoxy_mutex_t *mutex)
{
+#ifdef FEATURE_PTHREAD
int err = pthread_mutex_lock(mutex);
if (err)
{
}
exit(1);
}
+#else
+ EnterCriticalSection(mutex);
+#endif /* def FEATURE_PTHREAD */
}
*
* Function : privoxy_mutex_unlock
*
- * Description : Unlocks a mutex using pthread_mutex_unlock.
+ * Description : Unlocks a mutex.
*
* Parameters :
* 1 : mutex = The mutex to unlock.
*
- * Returns : Void, exits in case of errors.
+ * Returns : Void. May exit in case of errors.
*
*********************************************************************/
void privoxy_mutex_unlock(privoxy_mutex_t *mutex)
{
+#ifdef FEATURE_PTHREAD
int err = pthread_mutex_unlock(mutex);
if (err)
{
}
exit(1);
}
+#else
+ LeaveCriticalSection(mutex);
+#endif /* def FEATURE_PTHREAD */
}
*
* Function : privoxy_mutex_init
*
- * Description : Prepares a mutex using pthread_mutex_init.
+ * Description : Prepares a mutex.
*
* Parameters :
* 1 : mutex = The mutex to initialize.
*
- * Returns : Void, exits in case of errors.
+ * Returns : Void. May exit in case of errors.
*
*********************************************************************/
static void privoxy_mutex_init(privoxy_mutex_t *mutex)
{
+#ifdef FEATURE_PTHREAD
int err = pthread_mutex_init(mutex, 0);
if (err)
{
strerror(err));
exit(1);
}
-}
+#else
+ InitializeCriticalSection(mutex);
#endif /* def FEATURE_PTHREAD */
-
+}
+#endif /* def MUTEX_LOCKS_AVAILABLE */
/*********************************************************************
*
*********************************************************************/
static void initialize_mutexes(void)
{
-#ifdef FEATURE_PTHREAD
+#ifdef MUTEX_LOCKS_AVAILABLE
/*
* Prepare global mutex semaphores
*/
#ifndef HAVE_RANDOM
privoxy_mutex_init(&rand_mutex);
#endif /* ndef HAVE_RANDOM */
-#endif /* FEATURE_PTHREAD */
-
- /*
- * TODO: mutex support for mingw32 would be swell.
- */
-
+#endif /* def MUTEX_LOCKS_AVAILABLE */
}
random_seed = (unsigned int)time(NULL);
#ifdef HAVE_RANDOM
srandom(random_seed);
-#elif defined (_WIN32)
- /*
- * See pick_from_range() in miscutil.c for details.
- */
- log_error(LOG_LEVEL_INFO,
- "No thread-safe PRNG implemented for your platform. "
- "Using weak \'randomization\' factor which will "
- "limit the already questionable usefulness of "
- "header-time-randomizing actions (disabled by default).");
#else
srand(random_seed);
#endif /* ifdef HAVE_RANDOM */