1/*
2 Copyright (c) 2005-2019 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17// Header guard and namespace names follow TBB conventions.
18
19#ifndef __TBB_rml_tbb_H
20#define __TBB_rml_tbb_H
21
22#include "tbb/tbb_config.h"
23#include "rml_base.h"
24
25namespace tbb {
26namespace internal {
27namespace rml {
28
29class tbb_client;
30
31//------------------------------------------------------------------------
32// Classes instantiated by the server
33//------------------------------------------------------------------------
34
35//! Represents a set of tbb worker threads provided by the server.
36class tbb_server: public ::rml::server {
37public:
38 //! Inform server of adjustments in the number of workers that the client can profitably use.
39 virtual void adjust_job_count_estimate( int delta ) = 0;
40
41#if _WIN32||_WIN64
42 //! Inform server of a tbb master thread.
43 virtual void register_master( execution_resource_t& v ) = 0;
44
45 //! Inform server that the tbb master thread is done with its work.
46 virtual void unregister_master( execution_resource_t v ) = 0;
47#endif /* _WIN32||_WIN64 */
48};
49
50//------------------------------------------------------------------------
51// Classes instantiated by the client
52//------------------------------------------------------------------------
53
54class tbb_client: public ::rml::client {
55public:
56 //! Defined by TBB to steal a task and execute it.
57 /** Called by server when it wants an execution context to do some TBB work.
58 The method should return when it is okay for the thread to yield indefinitely. */
59 virtual void process( job& ) RML_PURE(void)
60};
61
62/** Client must ensure that instance is zero-inited, typically by being a file-scope object. */
63class tbb_factory: public ::rml::factory {
64
65 //! Pointer to routine that creates an RML server.
66 status_type (*my_make_server_routine)( tbb_factory&, tbb_server*&, tbb_client& );
67
68 //! Pointer to routine that calls callback function with server version info.
69 void (*my_call_with_server_info_routine)( ::rml::server_info_callback_t cb, void* arg );
70
71public:
72 typedef ::rml::versioned_object::version_type version_type;
73 typedef tbb_client client_type;
74 typedef tbb_server server_type;
75
76 //! Open factory.
77 /** Dynamically links against RML library.
78 Returns st_success, st_incompatible, or st_not_found. */
79 status_type open();
80
81 //! Factory method to be called by client to create a server object.
82 /** Factory must be open.
83 Returns st_success, or st_incompatible . */
84 status_type make_server( server_type*&, client_type& );
85
86 //! Close factory
87 void close();
88
89 //! Call the callback with the server build info
90 void call_with_server_info( ::rml::server_info_callback_t cb, void* arg ) const;
91};
92
93} // namespace rml
94} // namespace internal
95} // namespace tbb
96
97#endif /*__TBB_rml_tbb_H */
98