mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add CefThread interface (issue #1632)
This commit is contained in:
115
include/capi/cef_thread_capi.h
Normal file
115
include/capi/cef_thread_capi.h
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2016 Marshall A. Greenblatt. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the name Chromium Embedded
|
||||
// Framework nor the names of its contributors may be used to endorse
|
||||
// or promote products derived from this software without specific prior
|
||||
// written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool and should not edited
|
||||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CAPI_CEF_THREAD_CAPI_H_
|
||||
#define CEF_INCLUDE_CAPI_CEF_THREAD_CAPI_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/capi/cef_task_capi.h"
|
||||
#include "include/internal/cef_thread_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
///
|
||||
// A simple thread abstraction that establishes a message loop on a new thread.
|
||||
// The consumer uses cef_task_tRunner to execute code on the thread's message
|
||||
// loop. The thread is terminated when the cef_thread_t object is destroyed or
|
||||
// stop() is called. All pending tasks queued on the thread's message loop will
|
||||
// run to completion before the thread is terminated. cef_thread_create() can be
|
||||
// called on any valid CEF thread in either the browser or render process. This
|
||||
// structure should only be used for tasks that require a dedicated thread. In
|
||||
// most cases you can post tasks to an existing CEF thread instead of creating a
|
||||
// new one; see cef_task.h for details.
|
||||
///
|
||||
typedef struct _cef_thread_t {
|
||||
///
|
||||
// Base structure.
|
||||
///
|
||||
cef_base_t base;
|
||||
|
||||
///
|
||||
// Returns the cef_task_tRunner that will execute code on this thread's
|
||||
// message loop. This function is safe to call from any thread.
|
||||
///
|
||||
struct _cef_task_runner_t* (CEF_CALLBACK *get_task_runner)(
|
||||
struct _cef_thread_t* self);
|
||||
|
||||
///
|
||||
// Returns the platform thread ID. It will return the same value after stop()
|
||||
// is called. This function is safe to call from any thread.
|
||||
///
|
||||
cef_platform_thread_id_t (CEF_CALLBACK *get_platform_thread_id)(
|
||||
struct _cef_thread_t* self);
|
||||
|
||||
///
|
||||
// Stop and join the thread. This function must be called from the same thread
|
||||
// that called cef_thread_create(). Do not call this function if
|
||||
// cef_thread_create() was called with a |stoppable| value of false (0).
|
||||
///
|
||||
void (CEF_CALLBACK *stop)(struct _cef_thread_t* self);
|
||||
|
||||
///
|
||||
// Returns true (1) if the thread is currently running. This function must be
|
||||
// called from the same thread that called cef_thread_create().
|
||||
///
|
||||
int (CEF_CALLBACK *is_running)(struct _cef_thread_t* self);
|
||||
} cef_thread_t;
|
||||
|
||||
|
||||
///
|
||||
// Create and start a new thread. This function does not block waiting for the
|
||||
// thread to run initialization. |display_name| is the name that will be used to
|
||||
// identify the thread. |priority| is the thread execution priority.
|
||||
// |message_loop_type| indicates the set of asynchronous events that the thread
|
||||
// can process. If |stoppable| is true (1) the thread will stopped and joined on
|
||||
// destruction or when stop() is called; otherwise, the the thread cannot be
|
||||
// stopped and will be leaked on shutdown. On Windows the |com_init_mode| value
|
||||
// specifies how COM will be initialized for the thread. If |com_init_mode| is
|
||||
// set to COM_INIT_MODE_STA then |message_loop_type| must be set to ML_TYPE_UI.
|
||||
///
|
||||
CEF_EXPORT cef_thread_t* cef_thread_create(const cef_string_t* display_name,
|
||||
cef_thread_priority_t priority, cef_message_loop_type_t message_loop_type,
|
||||
int stoppable, cef_com_init_mode_t com_init_mode);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CEF_INCLUDE_CAPI_CEF_THREAD_CAPI_H_
|
117
include/cef_thread.h
Normal file
117
include/cef_thread.h
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) 2016 Marshall A. Greenblatt. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the name Chromium Embedded
|
||||
// Framework nor the names of its contributors may be used to endorse
|
||||
// or promote products derived from this software without specific prior
|
||||
// written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// The contents of this file must follow a specific format in order to
|
||||
// support the CEF translator tool. See the translator.README.txt file in the
|
||||
// tools directory for more information.
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CEF_THREAD_H_
|
||||
#define CEF_INCLUDE_CEF_THREAD_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_task.h"
|
||||
#include "include/internal/cef_thread_internal.h"
|
||||
|
||||
///
|
||||
// A simple thread abstraction that establishes a message loop on a new thread.
|
||||
// The consumer uses CefTaskRunner to execute code on the thread's message loop.
|
||||
// The thread is terminated when the CefThread object is destroyed or Stop() is
|
||||
// called. All pending tasks queued on the thread's message loop will run to
|
||||
// completion before the thread is terminated. CreateThread() can be called on
|
||||
// any valid CEF thread in either the browser or render process. This class
|
||||
// should only be used for tasks that require a dedicated thread. In most cases
|
||||
// you can post tasks to an existing CEF thread instead of creating a new one;
|
||||
// see cef_task.h for details.
|
||||
///
|
||||
/*--cef(source=library)--*/
|
||||
class CefThread : public CefBase {
|
||||
public:
|
||||
///
|
||||
// Create and start a new thread. This method does not block waiting for the
|
||||
// thread to run initialization. |display_name| is the name that will be used
|
||||
// to identify the thread. |priority| is the thread execution priority.
|
||||
// |message_loop_type| indicates the set of asynchronous events that the
|
||||
// thread can process. If |stoppable| is true the thread will stopped and
|
||||
// joined on destruction or when Stop() is called; otherwise, the the thread
|
||||
// cannot be stopped and will be leaked on shutdown. On Windows the
|
||||
// |com_init_mode| value specifies how COM will be initialized for the thread.
|
||||
// If |com_init_mode| is set to COM_INIT_MODE_STA then |message_loop_type|
|
||||
// must be set to ML_TYPE_UI.
|
||||
///
|
||||
/*--cef(optional_param=display_name)--*/
|
||||
static CefRefPtr<CefThread> CreateThread(
|
||||
const CefString& display_name,
|
||||
cef_thread_priority_t priority,
|
||||
cef_message_loop_type_t message_loop_type,
|
||||
bool stoppable,
|
||||
cef_com_init_mode_t com_init_mode);
|
||||
|
||||
///
|
||||
// Create and start a new thread with default/recommended values.
|
||||
// |display_name| is the name that will be used to identify the thread.
|
||||
///
|
||||
static CefRefPtr<CefThread> CreateThread(const CefString& display_name) {
|
||||
return CreateThread(display_name, TP_NORMAL, ML_TYPE_DEFAULT, true,
|
||||
COM_INIT_MODE_NONE);
|
||||
}
|
||||
|
||||
///
|
||||
// Returns the CefTaskRunner that will execute code on this thread's message
|
||||
// loop. This method is safe to call from any thread.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual CefRefPtr<CefTaskRunner> GetTaskRunner() =0;
|
||||
|
||||
///
|
||||
// Returns the platform thread ID. It will return the same value after Stop()
|
||||
// is called. This method is safe to call from any thread.
|
||||
///
|
||||
/*--cef(default_retval=kInvalidPlatformThreadId)--*/
|
||||
virtual cef_platform_thread_id_t GetPlatformThreadId() =0;
|
||||
|
||||
///
|
||||
// Stop and join the thread. This method must be called from the same thread
|
||||
// that called CreateThread(). Do not call this method if CreateThread() was
|
||||
// called with a |stoppable| value of false.
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void Stop() =0;
|
||||
|
||||
///
|
||||
// Returns true if the thread is currently running. This method must be called
|
||||
// from the same thread that called CreateThread().
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual bool IsRunning() =0;
|
||||
};
|
||||
|
||||
#endif // CEF_INCLUDE_CEF_THREAD_H_
|
@@ -46,8 +46,10 @@ extern "C" {
|
||||
|
||||
#if defined(OS_WIN)
|
||||
typedef DWORD cef_platform_thread_id_t;
|
||||
#define kInvalidPlatformThreadId 0U
|
||||
#elif defined(OS_POSIX)
|
||||
typedef pid_t cef_platform_thread_id_t;
|
||||
#define kInvalidPlatformThreadId 0
|
||||
#endif
|
||||
|
||||
///
|
||||
@@ -57,8 +59,10 @@ CEF_EXPORT cef_platform_thread_id_t cef_get_current_platform_thread_id();
|
||||
|
||||
#if defined(OS_WIN)
|
||||
typedef DWORD cef_platform_thread_handle_t;
|
||||
#define kInvalidPlatformThreadHandle 0U
|
||||
#elif defined(OS_POSIX)
|
||||
typedef pthread_t cef_platform_thread_handle_t;
|
||||
#define kInvalidPlatformThreadHandle 0
|
||||
#endif
|
||||
|
||||
///
|
||||
|
@@ -1396,6 +1396,73 @@ typedef enum {
|
||||
TID_RENDERER,
|
||||
} cef_thread_id_t;
|
||||
|
||||
///
|
||||
// Thread priority values listed in increasing order of importance.
|
||||
///
|
||||
typedef enum {
|
||||
///
|
||||
// Suitable for threads that shouldn't disrupt high priority work.
|
||||
///
|
||||
TP_BACKGROUND,
|
||||
|
||||
///
|
||||
// Default priority level.
|
||||
///
|
||||
TP_NORMAL,
|
||||
|
||||
///
|
||||
// Suitable for threads which generate data for the display (at ~60Hz).
|
||||
///
|
||||
TP_DISPLAY,
|
||||
|
||||
///
|
||||
// Suitable for low-latency, glitch-resistant audio.
|
||||
///
|
||||
TP_REALTIME_AUDIO,
|
||||
} cef_thread_priority_t;
|
||||
|
||||
///
|
||||
// Message loop types. Indicates the set of asynchronous events that a message
|
||||
// loop can process.
|
||||
///
|
||||
typedef enum {
|
||||
///
|
||||
// Supports tasks and timers.
|
||||
///
|
||||
ML_TYPE_DEFAULT,
|
||||
|
||||
///
|
||||
// Supports tasks, timers and native UI events (e.g. Windows messages).
|
||||
///
|
||||
ML_TYPE_UI,
|
||||
|
||||
///
|
||||
// Supports tasks, timers and asynchronous IO events.
|
||||
///
|
||||
ML_TYPE_IO,
|
||||
} cef_message_loop_type_t;
|
||||
|
||||
///
|
||||
// Windows COM initialization mode. Specifies how COM will be initialized for a
|
||||
// new thread.
|
||||
///
|
||||
typedef enum {
|
||||
///
|
||||
// No COM initialization.
|
||||
///
|
||||
COM_INIT_MODE_NONE,
|
||||
|
||||
///
|
||||
// Initialize COM using single-threaded apartments.
|
||||
///
|
||||
COM_INIT_MODE_STA,
|
||||
|
||||
///
|
||||
// Initialize COM using multi-threaded apartments.
|
||||
///
|
||||
COM_INIT_MODE_MTA,
|
||||
} cef_com_init_mode_t;
|
||||
|
||||
///
|
||||
// Supported value types.
|
||||
///
|
||||
|
Reference in New Issue
Block a user