source: libcf/trunk/src/cf_queue.c@ 151

Last change on this file since 151 was 151, checked in by cheese, 11 years ago

#1 fix interface and add util module

File size: 2.1 KB
RevLine 
[109]1/**
[128]2 * \file cf_queue.c
[117]3 *
[128]4 * \author myusgun <myusgun@gmail.com>
5 *
[119]6 * \brief 큐 구현
[109]7 */
8#include "cf_queue.h"
9#include "cf_list.h"
[151]10#include "cf_local.h"
[109]11#include "cf_error.h"
12
13#include <stdio.h>
14
[151]15static int
16CF_Queue_Local_Get (cf_ctx ctx,
17 void ** element,
18 CF_BOOL removeFlag)
19{
20 int result = 0;
21 cf_ctx list = (cf_ctx) ctx;
22 cf_traverser trav = NULL;
23
24 result = CF_List_Front (list, &trav);
25 if (result < 0)
26 return result;
27
28 result = CF_List_Get (trav, element);
29 if (result < 0)
30 return result;
31
32 result = (removeFlag == CF_TRUE)
33 ? CF_List_Remove (ctx, &trav)
34 : CF_OK;
35
36 return result;
37}
38
[111]39/**
40 * 큐 컨텍스트 생성
41 *
[119]42 * \return 성공 시, CF_OK; 실패 시, 오류 코드
[111]43 *
[119]44 * \param ctx 큐 컨텍스트 포인터
[111]45 */
[109]46int
[151]47CF_Queue_Create (cf_ctx * ctx)
[109]48{
[151]49 return CF_List_Create ((cf_ctx *) ctx);
[109]50}
51
[111]52/**
53 * 큐 컨텍스트 해제
54 *
[119]55 * \return 성공 시, CF_OK; 실패 시, 오류 코드
[111]56 *
[119]57 * \param ctx 큐 컨텍스트
[111]58 */
[109]59int
[151]60CF_Queue_Destroy (cf_ctx ctx)
[109]61{
[151]62 return CF_List_Destroy (ctx);
[109]63}
64
[111]65/**
66 * 큐에 삽입
67 *
[119]68 * \return 성공 시, CF_OK; 실패 시, 오류 코드
[111]69 *
[119]70 * \param ctx 큐 컨텍스트
71 * \param element 데이터 주소
[111]72 */
[109]73int
[151]74CF_Queue_Put (cf_ctx ctx,
[109]75 const void * element)
76{
[151]77 cf_ctx list = (cf_ctx) ctx;
[109]78
[151]79 return CF_List_AddRear (list, element);
[109]80}
81
[111]82/**
83 * 큐에서 꺼내기
84 *
[119]85 * \return 성공 시, CF_OK; 실패 시, 오류 코드
[111]86 *
[119]87 * \param ctx 큐 컨텍스트
88 * \param element 데이터 주소
[111]89 */
[109]90int
[151]91CF_Queue_Get (cf_ctx ctx,
92 void ** element)
[109]93{
[151]94 return CF_Queue_Local_Get (ctx, element, CF_TRUE);
[109]95}
96
[111]97/**
98 * 큐 처음의 데이터 조회
99 *
[119]100 * \return 성공 시, CF_OK; 실패 시, 오류 코드
[111]101 *
[119]102 * \param ctx 큐 컨텍스트
103 * \param element 데이터 주소
[111]104 */
[109]105int
[151]106CF_Queue_Front (cf_ctx ctx,
107 void ** element)
[109]108{
[151]109 return CF_Queue_Local_Get (ctx, element, CF_FALSE);
[109]110}
111
[111]112/**
113 * 큐에 등록된 항목의 수를 가져옴
114 *
[119]115 * \return 성공 시, 항목 수; 실패 시, 오류 코드
[111]116 *
[119]117 * \param ctx 큐 컨텍스트
[111]118 */
[109]119int
[151]120CF_Queue_GetSize (cf_ctx ctx)
[109]121{
[151]122 return CF_List_GetSize ((cf_ctx) ctx);
[109]123}
Note: See TracBrowser for help on using the repository browser.