Robust Distributed System Nucleus (rDSN)  ver 1.0.0
api_task.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2015 Microsoft Corporation
5  *
6  * -=- Robust Distributed System Nucleus (rDSN) -=-
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 /*
28  * Description:
29  * task and execution model
30  *
31  * Revision history:
32  * Feb., 2016, @imzhenyu (Zhenyu Guo), first version
33  * xxxx-xx-xx, author, fix bug about xxx
34  */
35 
36 # pragma once
37 
38 # include <dsn/c/api_common.h>
39 
40 # ifdef __cplusplus
41 extern "C" {
42 # endif
43 
50 typedef enum dsn_task_type_t
51 {
57  TASK_TYPE_COUNT,
60  TASK_TYPE_INVALID
62 
64 typedef void(*dsn_task_handler_t)(
65  void*
66  );
67 
70  dsn_message_t,
71  void*
72  );
73 
76  dsn_error_t,
77  dsn_message_t,
78  dsn_message_t,
79  void*
80  );
81 
83 typedef void(*dsn_aio_handler_t)(
84  dsn_error_t,
85  size_t,
86  void*
87  );
88 
90 typedef enum dsn_task_priority_t
91 {
92  TASK_PRIORITY_LOW,
93  TASK_PRIORITY_COMMON,
94  TASK_PRIORITY_HIGH,
95  TASK_PRIORITY_COUNT,
96  TASK_PRIORITY_INVALID
98 
112  void*
113  );
114 
116 extern DSN_API dsn_threadpool_code_t dsn_threadpool_code_register(const char* name);
117 extern DSN_API const char* dsn_threadpool_code_to_string(dsn_threadpool_code_t pool_code);
118 extern DSN_API dsn_threadpool_code_t dsn_threadpool_code_from_string(
119  const char* s,
120  dsn_threadpool_code_t default_code // when s is not registered
121  );
122 extern DSN_API int dsn_threadpool_code_max();
123 extern DSN_API int dsn_threadpool_get_current_tid();
124 
126 extern DSN_API dsn_task_code_t dsn_task_code_register(
127  const char* name, // task code name
128  dsn_task_type_t type,
129  dsn_task_priority_t,
130  dsn_threadpool_code_t pool // in which thread pool the tasks run
131  );
132 extern DSN_API void dsn_task_code_query(
133  dsn_task_code_t code,
134  /*out*/ dsn_task_type_t *ptype,
135  /*out*/ dsn_task_priority_t *ppri,
136  /*out*/ dsn_threadpool_code_t *ppool
137  );
138 extern DSN_API void dsn_task_code_set_threadpool( // change thread pool for this task code
139  dsn_task_code_t code,
140  dsn_threadpool_code_t pool
141  );
142 extern DSN_API void dsn_task_code_set_priority(dsn_task_code_t code, dsn_task_priority_t pri);
143 extern DSN_API const char* dsn_task_code_to_string(dsn_task_code_t code);
144 extern DSN_API dsn_task_code_t dsn_task_code_from_string(const char* s, dsn_task_code_t default_code);
145 extern DSN_API int dsn_task_code_max();
146 extern DSN_API const char* dsn_task_type_to_string(dsn_task_type_t tt);
147 extern DSN_API const char* dsn_task_priority_to_string(dsn_task_priority_t tt);
148 
154 extern DSN_API volatile int* dsn_task_queue_virtual_length_ptr(
155  dsn_task_code_t code,
156  int hash DEFAULT(0)
157  );
158 
161 # ifdef __cplusplus
162 }
163 # endif
void(* dsn_task_cancelled_handler_t)(void *)
callback prototype for task cancellation (called on task-being-cancelled)
Definition: api_task.h:111
dsn_task_priority_t
task priority
Definition: api_task.h:90
DSN_API volatile int * dsn_task_queue_virtual_length_ptr(dsn_task_code_t code, int hash DEFAULT(0))
apps updates the value at dsn_task_queue_virtual_length_ptr(..) to control the length of a vitual que...
task handling rpc response or timeout
Definition: api_task.h:53
void(* dsn_task_handler_t)(void *)
callback prototype for TASK_TYPE_COMPUTE
Definition: api_task.h:64
DSN_API dsn_threadpool_code_t dsn_threadpool_code_register(const char *name)
define a new thread pool with a given name
void(* dsn_rpc_request_handler_t)(dsn_message_t, void *)
callback prototype for TASK_TYPE_RPC_REQUEST
Definition: api_task.h:69
callback for file read and write
Definition: api_task.h:55
void(* dsn_rpc_response_handler_t)(dsn_error_t, dsn_message_t, dsn_message_t, void *)
callback prototype for TASK_TYPE_RPC_RESPONSE
Definition: api_task.h:75
void(* dsn_aio_handler_t)(dsn_error_t, size_t, void *)
callback prototype for TASK_TYPE_AIO
Definition: api_task.h:83
task handling rpc request
Definition: api_task.h:52
async calls or timers
Definition: api_task.h:54
DSN_API dsn_task_code_t dsn_task_code_register(const char *name, dsn_task_type_t type, dsn_task_priority_t, dsn_threadpool_code_t pool)
register a new task code
above tasks are seperated into several continuation tasks by thread-synchronization operations...
Definition: api_task.h:56
dsn_task_type_t
task/event type definition
Definition: api_task.h:50