Skip to content

Commit

Permalink
Change some includes to forward declarations (sogou#57)
Browse files Browse the repository at this point in the history
* Make thrdpool stronger

* Fix some comments

* fix grammar

* change some include to forward declaration

* remove some typedef

* move codes

Co-authored-by: XieHan <[email protected]>
  • Loading branch information
Barenboim and Barenboim authored Sep 18, 2020
1 parent 5d01438 commit 65473be
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/kernel/Communicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,11 @@ int Communicator::sleep(SleepSession *session)
return -1;
}

int Communicator::is_handler_thread()
{
return thrdpool_in_pool(this->thrdpool);
}

extern "C" void __thrdpool_schedule(const struct thrdpool_task *, void *,
thrdpool_t *);

Expand Down
11 changes: 4 additions & 7 deletions src/kernel/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
#include <pthread.h>
#include <openssl/ssl.h>
#include "list.h"
#include "msgqueue.h"
#include "thrdpool.h"
#include "poller.h"
#include "mpoller.h"

class CommConnection
{
Expand Down Expand Up @@ -263,13 +260,13 @@ class Communicator
void io_unbind(IOService *service);

public:
int is_handler_thread();
int increase_handler_thread();
int is_handler_thread() { return thrdpool_in_pool(this->thrdpool); }

private:
msgqueue_t *queue;
mpoller_t *mpoller;
thrdpool_t *thrdpool;
struct __mpoller *mpoller;
struct __msgqueue *queue;
struct __thrdpool *thrdpool;
int stop_flag;

private:
Expand Down
3 changes: 1 addition & 2 deletions src/kernel/Executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <stddef.h>
#include <pthread.h>
#include "list.h"
#include "thrdpool.h"

class ExecQueue
{
Expand Down Expand Up @@ -69,7 +68,7 @@ class Executor
int request(ExecSession *session, ExecQueue *queue);

private:
thrdpool_t *thrdpool;
struct __thrdpool *thrdpool;

private:
static void executor_thread_routine(void *context);
Expand Down
1 change: 1 addition & 0 deletions src/kernel/SleepRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define _SLEEPREQUEST_H_

#include "SubTask.h"
#include "Communicator.h"
#include "CommScheduler.h"

class SleepRequest : public SubTask, public SleepSession
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/thrdpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ thrdpool_t *thrdpool_create(size_t nthreads, size_t stacksize)
thrdpool_t *pool;
int ret;

pool = (struct __thrdpool *)malloc(sizeof (struct __thrdpool));
pool = (thrdpool_t *)malloc(sizeof (thrdpool_t));
if (pool)
{
if (__thrdpool_init_locks(pool) >= 0)
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/thrdpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extern "C"
* A thread task can be scheduled by another task, which is very important,
* even if the pool is being destroyed. Because thread task is hard to know
* what's happening to the pool.
* The thread pool can also be destroyed by a thread task. Although this seems
* to be strange, it's very logical. Destroying thread pool in thread task
* The thread pool can also be destroyed by a thread task. This may sound
* strange, but it's very logical. Destroying thread pool in thread task
* does not end the task thread. It'll run till the end of task.
*/

Expand Down

0 comments on commit 65473be

Please sign in to comment.