ev_set_loop_release_cb with class member functions.
Horacio Sanson
hsanson at gmail.com
Tue Jul 27 08:47:36 CEST 2010
I am trying to make my server class threaded following the thread example in the
libev documentation. Unfortunately I am having some problems converting the C to
C++ especially with the ev_set_loop_release_cb call.
Small test program:
#define EV_STANDALONE 1
#define EV_FEATURES 8
#define EV_USE_EPOLL 1
#define EV_PREPARE_ENABLE 1
#define EV_IDLE_ENABLE 1
#define EV_SIGNAL_ENABLE 1
#define EV_CHILD_ENABLE 1
#define EV_USE_STDEXCEPT 0
//#define EV_CONFIG_H <config.h>
#include <ev++.h>
#include "ev.c"
#include <pthread.h>
class Server
{
private:
void lock(EV_P) {
pthread_mutex_lock(&mutex);
}
void unlock(EV_P) {
pthread_mutex_unlock(&mutex);
}
pthread_mutex_t mutex;
struct ev_loop *m_loop;
public:
Server() {
pthread_mutex_init(&mutex, NULL);
m_loop = ev_default_loop(0);
ev_set_loop_release_cb(m_loop, &Server::lock, &Server::unlock);
}
void start() {
lock(m_loop);
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
ev_loop(m_loop, 0);
unlock(m_loop);
}
}
int main(int argc, char **argv)
{
Server server;
server.start();
}
Compilation of this sample results in the following error:
g++ -I./libev-3.9 -o libevtest libevtest.cpp
libevtest.cpp: In constructor ‘Server::Server()’:
libevtest.cpp:37: error: cannot convert ‘void (Server::*)(ev_loop*)’ to ‘void
(*)(ev_loop*)’ for argument ‘2’ to ‘void ev_set_loop_release_cb(ev_loop*, void
(*)(ev_loop*), void (*)(ev_loop*))’
libevtest.cpp: At global scope:
libevtest.cpp:15: error: new types may not be defined in a return type
libevtest.cpp:15: note: (perhaps a semicolon is missing after the definition of
‘Server’)
libevtest.cpp:49: error: two or more data types in declaration of ‘main’
--
regards,
Horacio Sanson
More information about the libev
mailing list