initial commit
This commit is contained in:
2
common/workqueue/config.mk
Executable file
2
common/workqueue/config.mk
Executable file
@@ -0,0 +1,2 @@
|
||||
CORE_SRCDIRS += $(COM_DIR)/workqueue
|
||||
FUSION_HEADERS += $(COM_DIR)/workqueue/*.h
|
||||
67
common/workqueue/workqueue.c
Executable file
67
common/workqueue/workqueue.c
Executable file
@@ -0,0 +1,67 @@
|
||||
/*************************************************
|
||||
File name : workqueue.h
|
||||
Module :
|
||||
Author : amir
|
||||
Version : 0.1
|
||||
Created on : 2022-02-07
|
||||
Description :
|
||||
Data structure and function definitions required by the socket interface
|
||||
|
||||
Modify History:
|
||||
1. Date: Author: Modification:
|
||||
*************************************************/
|
||||
#include "threadpool.h"
|
||||
#include "workqueue.h"
|
||||
#include "hlog.h"
|
||||
|
||||
|
||||
workqueue *workqueue_init(uint32_t max_cnt){
|
||||
workqueue *wq = threadpool_create(max_cnt);
|
||||
assert(wq);
|
||||
return wq;
|
||||
}
|
||||
|
||||
void workqueue_deinit(workqueue *wq){
|
||||
if (wq){
|
||||
threadpool_dump(wq);
|
||||
threadpool_destroy(wq);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t workqueue_add(workqueue *wq, thread_routine routine, kpacket *packet){
|
||||
return threadpool_add(wq, routine, packet );
|
||||
}
|
||||
|
||||
static void *workqueue_test_handler(void *param){
|
||||
kpacket *packet = (kpacket *)param;
|
||||
hlogi("%s V:%u", __func__, *((int32_t *) packet->tlv.V));
|
||||
return NULL;
|
||||
};
|
||||
|
||||
void workqueue_test()
|
||||
{
|
||||
hlogi("%s start", __func__);
|
||||
workqueue *wq = workqueue_init(5);
|
||||
uint32_t i;
|
||||
for(i=0; i<1000000;i++){
|
||||
kpacket *packet = kpacket(1, 10);
|
||||
hlogi("%s i:%u packet:%p", __func__, i, packet);
|
||||
if (!packet){
|
||||
hloge("%s i:%u packet:%p", __func__, i, packet);
|
||||
hv_usleep(1000);
|
||||
continue;
|
||||
}
|
||||
*((int32_t *) packet->tlv.V) = i;
|
||||
workqueue_add(wq, workqueue_test_handler, packet);
|
||||
kpacket_dec(packet);
|
||||
}
|
||||
workqueue_deinit(wq);
|
||||
hlogi("%s stop", __func__);
|
||||
}
|
||||
|
||||
void workqueue_dump(workqueue *wq)
|
||||
{
|
||||
threadpool_dump(wq);
|
||||
}
|
||||
|
||||
|
||||
47
common/workqueue/workqueue.h
Executable file
47
common/workqueue/workqueue.h
Executable file
@@ -0,0 +1,47 @@
|
||||
#ifndef __PAL_THREADPOOL_H__
|
||||
#define __PAL_THREADPOOL_H__
|
||||
#include <stdint.h>
|
||||
#include "list.h"
|
||||
#include "threadpool.h"
|
||||
|
||||
|
||||
typedef threadpool workqueue;
|
||||
|
||||
/** workqueue_init
|
||||
* [in] max_cnt, thread/task max count if need
|
||||
//
|
||||
void workqueue_deinit(workqueue *wq);
|
||||
*/
|
||||
|
||||
workqueue *workqueue_init(uint32_t max_cnt);
|
||||
|
||||
/** workqueue_deinit
|
||||
* no need to deinit commomly
|
||||
*/
|
||||
void workqueue_deinit(workqueue *wq);
|
||||
|
||||
|
||||
// add a work to workqueue
|
||||
// entry as callback
|
||||
/**
|
||||
* @brief Add a work to workqueue.
|
||||
*
|
||||
* @param [in] wq, workqueue instance.
|
||||
* @param [in] entry, as callback func.
|
||||
* @param [in] packet, param to entry.
|
||||
* @param [in] type, urge level.
|
||||
* @param [in] delayms, run after ms.
|
||||
* @retval 0 Mutex lock create successfully.
|
||||
* @retval ZFAILED Mutex lock create failed.
|
||||
*
|
||||
* @see os_mutex_delete
|
||||
*/
|
||||
uint32_t workqueue_add(workqueue *wq, thread_routine routine, kpacket *packet);
|
||||
|
||||
void workqueue_test();
|
||||
|
||||
void workqueue_dump();
|
||||
|
||||
|
||||
|
||||
#endif /* __PAL_THREADPOOL_H__ */
|
||||
Reference in New Issue
Block a user