OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Macros | Functions
thread.h File Reference

Functions for multi-threaded applications using Libevent. More...

`#include <event2/event-config.h>`
`#include "opal_rename.h"`

Go to the source code of this file.

## Data Structures
struct | evthread_lock_callbacks
| This structure describes the interface a threading library uses for locking. More...
struct | evthread_condition_callbacks
| This structure describes the interface a threading library uses for condition variables. More...

## Macros
#define | EVTHREAD_LOCK_API_VERSION 1
#define | EVTHREAD_CONDITION_API_VERSION 1
Flags passed to lock functions
#define | EVTHREAD_WRITE 0x04
| A flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for writing. More...
#define | EVTHREAD_READ 0x08
| A flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for reading. More...
#define | EVTHREAD_TRY 0x10
| A flag passed to a locking callback when we don't want to block waiting for the lock; if we can't get the lock immediately, we will instead return nonzero from the locking callback. More...
Types of locks
#define | EVTHREAD_LOCKTYPE_RECURSIVE 1
| A recursive lock is one that can be acquired multiple times at once by the same thread. More...
#define | EVTHREAD_LOCKTYPE_READWRITE 2

## Functions
int | evthread_set_lock_callbacks (const struct evthread_lock_callbacks *)
| Sets a group of functions that Libevent should use for locking. More...
int | evthread_set_condition_callbacks (const struct evthread_condition_callbacks *)
| Sets a group of functions that Libevent should use for condition variables. More...
void | evthread_set_id_callback (unsigned long(*id_fn)(void))
| Sets the function for determining the thread id. More...
void | evthread_enable_lock_debuging (void)
| Enable debugging wrappers around the current lock callbacks. More...
int | evthread_make_base_notifiable (struct event_base *base)
| Make sure it's safe to tell an event base to wake up from another thread or a signal handler. More...

## Detailed Description

Functions for multi-threaded applications using Libevent.

When using a multi-threaded application in which multiple threads add and delete events from a single event base, Libevent needs to lock its data structures.

Like the memory-management function hooks, all of the threading functions must be set up before an event_base is created if you want the base to use them.

Most programs will either be using Windows threads or Posix threads. You can configure Libevent to use one of these event_use_windows_threads() or event_use_pthreads() respectively. If you're using another threading library, you'll need to configure threading functions manually using evthread_set_lock_callbacks() and evthread_set_condition_callbacks().

## Macro Definition Documentation

#define EVTHREAD_LOCKTYPE_RECURSIVE 1

A recursive lock is one that can be acquired multiple times at once by the same thread.

No other process can allocate the lock until the thread that has been holding it has unlocked it as many times as it locked it.

Referenced by bufferevent_rate_limit_group_free(), bufferevent_rate_limit_group_new(), evbuffer_enable_locking(), evdns_add_server_port_with_base(), evdns_base_new(), event_base_free(), event_base_new_with_config(), and evthread_enable_lock_debuging().

#define EVTHREAD_READ 0x08

A flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for reading.

#define EVTHREAD_TRY 0x10

A flag passed to a locking callback when we don't want to block waiting for the lock; if we can't get the lock immediately, we will instead return nonzero from the locking callback.

#define EVTHREAD_WRITE 0x04

A flag passed to a locking callback when the lock was allocated as a read-write lock, and we want to acquire or release the lock for writing.

## Function Documentation

void evthread_enable_lock_debuging | ( | void |  | ) |

Enable debugging wrappers around the current lock callbacks.

If Libevent makes one of several common locking errors, exit with an assertion failure.

If you're going to call this function, you must do so before any locks are allocated.

References EVTHREAD_LOCKTYPE_RECURSIVE, and evthread_condition_callbacks::wait_condition.

int evthread_make_base_notifiable | ( | struct event_base * | base | ) |

Make sure it's safe to tell an event base to wake up from another thread or a signal handler.

Returns
  0 on success, -1 on failure.

References EV_FEATURE_FDS, EV_PERSIST, EV_READ, event_add(), event_assign(), event_priority_set(), event_base::evsel, evutil_make_socket_closeonexec(), evutil_make_socket_nonblocking(), evutil_socket_t, evutil_socketpair(), eventop::features, event_base::th_notify, event_base::th_notify_fd, and event_base::th_notify_fn.

Referenced by event_base_new_with_config(), and event_reinit().

int evthread_set_condition_callbacks | ( | const struct evthread_condition_callbacks * |  | ) |

Sets a group of functions that Libevent should use for condition variables.

For full information on the required callback API, see the documentation for the individual members of evthread_condition_callbacks.

Note that if you're using Windows or the Pthreads threading library, you probably shouldn't call this function; instead, use evthread_use_windows_threads() or evthread_use_pthreads() if you can.

References evthread_condition_callbacks::alloc_condition, evthread_condition_callbacks::free_condition, evthread_condition_callbacks::signal_condition, and evthread_condition_callbacks::wait_condition.

void evthread_set_id_callback | ( | unsigned long(*)(void) | id_fn | ) |

Sets the function for determining the thread id.

Parameters

  base | the event base for which to set the id function
  id_fn | the identify function Libevent should invoke to determine the identity of a thread.

int evthread_set_lock_callbacks | ( | const struct evthread_lock_callbacks * |  | ) |

Sets a group of functions that Libevent should use for locking.

For full information on the required callback API, see the documentation for the individual members of evthread_lock_callbacks.

Note that if you're using Windows or the Pthreads threading library, you probably shouldn't call this function; instead, use evthread_use_windows_threads() or evthread_use_posix_threads() if you can.

References evthread_lock_callbacks::alloc, evthread_lock_callbacks::free, evthread_lock_callbacks::lock, and evthread_lock_callbacks::unlock.