我无法将此函数编译为线程。有人可以帮我吗?感谢
class HWCLayerVersion1 : public Iterable<HWCLayerVersion1, hwc_layer_1_t> {
struct hwc_composer_device_1* mHwc;
...
status_t HWComposer::acquire(int disp) {
LOG_FATAL_IF(disp >= VIRTUAL_DISPLAY_ID_BASE);
struct arg_struct *args = (struct arg_struct *) args;
args->disp = disp;
args->value = 0;
args->h = mHwc;
pthread_t some_thread;
status_t ret;
if (mHwc) {
int hi = pthread_create(&some_thread, NULL, &mHwc->blank, &args);
}
return NO_ERROR;
}
在hwcomposer.h中:
typedef struct hwc_composer_device_1 {
struct hw_device_t common;
int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
在单独的.cpp文件中,hwc_composer_device_1是
static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
我收到以下错误(一行,但我把它分成3行):
error: cannot convert 'int (**)(hwc_composer_device_1*, int, int)'
to 'void* (*)(void*)' for argument '3'
to 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)'
答案 0 :(得分:1)
您的功能没有与pthread
一起使用的正确签名。一种选择是创建这样的函数:
void *do_blank(void *args) {
struct arg_struct *blank_args = (struct arg_struct *)args;
return hwc_blank(blank_args->h, blank_args->disp, blank_args->value);
}
然后你可以将它传递给pthread
:
if (mHwc) {
int hi = pthread_create(&some_thread, NULL, do_blank, &args);
}
每当从此线程检索返回值时,您需要将结果转换为整数。