1 /*
2     Copyright (c) 2005-2021 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 "oneapi/tbb/version.h"
23 #include "rml_base.h"
24 
25 namespace tbb {
26 namespace detail {
27 namespace r1 {
28 namespace rml {
29 
30 //------------------------------------------------------------------------
31 // Classes instantiated by the server
32 //------------------------------------------------------------------------
33 
34 //! Represents a set of oneTBB worker threads provided by the server.
35 class tbb_server: public ::rml::server {
36 public:
37     //! Inform server of adjustments in the number of workers that the client can profitably use.
38     virtual void adjust_job_count_estimate( int delta ) = 0;
39 
40 #if _WIN32 || _WIN64
41     //! Inform server of a oneTBB external thread.
42     virtual void register_external_thread( execution_resource_t& v ) = 0;
43 
44     //! Inform server that the oneTBB external thread is done with its work.
45     virtual void unregister_external_thread( execution_resource_t v ) = 0;
46 #endif /* _WIN32||_WIN64 */
47 };
48 
49 //------------------------------------------------------------------------
50 // Classes instantiated by the client
51 //------------------------------------------------------------------------
52 
53 class tbb_client: public ::rml::client {
54 public:
55     //! Defined by TBB to steal a task and execute it.
56     /** Called by server when it wants an execution context to do some TBB work.
57         The method should return when it is okay for the thread to yield indefinitely. */
58     virtual void process( job& ) RML_PURE(void)
59 };
60 
61 /** Client must ensure that instance is zero-inited, typically by being a file-scope object. */
62 class tbb_factory: public ::rml::factory {
63 
64     //! Pointer to routine that creates an RML server.
65     status_type (*my_make_server_routine)( tbb_factory&, tbb_server*&, tbb_client& );
66 
67     //! Pointer to routine that calls callback function with server version info.
68     void (*my_call_with_server_info_routine)( ::rml::server_info_callback_t cb, void* arg );
69 
70 public:
71     typedef ::rml::versioned_object::version_type version_type;
72     typedef tbb_client client_type;
73     typedef tbb_server server_type;
74 
75     //! Open factory.
76     /** Dynamically links against RML library.
77         Returns st_success, st_incompatible, or st_not_found. */
78     status_type open();
79 
80     //! Factory method to be called by client to create a server object.
81     /** Factory must be open.
82         Returns st_success, or st_incompatible . */
83     status_type make_server( server_type*&, client_type& );
84 
85     //! Close factory
86     void close();
87 };
88 
89 } // namespace rml
90 } // namespace r1
91 } // namespace detail
92 } // namespace tbb
93 
94 #endif /*__TBB_rml_tbb_H */
95